确定进行缓冲区溢出攻击所需的额外字节数(作业)

Determine needed # of extra bytes to conduct buffer overflow attack (homework)

协助完成 this buffer overflow project (.pdf) in Assembly, I'm using this guide 的第 0 级。

Goal = provide a string longer than getbuf can handle (getbuf() takes an input of 32 characters), causing an overflow and pushing the rest of the string onto the stack where you can then control where the function getbuf returns after exection (we want to call the smoke() function).

当我到达指南的第 2 步时,我需要计算我的输入字符串在原始 32 个字符输入之上应该有多少个额外字符,以便执行缓冲区溢出并调用 smoke().

(第 2 步摘录)

在我的例子中,我发现 startingAddressOfBufVariable0x55683ddc%ebp0x55683df0

我计算buffer size = addressAt%ebp+4 - startingAddressOfBufVariable,也就是0x55683df0+4 - 0x55683ddc = 0x18 = 24.

在下一步中,我应该从该结果中减去 32,以确定我的输入字符串应该有多少个额外的字符(在原来的 32 个字符之上)。然而,24 - 32 = -8。我得到一个负数!我不知道该怎么办。 从我的 32 个字符的输入字符串中减去 8 个字符?我正在尝试进行溢出,所以这没有意义。

出于 testing/guessing 目的,我继续阅读指南,假装我得到的 -8 结果实际上是阳性 8。所以我继续使用指南,打算在我的 32 个字符的字符串之上添加 8 个字符。

知道我的 smoke() 函数的地址是 0x08048b2b,我按照步骤 4 中的说明创建了我的输入文件(尽管他们为什么将 aa 更改为61?):

perl -e 'print "AA "x32, "BB "x4, "CC "x4, "2b 8b 04 08" '>hex3

(第 4 步摘录:)

所以,我是否在指南的第 2 步中使用了不正确的数学?我在数学中使用的地址不正确吗?如果它们是正确的,我如何解释 -8 结果,以及 -8 结果是什么意思,就修改我的字符输入以执行溢出攻击而言?

他们在示例 C 代码中写入缓冲区大小为 12。您必须从寄存器推断缓冲区大小是有道理的。也许用 0x18 的基本字符串大小再试一次?