获取 return 地址 GDB

get return address GDB

我最近开始使用 GDB class,但我一直在努力。我有 an assignment 我必须做实验 1 练习 2,它需要我在代码中搜索两个漏洞并对它们执行以下操作:

The first must overwrite a return address on the stack, and the second must overwrite some other data structure that you will use to take over the control flow of the program.

我已经溢出了数据结构,我认为它在谈论的是指向它将执行的其他指令的 EIP。

现在如何到达框架的 return 地址 (RET)?任何帧,都没关系,我只想知道如何计算 RET 和 ESP 之间的字节,以便我可以减去它并得到长度。我刚开始使用 GDB,请放轻松。

Now how do I get to the return address (RET) of the frame?

要获取特定函数存储的return地址的位置,您可以在该函数处放置断点并使用info frame命令。

这是一个例子:

gdb /path/to/binary
(gdb) br main
(gdb) run
Starting program: /path/to/binary 

Breakpoint 1, 0x08048480 in main ()
(gdb) info frame
Stack level 0, frame at 0xffffd700:
eip = 0x8048480 in main; saved eip = 0xf7e3ca63
Arglist at 0xffffd6f8, args: 
Locals at 0xffffd6f8, Previous frame's sp is 0xffffd700
Saved registers:
ebp at 0xffffd6f8, eip at 0xffffd6fc

注意 saved eip = 0xf7e3ca63eip at 0xffffd6fc。 在这种情况下,您需要覆盖 0xffffd6fc 处的值,以便函数 return 的执行将以您存储在那里的值继续。