Kernel Version : 5.15.0-67-generic
OS : Ubuntu 20.04.6
Hyperviser : Oracle VM VirtualBox
- I succesfully intercepted
execvesyscall, identified commands prefxied with/hiddenand able to run the modified command. - I didn't suppress the logging.
- To hook the
execvecall we need to accesssys_call_tablewhich stores pointers of all syscalls. kallsymscontains all symbols for kernel functions and tables.- There is function called
kallsyms_lookup_namewhich takes symbol name as argument and returns address of symbol.
- In kernel versions > 5.7
kallsyms_lookup_nameis not exported. To overcome this I usedkprobes[Reference] - To get
kallsyms_lookup_nameaddress,kprobeis placed and address is fetched. - Similarly
sys_call_tableaddress can be found usingkallsyms_lookup_namefunction. - To intercept
execvesyscall, we have to overwriteexecvepointer insys_call_table
- In x86 architecture, 16th bit of
cr0register decides Write Protection. If it is 1, protection is enabled. - In default, it is 1. To disable protection we have to flip bit. Due to certain restrictions in kernel, we have to do it in assembly.
- To disable protection
new_cr0 = orginal_cr0 & ~0x00010000
- To enable protection
new_cr0 = orginal_cr0 | 0x00010000
Note :
0x00010000is hexadecimal equivalent of 2^16
- Function prototype is created for
execvesyscall and call is hooked by replacing original pointer with modifiedexecvepointer. - Filename and Arguments are obtained from registers by looking at syscall reference table
Note : This rootkit works for programs available in
/usr/bin. I cannot find path for each program. I also tried usingkmod_path_lookupthe fucntion used to find path of program. Because of NX (Non Executable) protection on memory, I cannot find the path.
- Commands prefixed with
/hiddenis identified ,Filename and Arguments are modified accordingly.
- Unloading module rollbacks original
execvesyscall.
.
