People,
I am trying to crack the kernel module by changing its symbol. The main idea is to replace the original function with a new function by rewriting its address in symtab. However, I found that when declaring a function as static, hacking fails. But it works with non-static function. My sample code is below:
filename: orig.c
int fun(void) { printk(KERN_ALERT "calling fun!\n"); return 0; } int evil(void) { printk(KERN_ALERT "===== EVIL ====\n"); return 0; } static int init(void) { printk(KERN_ALERT "Init Original!"); fun(); return 0; } void clean(void) { printk(KERN_ALERT "Exit Original!"); return; } module_init(init); module_exit(clean);
Then I follow the sticky article to replace the original fun function in symtab with the evil call function, http://www.phrack.org/issues.html?issue=68&id=11
>objdump -t orig.ko ... 000000000000001b g F .text 000000000000001b evil 0000000000000056 g F .text 0000000000000019 cleanup_module 0000000000000036 g F .text 0000000000000020 init_module 0000000000000000 g F .text 000000000000001b fun ...
By executing the elfchger function
>./elfchger -s fun -v 1b orig.ko [+] Opening orig.ko file... [+] Reading Elf header... >> Done! [+] Finding ".symtab" section... >> Found at 0xc630 [+] Finding ".strtab" section... >> Found at 0xc670 [+] Getting symbol' infos: >> Symbol found at 0x159f8 >> Index in symbol table: 0x1d [+] Replacing 0x00000000 with 0x0000001b... done!
I can successfully change the table of funny characters to evil and insert a module to see the effects:
000000000000001b g F .text 000000000000001b evil ... 000000000000001b g F .text 000000000000001b fun > insmod ./orig.ko > dmesg [ 7687.797211] Init Original! [ 7687.797215]
So far, this works fine. When I change the declaration of fun as โstatic int fun (void)โ and follow the same steps as mentioned above, I find that evil is not caused. Can someone give me some suggestion?
Thanks William
source share