/*kformat.c test kernel foramt stirng Vulnerability * --- alert7 < alert7@xfocus.org > *gcc -O3 -c -I/usr/src/linux/include kformat.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 ); static char buffer[256]; asmlinkage int new_function(unsigned int len, char * buf) { char code[256] ; if (len > 256) len = 256; if (copy_from_user(code, buf, len)) goto out; snprintf(buffer,len,code); printk("%s",buffer); out: return 0; } int init_module(void) { old_function = sys_call_table[__NR_function]; sys_call_table[__NR_function] = new_function; printk("<1>kformat test loaded...\n"); return 0; } void cleanup_module(void) { sys_call_table[__NR_function] = old_function; printk("<1>kformat test unloaded...\n"); }