目标: 内核层的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">(出处:清风软件下载学院)
|