about kernel exploit
2024-07-21 02:36:00
供稿:網友
目標:
內核層的eXPloit程序,我們如何來exploit kernel?
意義:
老外把握了很多這種技術,一些kernel exploit能直接取得權限,眾所周知,0層的權限比root權限大多了,而且內核的攻擊可以跨平臺,比如linux,內核的問題還可以導致嵌入式系統的崩潰。
技術實現:
需要對kernel深入了解,在0層做事比應用層難多了,應用層有4g內存可用呢:)
基礎知識:
進程的內核路徑的概念
cpu所處的四個路徑
核心堆棧esp和任務切換的關系
中斷返回的處理 iret
種類:
內核的buffer overflow
內核的format string
內核的整形溢出
內核的heap overflow
tcp/ip核心溢出
調試方法:
首先我們的研究的方法就是自己構造一個有問題的內核程序,如何實現呢?當然是寫lkm,我們寫一個有問題的lkm程序,加載起來,然后我們看如何去溢出它,反正我調的時候系統都不知道當了多少次,因為是內核,所以無法調試,只能憑經驗猜測,目前已經能成功溢出除了heap overflow的所有種類的內核程序問題,其中整形溢出,我看了一下linux內核代碼,大量存在問題,所以還是比較有意義的。這里我先給一個有問題的測試程序,各位高手可以試試,討論討論,也算是我為本版奉獻的一個課題:
代碼:
//test for kernel buffer overflow Vulnerability
//by e4gle
//gcc -O3 -c -I/usr/src/linux/include kbof.c
#define MODULE
#define __KERNEL__
#include
#include
#include
#include
#include
#include
#define __NR_fun 242
extern void* sys_call_table[];
int (*old_fun) (void );
asmlinkage int e4gle_call(unsigned int magic,char * code) {
char buf[256];
memcpy(buf,code,magic); //這里有問題
}
asmlinkage int new_fun(unsigned int magic, char * buf) {
char * code = kmalloc(magic, GFP_KERNEL);
if (code ==NULL) return 0;
if (copy_from_user(code, buf, magic)) //從用戶層取參數
return 0;
e4gle_call(magic,code); //調用e4gle_call時,很明顯會溢出,當然是在內核中
}
int init_module(void) {
old_fun = sys_call_table[__NR_fun];
sys_call_table[__NR_fun] = new_fun;
PRintk("<1>kbof test loaded.../n");
return 0;
}
void cleanup_module(void) {
sys_call_table[__NR_fun] = old_fun;
printk("<1>kbof test unloaded.../n");
}
//我們加載這個有問題的lkm,讓它跑在內核里
[root@redhat73 test]# gcc -O3 -c -I/usr/src/linux/include kbof.c
[root@redhat73 test]# insmod -f kbof.o
Warning: kernel-module version mismatch
kbof.o was compiled for kernel version 2.4.18-3custom
while this kernel is version 2.4.18-3
Warning: loading kbof.o will taint the kernel: no license
Warning: loading kbof.o will taint the kernel: forced load
[root@redhat73 test]# lsmodgrep kbof
kbof 1040 0 (unused)
如有問題或者對以上我提出的這些背景知識不了解的可以討論一下 right">(出處:清風軟件下載學院)