免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1952 | 回复: 6
打印 上一主题 下一主题

请教一个“段错误”问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-06-17 14:40 |只看该作者 |倒序浏览
各位大侠,有个shellcode的问题,请大家指点,谢谢!

我的平台是虚拟机上的 redhat 9.0.,kernel为2.4.20-8,gcc为 3.2.2.
编译下面这个样本程序:

char sc[] =
    "\x31\xc0"
    "\x50"
    "\x68\x6e\x2f\x73\x68"
    "\x68\x2f\x2f\x62\x69"
    "\x89\xe3"
    "\x50"
    "\x53"
    "\x89\xe1"
    "\xb0\x0b"
    "\xcd\x80"
;
int main()
{
       void    (*fp)(void) = (void (*)(void))sc;

       printf("Length: %d\n",strlen(sc));
       fp();
}



运行结果:

Length:23
段错误

如果我去掉 程序中: printf("Length: %d\n",strlen(sc));

运行结果是正确的,派生出一个SHELL。

搞不明白怎么回事,请各位大侠指点,再次感谢!

[ 本帖最后由 ShareThought 于 2008-6-17 14:42 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2008-06-18 08:04 |只看该作者
顶上来

让大家看到

论坛徽章:
0
3 [报告]
发表于 2008-06-18 11:11 |只看该作者
>>fp();

fp是函数指针,不是函数

论坛徽章:
0
4 [报告]
发表于 2008-06-18 11:46 |只看该作者
来看看gdb调试的过程

  1. [xiaodao@dev t]$ gcc -g foo.c
  2. [xiaodao@dev t]$ gdb ./a.out
  3. GNU gdb Red Hat Linux (6.6-35.fc8rh)
  4. Copyright (C) 2006 Free Software Foundation, Inc.
  5. GDB is free software, covered by the GNU General Public License, and you are
  6. welcome to change it and/or distribute copies of it under certain conditions.
  7. Type "show copying" to see the conditions.
  8. There is absolutely no warranty for GDB.  Type "show warranty" for details.
  9. This GDB was configured as "i386-redhat-linux-gnu"...
  10. Using host libthread_db library "/lib/libthread_db.so.1".
  11. (gdb) list
  12. 10          "\x50"
  13. 11          "\x53"
  14. 12          "\x89\xe1"
  15. 13          "\xb0\x0b"
  16. 14          "\xcd\x80"
  17. 15      ;
  18. 16
  19. 17      int main()
  20. 18      {
  21. 19             void    (*fp)(void) = (void (*)(void))sc;
  22. (gdb)
  23. 20
  24. 21             printf("Length: %d\n",strlen(sc));
  25. 22             fp();
  26. 23      }
  27. (gdb) b 22
  28. Breakpoint 1 at 0x804840c: file foo.c, line 22.
  29. (gdb) r
  30. Starting program: /home/xiaodao/t/a.out

  31. warning: Missing the separate debug info file: /usr/lib/debug/.build-id/ac/2eeb206486bb7315d6ac4cd64de0cb50838ff6.debug

  32. warning: Missing the separate debug info file: /usr/lib/debug/.build-id/ba/4ea1118691c826426e9410cafb798f25cefad5.debug
  33. Length: 23

  34. Breakpoint 1, main () at foo.c:22
  35. 22             fp();
  36. (gdb) p sc
  37. $1 = "1hn/shh//bi\211?\211?v?200"
  38. (gdb) p &sc
  39. $2 = (char (*)[24]) 0x804966c
  40. (gdb) p fp
  41. $3 = (void (*)(void)) 0x804966c <sc>
  42. (gdb) p &fp
  43. $4 = (void (**)(void)) 0xbf8ed28c
  44. (gdb) n

  45. Program received signal SIGSEGV, Segmentation fault.             //这里收到了SIGSEGV信号
  46. 0x0804840f in main () at foo.c:22
  47. 22             fp();
  48. (gdb)
复制代码

论坛徽章:
0
5 [报告]
发表于 2008-06-18 14:10 |只看该作者
谢谢 xi2008wang :wink:

论坛徽章:
0
6 [报告]
发表于 2008-06-18 21:43 |只看该作者
我在Fc 6中运行没有出现段错误的情况.

论坛徽章:
0
7 [报告]
发表于 2008-06-19 15:10 |只看该作者
不明白 为什么?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP