Writeup: Pride Challenge (Reverse Engineering)
Challenge Overview
Pride is a multi-layered Windows reverse engineering challenge. It requires the researcher to navigate through a protective "shell" (UPX), bypass environmental checks (Anti-Debugging/Anti-VM), and eventually reverse-engineer a custom Virtual Machine (VM) architecture to extract the hidden flag fragment.
1. Initial Analysis & Unpacking
The binary initially presents a decoy flag. Analysis with PEiD or Detect It Easy (DIE) reveals the executable is compressed with UPX.
Manual Unpacking
While a standard upx -d pride.exe is the first step, this challenge utilizes a modified UPX header. To unpack manually:
Load the binary in x64dbg.
Look for the
POPADinstruction followed by a largeJMP—this is the jump to the Original Entry Point (OEP).Use Scylla to dump the process and fix the IAT (Import Address Table).
2. Anti-Analysis Bypassing
Once unpacked, the binary performs several checks to ensure it is not being monitored.
| Technique | Mechanism | Bypass Strategy |
| PEB Check | Inspects BeingDebugged flag in the PEB. | Patch the MOV EAX, [FS:30h] result or use ScyllaHide. |
| Timing Check | Uses rdtsc to measure execution time between instructions. | Patch the conditional jump (JZ/JNZ) following the delta comparison. |
| Hardware Check | Queries CPUID for hypervisor strings (e.g., "VMware", "VBox"). | Manually edit the EAX/EBX/ECX/EDX return values in the debugger. |
| Parent Check | Verifies if the parent process is explorer.exe. | Patch the check or start the process via a shell. |
3. Virtual Machine Architecture
The core logic resides in a custom VM. To reconstruct the flag, we must understand the instruction set architecture (ISA).
Instruction Set (ISA)
The VM utilizes 16 registers (R0-R15) and a stack-based memory model.
0x01 (MOV_IMM): Loads a constant into a register.
Arithmetic:
ADD,SUB,XOR,AND,OR.Bitwise:
ROL(Rotate Left),ROR(Rotate Right),SHL/SHR(Shifts).Control Flow:
JUMP,JZ(Jump if Zero),JNZ(Jump if Not Zero).Lifecycle:
0x00 (HALT)terminates the VM.
4. Bytecode Reversal & Flag Extraction
The "Pride" fragment is not stored in plaintext. It is reconstructed at runtime through a series of transformations:
Initialization: Registers R0-R7 are loaded with obfuscated constants.
Key Injection: Registers R8-R15 are loaded with the XOR key:
PRIDE_F_}.Transformation:
Bytecode performs a loop where
R[i] = (R[i] XOR R[i+8]).A secondary pass applies a
RORby 3 bits and anADDoperation with a static salt.
Reconstruction: The VM writes the resulting bytes into a memory buffer, which forms the final string.
Flag Fragment
By tracing the VM state at the OP_HALT instruction or statically emulating the bytecode in Python, we retrieve the hex-encoded fragment:
Final Flag:
SkelerCTF{PRIDE_FRAGMENT_9F3A7E2B1C8D4A6F}
Key Learning Points
Header Manipulation: Understanding how modified packers break automated tools.
Environment Awareness: Recognizing how malware and protected software detect analysis.
VM De-obfuscation: Mapping raw hex bytecode to functional assembly logic.
Tools Used: x64dbg, IDA Pro, Scylla, Python (for emulation).
By SkelerSecurity

Comments
Post a Comment