免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: Godbach
打印 上一主题 下一主题

Linux下实现劫持系统调用的总结 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2009-12-02 22:36 |只看该作者

回复 #10 Godbach 的帖子

godbach 太谦了,我是进来学习的

论坛徽章:
0
12 [报告]
发表于 2009-12-03 10:07 |只看该作者
之前这部分知识很零散,通过 Godbach 这么一串,理解了很多

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
13 [报告]
发表于 2009-12-03 10:29 |只看该作者

回复 #12 platinum 的帖子

我也是通过总结第二部分,把这个流程梳理清楚了

论坛徽章:
0
14 [报告]
发表于 2009-12-03 10:32 |只看该作者
经典,收藏了。
这样的大作,实在是一种享受。

论坛徽章:
3
金牛座
日期:2014-06-14 22:04:062015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:45
15 [报告]
发表于 2009-12-03 15:44 |只看该作者
这贴很有技术含量

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
16 [报告]
发表于 2009-12-03 15:57 |只看该作者

回复 #15 dreamice 的帖子

dreamice兄过奖了。。。

论坛徽章:
0
17 [报告]
发表于 2009-12-03 16:47 |只看该作者
Godbach的文章都很有技术内涵,顶你。

论坛徽章:
0
18 [报告]
发表于 2009-12-05 00:15 |只看该作者
本帖最后由 Godbach 于 2010-08-30 11:45 编辑

unsigned long
get_syscall_table_x86_64(void)
{
#define OFFSET_SYSCALL 256

    unsigned long     syscall_entry;
    char         sc_asm[OFFSET_SYSCALL];
    char        *p;

#ifndef CONFIG_XEN
    syscall_entry = get_syscall_from_hw(ARCH_X86_64);
#else
    if (!is_running_on_xen())
        syscall_entry = get_syscall_from_hw(ARCH_X86_64);
    else if ((is_initial_xendomain()))
        syscall_entry = get_syscall_from_xen(ARCH_X86_64);
    else
        syscall_entry = get_syscall_from_kallsyms(ARCH_X86_64);
#endif

    if (unlikely(syscall_entry == 0)) {
        printk("[%s] Could not find system_call entry\n",
               __FUNCTION__);
        return -ENOSYS;
    }
   
    memcpy(sc_asm, (void*)syscall_entry, OFFSET_SYSCALL);

    p = (char *)memmem(sc_asm, OFFSET_SYSCALL, "\xff\x14\xc5", 3);
    if (unlikely(!p)) {
        printk("[%s] Could not to find system calls table\n",
               __FUNCTION__);
        return -ENOSYS;
    }
   
    return *(unsigned long*)(p + 3);

#undef OFFSET_SYSCALL
}

评分

参与人数 1可用积分 +30 收起 理由
Godbach + 30 感谢分享

查看全部评分

论坛徽章:
0
19 [报告]
发表于 2009-12-05 00:16 |只看该作者
本帖最后由 Godbach 于 2010-08-30 11:45 编辑

unsigned long
get_syscall_from_hw(arch_t arch)
{
    unsigned long    syscall_entry = 0;
    struct idtr    idtr;
    struct idt    idt;

    switch(arch) {
    case ARCH_X86_64:
        rdmsrl(MSR_LSTAR, syscall_entry);
        break;
    case ARCH_X86:
        asm("sidt %0"
            :"=m"(idtr)
            );
        memcpy(&idt, (char *) idtr.base + 16 * 0x80, sizeof(idt));
        syscall_entry =
            (((unsigned long)idt.offset_high ) << 32) |
            (((idt.offset_middle << 16) |
              idt.offset_low) &
             0x00000000ffffffff );
        break;
    }
    return syscall_entry;
}

论坛徽章:
0
20 [报告]
发表于 2009-12-05 00:17 |只看该作者
本帖最后由 Godbach 于 2010-08-30 11:45 编辑

unsigned long
get_syscall_from_xen(arch_t arch)
{
    unsigned long        syscall_entry = 0;
    xen_domctl_t        dmctl;
    vcpu_guest_context_t    ctxt;

    dmctl.cmd        = XEN_DOMCTL_getvcpucontext;
    dmctl.domain        = 0;
    dmctl.interface_version = XEN_DOMCTL_INTERFACE_VERSION;

    dmctl.u.vcpucontext.vcpu   = 0;
    dmctl.u.vcpucontext.ctxt.p = &ctxt;

    if (unlikely(HYPERVISOR_domctl(&dmctl) != 0)) {
        printk("[%s] hypercall failed\n", __FUNCTION__);
        return 0;
    }

    switch(arch) {
    case ARCH_X86_64:
        syscall_entry = ctxt.syscall_callback_eip;
        break;
    case ARCH_X86:
        syscall_entry = ctxt.trap_ctxt[0x80].address;
        break;
    }
   
    return syscall_entry;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP