获取在C中的函数的地址?

在用户空间中以根用户身份运行此代码时,我遇到了segfault。我不明白为什么。我相信我有一个rootkit,我想检查地址是否与/boot/system.map-3.2.0-4-amd64中的地址相同

unsigned long hex;
unsigned long **sys_call_table;

for(hex = 0xffffffff810f8989; hex < 0xffffffff8160e370; hex += sizeof(void *))
{
    sys_call_table = (unsigned long **)hex;

    if(sys_call_table[3] == (unsigned long *)0xffffffff810f8989)
    {
        puts("sys_close's address has not been replaced by the rootkit");
    }
}

cat/boot/system.map-3.2.0-4-amd64 grep“想要的字符串”
ffffffff81401200 R sys_call_table
ffffffff810f9f9e T sys_read         // sys_call_table[0]
ffffffff810fa009 T sys_write        // sys_call_table[1]
ffffffff810f950d T sys_open         // sys_call_table[2]
ffffffff810f8989 T sys_close        // sys_call_table[3]
ffffffff8160e370 D loops_per_jiffy


最佳答案:

仅从root运行是不够的-问题是您在user space中运行它-例如在kernel space中作为内核模块运行它。尽管拥有root权限足以调用系统调用,但您无法访问表-在user space中,您只能访问分配给您的内存。