免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123
最近访问板块 发新帖
楼主: sealdad

redhat enterPrise linux 5的系统调用劫持 [复制链接]

论坛徽章:
0
发表于 2009-09-24 11:34 |显示全部楼层
实现了,在arch下面都已经跑通了。
在 redhat 5下面sys_call_table都得不到。

论坛徽章:
0
发表于 2009-09-24 11:36 |显示全部楼层
原帖由 Godbach 于 2009-9-24 11:26 发表
记得2.6下系统调用表是可读不可写的,劫持的时候需要将其修改为可写的,你的代码中实现这一步了吗?


这个。。。。。。我再看下,不过arch下面好像不用这么弄

论坛徽章:
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
发表于 2009-09-24 11:48 |显示全部楼层
看一下这个劫持系统调用的帖子,可以获取到syscall_table,不过我这里执行同样OOps:
http://linux.chinaunix.net/bbs/thread-1135859-1-1.html

论坛徽章:
0
发表于 2009-09-24 11:57 |显示全部楼层
原帖由 Godbach 于 2009-9-24 11:48 发表
看一下这个劫持系统调用的帖子,可以获取到syscall_table,不过我这里执行同样OOps:
http://linux.chinaunix.net/bbs/thread-1135859-1-1.html


linux2.6下系统调用劫持代码的原理几乎都是一样的。
我又试了一下
Linux ids1150srvr 2.6.16.60-0.21-smp.OK

感觉是redhat LINUX 5这个版本比较特殊。

论坛徽章:
0
发表于 2009-09-24 12:44 |显示全部楼层
  1. /**
  2. * Return the first appearence of NEEDLE in HAYSTACK.  
  3. * */
  4. static void *memmem(const void *haystack, size_t haystack_len,
  5.                 const void *needle, size_t needle_len)
  6. {
  7.         const char *begin;
  8.         const char *const last_possible
  9.                 = (const char *) haystack + haystack_len - needle_len;
  10.         if (needle_len == 0)
  11.                 /* The first occurrence of the empty string is deemed to occur at
  12.                    the beginning of the string.  */
  13.                 return (void *) haystack;
  14.         /* Sanity check, otherwise the loop might search through the whole
  15.            memory.  */
  16.         if (__builtin_expect(haystack_len < needle_len, 0))
  17.                 return NULL;
  18.         for (begin = (const char *) haystack; begin <= last_possible;
  19.                         ++begin)
  20.                 if (begin[0] == ((const char *) needle)[0]
  21.                                 && !memcmp((const void *) &begin[1],
  22.                                         (const void *) ((const char *) needle + 1),
  23.                                         needle_len - 1))
  24.                         return (void *) begin;
  25.         return NULL;
  26. }
  27. /**
  28. * Find the location of sys_call_table
  29. */
  30. static unsigned long get_sys_call_table(void)
  31. {
  32.         /* we'll read first 100 bytes of int $0x80 */
  33. #define OFFSET_SYSCALL 100        
  34.         struct idtr idtr;
  35.         struct idt idt;
  36.         unsigned sys_call_off;
  37.         unsigned retval;
  38.         char sc_asm[OFFSET_SYSCALL], *p;
  39.         /* well, let's read IDTR */
  40.         asm("sidt %0":"=m"(idtr)
  41.                         :
  42.                         :"memory" );
  43.         dbgprint("idtr base at 0x%X\n", (unsigned int)idtr.base);
  44.         /* Read in IDT for vector 0x80 (syscall) */
  45.         memcpy(&idt, (char *) idtr.base + 8 * 0x80, sizeof(idt));
  46.         sys_call_off = (idt.off2 << 16) | idt.off1;
  47.         dbgprint("idt80: flags=%X sel=%X off=%X\n",
  48.                         (unsigned) idt.flags, (unsigned) idt.sel, sys_call_off);
  49.         /* we have syscall routine address now, look for syscall table
  50.            dispatch (indirect call) */
  51.         memcpy(sc_asm, (void *)sys_call_off, OFFSET_SYSCALL);
  52.         /**
  53.          * Search opcode of `call sys_call_table(,eax,4)'
  54.          */
  55.         p = (char *) memmem(sc_asm, OFFSET_SYSCALL, "\xff\x14\x85", 3);
  56.         if (p == NULL)
  57.                 return 0;
  58.         retval = *(unsigned *) (p + 3);
  59.         if (p) {
  60.                 dbgprint("sys_call_table at 0x%x, call dispatch at 0x%x\n",
  61.                                 retval, (unsigned int) p);
  62.         }
  63.         return retval;
  64. #undef OFFSET_SYSCALL
  65. }
复制代码
这个是我以前做的项目里的一部分,应该是抄的albcamus的某个帖子,在as5下没有问题。
查找前先处理cr0的第17位(还是第20位?)

[ 本帖最后由 caravsapm70 于 2009-9-24 13:06 编辑 ]

论坛徽章:
0
发表于 2009-09-24 12:49 |显示全部楼层
我的内核是2.6.18-128.1.1.el5PAE。xen的内核没有试过。

论坛徽章:
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
发表于 2009-09-24 13:28 |显示全部楼层
查找前先处理cr0的第17位(还是第20位?)

应该是第20位
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP