我的ROP利用崩溃与分割错误的未知原因。这是一个易受攻击的代码(通过命令gcc h2.c -no-pie -fno-stack-protector -m32 -o h2编译):
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char string[100];
void exec_string() {
system(string);
}
void add_bin(int magic) {
if (magic == 0xdeadbeef) {
strcat(string, "/bin");
}
}
void add_sh(int magic1, int magic2) {
if (magic1 == 0xcafebabe && magic2 == 0x0badf00d) {
strcat(string, "/sh");
}
}
void vulnerable_function(char* string) {
char buffer[100];
strcpy(buffer, string);
}
int main(int argc, char** argv) {
string[0] = 0;
vulnerable_function(argv[1]);
return 0;
}我遵循了这个例子:https://medium.com/@nikhilh20/return-oriented-programming-rop-chaining-def0677923ad
此外,没有合适的pop pop ret模式的小工具(实际上,有,但有,但pop [some reg] pop ebp ret,它扰乱堆栈以及小工具的休假指令)。
我尝试了两种不同的堆栈填充来利用漏洞:第一种与我在上面提供的链接中的引物相同。第二个地址是(上高地址,下低地址):
address of exec_string
garbage value
0x0badf00d
0xcafebabe
add esp 8; pop ebx; ret <-- gadget
address of add_sh
0xdeadbeef
pop; ret gadget <-- gadget
address of add_bin <-- compromised instruction pointer after BoF
AAAA
....
112 'A's to overflow the buffer and overwrite ebp (108 + 4)
....
AAAA让我解释一下add esp, 8; pop ebx; ret的小工具。没有像pop [some reg]; pop [some reg, not ebp]; ret这样的小工具可以将调用从add_sh链接到exec_string函数,所以我尝试了一下。我选择了add esp, 8; pop ebx; ret小工具,通过add esp,8弹出0xcafebabe和0x0badf00d,然后通过pop ebx弹出未引用的垃圾值,然后从ret到exec_string。它应该完全起作用吗?如果我错了就纠正我。
此外,当我开始调试时,结果是:

酷,看起来我有一个指令指针,我需要用add_bin函数地址来替换它,然后跳转到它并启动一个ROP链。
但是..。

0x91c2b1c2中的SIGSEGV?我输入了正确的add_bin地址,ASLR,PIE和金丝雀都被禁用了。我想,也许vulnerable_function获得的字符串有一个未定义的引用,但是在上面提供的链接中,它被忽略了,所以它让我很困惑。
发布于 2020-01-12 23:59:58
问题实际上是在Python3中,它不能像Python2那样直接地输出原始字节。而且,我关于add esp, 8; pop ebx; ret小工具的理论是正确的:)这是构建ROP链的另一种方法(垃圾值没有被add_sh函数引用,所以我可以这样做,而不会陷入分段错误,在二进制中几乎没有完美的小工具时,它可能会非常有用)。下面是利用:


发布于 2020-01-12 02:57:52
如果你解决了这个问题,我相信你会成功的。
gef➤ ropper --search pop
[...]
0x0804901e: pop ebx; ret;
0x080491c4: pop edi; pop ebp; ret;
[...]在本例中,这些小工具不会“搞乱”堆栈;它们会在溢出后稍微清理堆栈,以便您能够返回到链中的下一个函数。您选择的小工具是接近的,但是需要是add esp, 4而不是8,或者不需要额外的pop。如果您在调试器中执行它,您将看到为什么。
因此,可以从上面使用pop; pop; ret。
https://security.stackexchange.com/questions/224059
复制相似问题