/*kbof.c test kernel buffer overflow Vulnerability * --- alert7 < alert7@xfocus.org > *gcc -O3 -c -I/usr/src/linux/include kbof.c */ #define MODULE #define __KERNEL__ #include #include #include #include #include #include #define __NR_function 240 //linux not use extern void* sys_call_table[]; int (*old_function) (void ); asmlinkage int test(unsigned int len,char * code) { char buf[256]; //strcpy(buf,code); memcpy(buf,code,len); } asmlinkage int new_function(unsigned int len, char * buf) { char * code = kmalloc(len, GFP_KERNEL); if (code ==NULL) goto out; if (copy_from_user(code, buf, len)) goto out; test(len,code); out: return 0; } int init_module(void) { old_function = sys_call_table[__NR_function]; sys_call_table[__NR_function] = new_function; printk("<1>kbof test loaded...\n"); return 0; } void cleanup_module(void) { sys_call_table[__NR_function] = old_function; printk("<1>kbof test unloaded...\n"); }