【问题标题】:Why this isnt exploitable with the exit function为什么这不能被 exit 函数利用
【发布时间】:2014-01-16 22:15:15
【问题描述】:

我有一段代码只是 strcpy() argv1 在 100 字节长的缓冲区中。之后,出于测试目的,我放置了 exit(0) 或 exit(1) 函数。没用别的。我从 gdb 得到的结果如下

 (gdb) i r eip
 eip            0x8048455   0x8048455 <main+65>
 (gdb) info frame
 Stack level 0, frame at 0xbffff260:
eip = 0x8048455 in main (exploitable.c:9); saved eip 0x41414141
source language c.
Arglist at 0xbffff258, args: argc=1094795585, argv=0xbffff304
 Locals at 0xbffff258, Previous frame's sp is 0xbffff260
 Saved registers:
 ebp at 0xbffff258, eip at 0xbffff25c
(gdb) i r eip
eip            0x8048455    0x8048455 <main+65>
(gdb) c
Continuing.
[Inferior 1 (process 2829) exited normally]

既然保存的 eip 是 0x41414141,为什么在离开当前堆栈后执行会转到无效的 0x41414141 地址?当然它与退出功能有关,但我无法理解:/

我知道解释在下面的代码中,但我看不懂

   => 0x08048455 <+65>: mov    DWORD PTR [esp],0x0
   0x0804845c <+72>:    call   0x8048350 <exit@plt>

最后一行意味着执行转到退出函数,我不确定 0x08040455 行是否显示传递给退出函数的 0 参数。 Exit 函数在运行时没有任何 leave/ret 指令吗?因为“刚刚”在主框架之外的框架的保存的eip被覆盖了!

【问题讨论】:

  • 这不清楚。听起来您知道“保存的 eip”实际上是返回地址。那么有什么问题呢?

标签: c gdb stack buffer-overflow


【解决方案1】:

exit 函数不返回。它调用用atexit() 定义的函数,进行一些清理,然后通过用函数0 (EXIT) 调用Linux 来终止进程。

使用return 1 / return 0 而不是exit(1) / exit(0),如果您想检查EIPmain() 完成后会发生什么。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-30
    • 2021-01-09
    • 1970-01-01
    • 2013-01-17
    • 2016-07-02
    • 2019-12-08
    相关资源
    最近更新 更多