Solving CTF Challenges Through Reverse Engineering and Linear Algebra

Binary Analysis with IDA Pro

When analyzing check_in.exe, the following key observations were made:

  1. The program requires flag.jpg as input
  2. It performs XOR operations between file contents and a hardcoded key
  3. Output is written to hint.txt
// Simplified decompiled code snippet
void process_file() {
    FILE *input = fopen("flag.jpg", "rb");
    FILE *output = fopen("hint.txt", "wb");
    
    // Read file contents into buffer
    fseek(input, 0, SEEK_END);
    size_t size = ftell(input);
    rewind(input);
    
    char *data = malloc(size);
    char *output_buffer = malloc(size);
    fread(data, 1, size, input);
    
    // XOR transformation
    for (int i = 0; i < size; i++) {
        output_buffer[i] = key[i] ^ data[i];
    }
    
    fwrite(output_buffer, 1, size, output);
    fclose(input);
    fclose(output);
}

License Validation Challenge

The zerothree.exe binary implements a complex license validation system:

  1. Accepts username and license as input
  2. Performs XOR between username (repeated as needed) and license
  3. Validates result against 36 linear equations
# Matrix equation solver implementation
import numpy as np

def solve_license_equations(equations):
    # Parse equations into matrix form
    A = np.zeros((36, 36), dtype=int)
    b = np.zeros(36, dtype=int)
    
    for i, eq in enumerate(equations):
        # Process each equation to extract coefficients
        terms = parse_equation(eq)
        for coeff, var_idx in terms:
            A[i, var_idx - 4] = coeff  # v4 is index 0
        b[i] = eq.constant
    
    # Solve the system
    solution = np.linalg.solve(A, b)
    return np.round(solution).astype(int)

# Example usage:
username = "or4nge"
solution_vector = solve_license_equations(parsed_equations)
license = "".join([chr(ord(c) ^ s) for c, s in zip(username*(36//6+1), solution_vector)])
print(f"Valid license: {license}")

Key Techniques Demonstrated

  1. Binary Analysis:

    • IDA Pro for disassembly and decompilation
    • Understadning file I/O operations
    • Recognizing cryptographic patterns (XOR)
  2. Mathematical Solving:

    • Linear algebra for equation systems
    • Regular expressions for text processing
    • Numerical computation with NumPy
  3. Problem-Solving Approach:

    • Pattern recognition in binary behavior
    • Systematic transformation of constraints
    • Verification of intermediate results

Tags: reverse-engineering CTF linear-algebra ida-pro binary-analysis

Posted on Fri, 30 Oct 2026 16:30:04 +0000 by eric_e