免费注册 查看新帖 |

Chinaunix

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

我写的系统调用劫持出现crash了 [复制链接]

论坛徽章:
0
21 [报告]
发表于 2010-04-17 20:39 |只看该作者
回复  eclipse_2
那上面有完整的程序,你可以直接编译并测试一下能否正常工作。
Godbach 发表于 2010-04-17 20:35



    不对 你说的是哪儿有完整的代码?
    你上次给的连接吗? 我测试过了 在我的电脑不行的 会crash的

论坛徽章:
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
22 [报告]
发表于 2010-04-17 20:39 |只看该作者
既然知道到哪一步就出问题了,那么应该可以好调试了。打印一些关注的信息,并且提前返回。
另外,贴出完整程序可以让别人有时间时候,直接拿着你的代码调试。

论坛徽章:
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
23 [报告]
发表于 2010-04-17 20:43 |只看该作者
不对 你说的是哪儿有完整的代码?
    你上次给的连接吗? 我测试过了 在我的电脑不行的 会cras ...
eclipse_2 发表于 2010-04-17 20:39


这个链接:
http://linux.chinaunix.net/bbs/viewthread.php?tid=1147025
Linux下实现劫持系统调用的总结

论坛徽章:
0
24 [报告]
发表于 2010-04-17 20:49 |只看该作者
mainc.
  1. #include <linux/module.h>
  2. #include <linux/init.h>
  3. #include <linux/kernel.h>

  4. #define DRIVER_AUTHOR         "kamus <kamus.sun@gmail.com>"
  5. #define DRIVER_DESC          "A simple modify syscall"

  6. MODULE_AUTHOR(DRIVER_AUTHOR);
  7. MODULE_DESCRIPTION(DRIVER_DESC);
  8. MODULE_LICENSE("GPL");

  9. void** my_table;

  10. struct idt
  11. {
  12.         unsigned short offset_low;
  13.         unsigned short sel;
  14.         unsigned char none,flags;
  15.         unsigned short offset_high;
  16. }__attribute__ ((packed));
  17. #define gdb_printk(format,args...) \
  18.         printk(KERN_INFO "Entry Function:%s-%s-%d "format,__FILE__,__FUNCTION__,__LINE__,##args)

  19. static unsigned long get_syscall_table()
  20. {

  21. #define  OFFSET_SYSCALL         100
  22.         unsigned char idtr[6] = {0};
  23.         struct idt *idt;
  24.         unsigned int sys_call_off = 0;
  25.         unsigned int retval;

  26. //        char sc_asm[OFFSET_SYSCALL] = {0};

  27.         asm (
  28.                 "sidt %0"
  29.                 :"=m"(idtr)
  30.                 :
  31. //                :"a"(idtrp)
  32.                 :"memory"
  33.                 );
  34.         gdb_printk("idt base 0x%x\t limit 0x%x\n",*(unsigned int *)(idtr+2),*(unsigned short *)idtr);

  35.         idt = (struct idt *)(*(unsigned int *)&idtr[2] + 8 * 0x80);
  36. //        gdb_printk("idt offset1 is 0x%x\n",idt->offset_low);
  37.         gdb_printk("syscall offset is 0x%x\n",sys_call_off);
  38.         return 0;
  39. }

  40. static int intercept_init(void)
  41. {
  42.         my_table = (void **)get_syscall_table();
  43.         if(my_table == NULL)
  44.                 return -1;
  45.         gdb_printk("syscall table %p\n",(void *)my_table);
  46.         return 0;
  47. }
  48. static int __init syscall_init(void)
  49. {
  50.         int ret;
  51.         gdb_printk("entry syscall module\n");
  52.         ret = intercept_init();
  53.         return 0;
  54. }

  55. static void __exit syscall_exit(void)
  56. {
  57.         gdb_printk("exit syscall module\n");
  58. }


  59. module_init(syscall_init);
  60. module_exit(syscall_exit);
复制代码
Makefile
  1. TARGET:=syscall

  2. syscall-objs:=main.o misc.o
  3. obj-m:=$(TARGET).o

  4. KERNELDIR:=/lib/modules/${shell uname -r}/build
  5. PWD:=${shell pwd}

  6. .PHONY:install uninstall clean
  7. default:
  8.         $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
  9. install:
  10.         insmod $(TARGET).ko
  11. uninstall:
  12.         rmmod $(TARGET).ko
  13. clean:
  14.         rm -rf *.o *.mod.c Module.*
复制代码

论坛徽章:
0
25 [报告]
发表于 2010-04-17 20:50 |只看该作者
这个链接:

Linux下实现劫持系统调用的总结
Godbach 发表于 2010-04-17 20:43



    呵呵 用过了 直接crash了

论坛徽章:
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
26 [报告]
发表于 2010-04-17 21:22 |只看该作者
作为一个搞研发的,只说一句直接crash了是不够的。

论坛徽章:
0
27 [报告]
发表于 2010-04-17 21:23 |只看该作者
作为一个搞研发的,只说一句直接crash了是不够的。
Godbach 发表于 2010-04-17 21:22



    呵呵 我不是搞研发的 水平太次了 我是打酱油的

论坛徽章:
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
28 [报告]
发表于 2010-04-17 21:25 |只看该作者
我的意思是说,既然crash了,有什么样的提示信息,你总得说一下吧

论坛徽章:
0
29 [报告]
发表于 2010-04-17 21:39 |只看该作者
我的意思是说,既然crash了,有什么样的提示信息,你总得说一下吧
Godbach 发表于 2010-04-17 21:25



   恩 你贴的那个连接的代码 在我的电脑上 RHEL 5.4上运行的 crash 抓图

k.jpg (843.8 KB, 下载次数: 24)

k.jpg

论坛徽章:
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
30 [报告]
发表于 2010-04-17 21:49 |只看该作者
图上最后一个行提示EIP执行出错了。反汇编看一下clear_and_return_cr0函数中的那一条指令出问题了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP