The syscall table is generally an array of function pointers; these function pointers can be redirected to point to functions implemented in the rootkit, often times an LKM. This type of kernel rootkit is easy to detect compared to other kernel rootkits. A hands on approach is to analyze /proc/kcore with gdb and verify the syscalls against the System.map (A file created at kernel compilation time for debugging purposes). A simpler approach is to run a tool like ktraq, which also has the benefit of disabling this type of rootkit by resetting the syscall function pointers.
A kernel rootkit of this nature would initialize the syscall hooks by using code like the following, which assumes we want to intercept the sys_write, and sys_ioctl syscalls; perhaps we intercept sys_write so that a specific line of text is not written to stdout from /etc/passwd, and sys_getdents64 to hide files.
First define function pointers to point to the original syscalls:
asmlinkage int (*old_write) (int, const void *, size_t);
asmlinkage int (*old_getdents64) (unsigned int, struct dirent *, unsigned int);
Next we would create new syscalls which serve evil purposes i.e.
asmlinkage int new_write(int fd, const void *buf, size_t bytes)
{
... evil code ...
printk(KERN_INFO "This syscall has been hijacked");
... Call original syscall ...
return old_write(fd, buf, bytes);
}
We would do the same with getdents64 -- however this is not a guide on writing rootkits so I will not cover the real details involved.
To perform the actual syscall interception within a kernel module you would do:
-- module_init() -- /* save original */ old_write = (void *) sys_call_table[__NR_write]; /* redirect pointer to new code */ sys_call_table[__NR_write] = (void *) new_write; /* same thing */ old_getdents64 = (void *) sys_call_table[__NR_getdents64]; sys_call_table[__NR_getdents64] = (void *) new_getdents64;
Now future calls to sys_write and sys_getdents64 are going to be executing the code located at new_write and new_getdents64, which will transfer execution over to the original syscall code once finished.
Once the kernel module is removed the syscalls should be reset:
-- module_exit() -- sys_call_table[__NR_write] = (void *)old_write; sys_call_table[__NR_getdents64] = (void *)old_getdents64;
This type of kernel rootkit is still common, but is not as stealth as certain newer methods. There are several tools which can detect this type of kernel rootkit, and even one that can disable them like ktraq which is featured on http://www.bitlackeys.com -- there are however times when a tool like this may not be available etc. Here is a method that is useful for detecting this type of infection:
# grep sys_call_table /boot/System.map
(or /proc/kallsyms if the option for all kernel symbols is enabled)
Assuming the result is: c048d720
# gdb /usr/src/linux/vmlinuxThen within gdb you could do
(gdb) x/10 0xc048d720 0xc048d720: 0xc0127460 0xc011f950 0xc01021a0 0xc01646f0 0xc048d730 : 0xc0164760 0xc0162340 0xc0163320 0xc011f1c0 0xc048d740 : 0xc0162380 0xc016d4b0 (gdb)
Although instead of doing x/10 you would want to do x/N whereas N is the number of syscalls which you can find in /usr/include/asm/unistd.h generally.
In another console you will want to open up /proc/kcore, you can do this by doing
# gdb /usr/src/linux/vmlinux /proc/kcore
You would have to follow the same steps :
Core was generated by `BOOT_IMAGE=2.6.25-nosmp ro root=803 acpi=off nomsi'.
#0 0x00000000 in ?? () (gdb) x/10 0xc048d720 0xc048d720: 0xc0127460 0xc011f950 0xc01021a0 0xc01646f0 0xc048d730 : 0xf897f6d0 0xf897f5d0 0xc0163320 0xc011f1c0 0xc048d740 : 0xc0162380 0xc016d4b0 (gdb)
Notice the 5th entry has changed from 0xc0164760 to 0xf897f6d0; that is because sys_write has been hijacked.
This type of analysis can also be useful for other types of kernel infection including syscall interception by overwriting the first several bytes of a syscall with a jmp or a push/ret. In Linux one must be careful not to mistake changes for runtime patches -- which have a very specific set of alternative instructions for memory barriers and SMP replacements.
Spy DLL Remover
Tools-SpyDLLRemover
Rootkit Analytics
Hidden Process Detection
Tools-Elfstat
Spy DLL Remover32266
Elfstat1054
KsiD670
SHC504
dwtf415