madx

Source + static ELF review

A fake hardware lock hides a 29-byte password check. The shortcut is not a traced comparison—it is understanding a position-dependent keystream and undoing its byte arithmetic.

Linux ELFx86-64 PIEBinary patchingXorshiftModular arithmeticStatic analysis
  1. 1. Hardcoded lockis_locked = 1The original program exits before asking for input.
  2. 2. Input gatestrlen(input) == 29The first newline is removed; the length is in bytes.
  3. 3. Per-byte check(input[i] + K(i)) mod 256Must match target_a[i] XOR target_b[i].
  4. 4. One final decisiondiff == 0All 29 positions must match to unlock the vault.
The lock and password are separate obstacles. You can derive the password from the supplied source and binary data without patching or running anything.

The scenario

madx is a small Linux executable that pretends to require a hardware key. In reality, lock_check() sets a local variable to 1, checks it against 1, and exits. Behind that gate is an input prompt and a custom password verifier.

The verifier does not call strcmp or memcmp. Instead, it generates a deterministic byte from the input position, adds that byte to the input character with 8-bit wrapping, and compares the result with two XOR-combined target arrays. It accumulates every mismatch and decides only after all 29 positions.

The exercise teaches how to follow control flow, distinguish instruction addresses from patch bytes, recover fixed-width arithmetic, extract actual referenced data, and algebraically invert a validator.

What was reviewed—and what was not run

The supplied madx.c, solve.py, README, and PDF text were read. The ELF header, symbols, disassembly, raw target bytes, and ZIP member were inspected as data. The executable and supplied solver were never executed, compiled, patched, or traced. Expected behavior below follows from the code, not a recorded run.

What a complete solve means

  • Explain why the original hardware-lock branch always exits.
  • Recover the exact 29-byte input requirement and newline handling.
  • Identify the position-seeded xorshift operations and their 32-bit width.
  • Read both 29-byte target arrays and invert the bytewise transformation.
  • Distinguish recovering the correct password from merely forcing a success branch.

The important equation

input[i] = ((a[i] XOR b[i]) − K(i)) mod 256. No brute force is needed when all ingredients are available.

The important correction

No libc comparison means no simple ltrace comparison leak—not “dynamic analysis is impossible.”

Reveal the recovered password / challenge flag

This is the 29-byte answer reported by the README and PDF, and supported by their supplied target arrays and recovery formula. Acceptance by a running executable was not tested here.

Password / flag · source-derived reference
madx{k3ystr34m_b34ts_ltr4c3!}

The actual C program prints [+] Access Granted. Vault unlocked. when the password matches. It does not print the flag itself; the recovered password is the challenge answer.

How the check works

Checked against madx.c

The arithmetic is reversible because the keystream depends only on a known position. The entire password is encoded in the verifier's public constants.

1. The “hardware key” is a constant branch

madx.c · lines 9–16
void lock_check(void) {
    int is_locked = 1;
    if (is_locked == 1) {
        puts("[!] FATAL ERROR: System Locked. Hardware key missing.");
        exit(1);
    }
    puts("[*] Hardware Lock bypassed! Welcome to MADX.");
}

No hardware query, device interaction, secret key exchange, or anti-debugger check appears here. main() calls this function before input handling. Setting the local constant to zero would change the branch, but is unnecessary for static password recovery.

2. Input handling fixes the password length

madx.c · input handling excerpt
char input[100];
if (!fgets(input, sizeof(input), stdin)) {
    return 1;
}
input[strcspn(input, "\n")] = '\0';

if (strlen(input) != PW_LEN) {  // PW_LEN = 29
    puts("[-] Access Denied. Incorrect length.");
    return 1;
}

fgets can store up to 99 input bytes plus the terminating NUL in this buffer. The first newline is replaced by NUL. Then strlen requires 29 bytes before the first NUL—not 29 arbitrary Unicode characters.

A carriage return \r is not explicitly stripped. A CRLF-formatted line can therefore leave an extra byte after the 29-byte password. An embedded NUL also changes the length seen by strlen.

3. A new xorshift value is seeded for each position

madx.c · lines 22–28
unsigned char keystream(int i) {
    unsigned int x = SEED ^ (unsigned int)(i * 0x9E3779B1u);
    x ^= x << 13;
    x ^= x >> 17;
    x ^= x << 5;
    return (unsigned char)(x & 0xFF);
}

For every index i, the function begins again with 0xc0ffee42 XOR (i × 0x9e3779b1). This is not a persistent PRNG state advanced from one character to the next. K(7) can be calculated directly from 7.

The inspected executable uses 32-bit multiplication, XOR, left shifts, and a logical right shift. Values wrap at 32 bits, and the caller ultimately uses the low byte. The seed and multiplier are fixed constants, not hidden inputs.

Equivalent fixed-width model · reference code only
def keystream(i):
    x = ((i * 0x9E3779B1) ^ 0xC0FFEE42) & 0xFFFFFFFF
    x = (x ^ (x << 13)) & 0xFFFFFFFF
    x = (x ^ (x >> 17)) & 0xFFFFFFFF
    x = (x ^ (x << 5)) & 0xFFFFFFFF
    return x & 0xFF

Python integers do not wrap automatically. Keeping the 32-bit masks preserves the C/assembly behavior, especially before the right shift.

4. Two arrays combine into each target byte

Both target_a and target_b contain 29 bytes. Neither alone is the target. At position i, the comparator forms T(i) = target_a[i] XOR target_b[i].

This is obfuscation, not a secret-sharing boundary: both halves are shipped in the same executable, and the verifier reveals how they combine. Their symbol names survive in the supplied binary.

5. The cast makes addition wrap at 8 bits

madx.c · complete password comparator
int check_password(const char *input) {
    unsigned int diff = 0;
    for (int i = 0; i < PW_LEN; i++) {
        unsigned char target_byte = target_a[i] ^ target_b[i];
        unsigned char transformed = (unsigned char)(input[i] + keystream(i));
        diff |= (transformed ^ target_byte);
    }
    return diff == 0;
}

The addition is truncated to an unsigned char before comparing. So the acceptance condition is (input[i] + K(i)) mod 256 = T(i). Ignoring that cast can make a decompiler's widened pseudo-C look like a different check.

6. Mismatches accumulate; they cannot cancel

A matching byte contributes zero because x XOR x = 0. A mismatch contributes a nonzero bit pattern. diff |= ... only sets bits; once a bit is set, later matches cannot clear it.

After all 29 iterations, diff == 0 means every byte matched. It is important that the accumulator uses OR, not XOR: XORing mismatch values could allow equal errors to cancel.

No early return is not a complete timing-security proof

The loop removes a classic “stop at the first wrong byte” signal. It does not prove constant-time behavior across compilers and processors, hide intermediate values from a debugger, or make reverse engineering impossible. The documentation's “un-brute-forceable” language is stronger than the source establishes.

7. Invert addition, not the xorshift generator

Recovery equation
(input[i] + K(i)) mod 256 = target_a[i] XOR target_b[i]

input[i] = ((target_a[i] XOR target_b[i]) - K(i)) & 0xFF

You do not need to reverse a PRNG state or guess a seed. Evaluate the public function at each known index, then subtract its byte from the combined target with modulo-256 wrapping.

One worked byte

At index 0, 0xbb XOR 0xdd = 0x66 and the documented keystream function yields K(0) = 0xf9. Thus (0x66 − 0xf9) mod 256 = 0x6d, the ASCII byte for m. Forward checking gives (0x6d + 0xf9) mod 256 = 0x66.

Binary & lock patch

Static byte inspection

The write-up's instruction address matches this binary. But the immediate to change begins three bytes later—and a PIE address is not automatically a file offset.

The exact binary reviewed

The local madx/madx is a 19,968-byte, little-endian ELF64 x86-64 position-independent executable. It retains a symbol table with lock_check, keystream, check_password, main, and both target arrays. Its entry point is image address 0x1140.

SHA-256 · local binary and the ZIP's matching member
3fb9be977da82922605c18bb2aa6a6546d80cf07b61d4c7379557630f8f554b2
Symbol / objectImage addressWhat to inspect
lock_check0x1229Hardcoded assignment and fatal/success control flow.
keystream0x126dMultiplier, seed, shifts 13/17/5, and 32-bit operations.
check_password0x12a9Array references, byte truncation, mismatch OR, and loop bound.
main0x1337Lock call, input, newline removal, length, and output branches.
target_a0x208029 bytes; file offset is also 0x2080 in this artifact.
target_b0x20a029 bytes; file offset is also 0x20a0 in this artifact.

Lock control flow, as disassembled

Static disassembly excerpt · matching the local ELF
1235: c7 45 fc 01 00 00 00   mov DWORD PTR [rbp-0x4], 0x1
123c: 83 7d fc 01            cmp DWORD PTR [rbp-0x4], 0x1
1240: 75 19                  jne 0x125b

1242: ...                    load fatal-error message
124c: ...                    call puts
1251: ...                    set exit status to 1
1256: ...                    call exit

125b: ...                    load bypassed-lock message
1265: ...                    call puts

Originally, the comparison is equal, so jne is not taken. Execution falls into the fatal block. If the assignment were zero, the comparison would be unequal and the existing jump would reach the success block.

Instruction start versus immediate bytes

Documented patch, shown as bytes only · not applied
Instruction start: 0x1235

Before: c7 45 fc 01 00 00 00
After:  c7 45 fc 00 00 00 00
                 ↑
Immediate starts at image address 0x1238.
Only its low byte differs for the value 1 → 0.

0x1235 names the whole instruction. Editing its immediate in a disassembler is sensible; blindly writing zero to the byte at 0x1235 would corrupt the opcode instead of changing the constant.

In this binary, the executable load segment maps file offset 0x1000 to image address 0x1000. Therefore the immediate is also at file offset 0x1238. That equality is specific to this layout.

General ELF address relationship
file_offset = segment.p_offset + (image_address - segment.p_vaddr)

For the reviewed executable segment:
0x1000 + (0x1238 - 0x1000) = 0x1238

For a PIE loaded in memory:
runtime_address = load_bias + image_address

No patch was performed

These bytes explain the author walkthrough. The original executable and ZIP were left untouched. For later owned-lab practice, work on a copy, check the original bytes and segment mapping, and confirm that only the intended operand changed.

The crucial byte truncation in the checker

Static comparator excerpt
1306: call 0x126d                   ; keystream(i)
130b: add eax, ebx                  ; add the input byte
130d: mov BYTE PTR [rbp-0x11], al   ; retain the low 8 bits
1310: movzx eax, BYTE PTR [rbp-0x11]
1314: xor al, BYTE PTR [rbp-0x12]   ; compare against combined target
131a: or DWORD PTR [rbp-0x10], eax  ; accumulate mismatches

1321: cmp DWORD PTR [rbp-0xc], 0x1c
1325: jle 0x12ca                   ; indices 0 through 28
1327: cmp DWORD PTR [rbp-0x10], 0
132b: sete al                      ; success iff diff is zero

The low-byte store at 0x130d supports modulo-256 addition directly. The README/PDF's widened decompiler excerpt does not display that cast clearly; the actual source and assembly do.

Why a library-call trace misses the secret check

The binary imports puts, strlen, printf, strcspn, fgets, fflush, and exit, among runtime support symbols. It does not import strcmp or memcmp. Its own code handles the per-byte comparison.

This removes the usual “trace strcmp and read the compared string” shortcut. It does not prevent observing instructions, registers, memory, or breakpoints with other dynamic-analysis techniques. No tracing was used in this review.

Solve walkthrough

Static recovery route

Read the validator, recover the constants, and undo the transformation. The supplied solver is short because the hard part is finding the correct equation.

No executable launch, patch, trace, or supplied-script execution is required for this reference. The steps below explain the author's solve using the source and statically inspected binary.

  1. Map the functions and the two gates

    Start from main. It calls lock_check first, then reads input, strips the newline, checks 29-byte length, and calls check_password. The symbol table makes these functions easy to locate in this artifact.

    The hardware gate explains why the original executable would stop before the prompt. It does not prevent reading the later functions statically.

  2. Understand the documented lock bypass

    Follow the assignment, comparison, and jne. The intended change is the assignment's immediate value from 1 to 0—not the comparison constant and not the instruction's opcode.

    The patchable immediate begins at image/file offset 0x1238 for this exact artifact. No patch is needed to derive the password, and no patch was made here.

  3. Recover the comparison at the right width

    Read check_password as a 29-iteration loop. Each position compares an 8-bit wrapped sum with target_a[i] XOR target_b[i]. OR-accumulated mismatches force all positions to match.

    One position's acceptance condition
    ((input[i] + keystream(i)) & 0xFF)
        == (target_a[i] ^ target_b[i])

    A library-call trace need not expose this internal loop. Static analysis is enough; dynamic analysis is not categorically ruled out.

  4. Extract exactly 29 bytes from each array

    The supplied source, solver, README, and inspected binary contain the same target data. The ELF symbols and raw bytes place target_a at 0x2080 and target_b at 0x20a0.

    Target A · 29 bytes
    bb54aac4b89dc868ba37d9cc21b2cece9f09b43ceb7e57a0ea87662216
    Target B · 29 bytes
    dd1df404c2f10622fda9430150d2c67b491e67363230c5df4f034647e3

    The array addresses are 32 bytes apart, but each object is only 29 bytes. Do not include the intervening padding as password data or start indexing at 1.

  5. Model the keystream with unsigned wrapping

    For each index 0–28, seed a fresh 32-bit value, apply XOR-shifts 13/17/5, and take the low byte. This is direct evaluation of public arithmetic, not inversion of an unknown random generator.

    Do not omit the masks in a language with unbounded integers, and do not carry the previous character's state into the next.

  6. Subtract the keystream modulo 256

    For every position, XOR the two target bytes, subtract the corresponding keystream byte, and keep the low eight bits. The recovered bytes form the password, which is also the challenge's flag.

    Complete recovery model · inert reference text
    def keystream(i):
        x = ((i * 0x9E3779B1) ^ 0xC0FFEE42) & 0xFFFFFFFF
        x = (x ^ (x << 13)) & 0xFFFFFFFF
        x = (x ^ (x >> 17)) & 0xFFFFFFFF
        x = (x ^ (x << 5)) & 0xFFFFFFFF
        return x & 0xFF
    
    target_a = bytes.fromhex(
        "bb54aac4b89dc868ba37d9cc21b2cece9f09b43ceb7e57a0ea87662216"
    )
    target_b = bytes.fromhex(
        "dd1df404c2f10622fda9430150d2c67b491e67363230c5df4f034647e3"
    )
    assert len(target_a) == len(target_b) == 29
    
    password = bytes(
        ((a ^ b) - keystream(i)) & 0xFF
        for i, (a, b) in enumerate(zip(target_a, target_b))
    )
    
    # Forward-check the equation; this never launches the ELF.
    assert all(
        ((password[i] + keystream(i)) & 0xFF)
            == (target_a[i] ^ target_b[i])
        for i in range(29)
    )
    print(password.decode("ascii"))

    This slightly annotated model shows explicit widths, byte output, and a forward-check assertion. The original 20-line solve.py is preserved on the Files page. Neither script is automatically executed by this HTML.

  7. Distinguish a derived answer from runtime proof

    The source-defined accepted input is the recovered 29-byte password. After a correct lock bypass, the success branch prints [+] Access Granted. Vault unlocked.. The unmodified binary still exits at the hardware gate even if the password is known.

    No runtime acceptance claim is made here. Patching the password branch to always succeed would demonstrate control-flow modification, not prove the password equation was solved.

Reveal the answer
29-byte password / flag
madx{k3ystr34m_b34ts_ltr4c3!}

Matches the answer in the supplied README and five-page write-up. The target constants also appear verbatim in the local ELF.

Expected output and return status

These are derived from main and lock_check. The input cases assume the hardware lock has been bypassed.

ConditionSource-defined behaviorStatus
Original hardware gateFatal “System Locked. Hardware key missing.” message, then exit.1
Input read failsReturns after the prompt; does not check a password.1
Length is not 29 bytes[-] Access Denied. Incorrect length.1
29 bytes, wrong password[-] Access Denied. Incorrect password.0
29 bytes, matching password[+] Access Granted. Vault unlocked.0

Exit code zero does not mean the password was correct

Both the accepted and rejected 29-byte password paths reach return 0. Any later test must distinguish the actual result, not use the process's zero exit code as proof of acceptance.

If a future solve looks wrong

  • Unreadable output: verify both arrays, byte order, XOR before subtraction, and 32-bit masks.
  • Correct prefix but wrong suffix: check every index is reseeded independently and both arrays contain exactly 29 bytes.
  • Negative character values: use & 0xff after subtraction to model modulo 256.
  • “Incorrect length” with a known answer: check CRLF, spaces, NULs, and UTF-8 byte length.
  • Still “System Locked”: knowing the answer does not bypass the first gate; inspect the patch location on a separate practice copy.
  • Patch corrupts an instruction: distinguish the instruction start at 0x1235 from the immediate at 0x1238.

Things to learn

Takeaways & corrections

A hidden string is not necessarily a protected secret. Precise control flow and integer widths explain this lab better than a long list of tools.

Read the validator as a mathematical function

Start with the acceptance condition, identify which quantities are known, and solve for the unknown input. Here, all array bytes, the seed, multiplier, shifts, and index are visible. The recovery requires one direct computation per byte.

Respect casts and widths

The keystream arithmetic wraps at 32 bits, while the transformed input and target comparison operate on bytes. Those are separate widths. A wide decompiler expression can omit the decisive narrowing visible in C and assembly.

Use symbols and cross-references before guessing offsets

The binary is not stripped. Named functions and array symbols make extraction straightforward. Referenced 29-byte objects are more reliable evidence than reading arbitrary blocks around a string or assuming a build always keeps the same addresses.

Understand what your tool can observe

ltrace's common use is observing library-call arguments and results. A local comparison loop can defeat the familiar libc-comparison shortcut without containing any anti-debugging feature. Choose tools based on the observable mechanism, not the absence of one convenient call.

Prove what a patch changes

Changing the hardware gate opens the path to the real password checker. Changing the checker to always accept answers a different question. Preserve that distinction when writing up a solve.

Translate addresses deliberately

A disassembler's image address, a byte offset in the file, and a runtime address after PIE relocation are different coordinates. They happen to align for the reviewed text and read-only segments; that is not a universal ELF property.

Challenge hardening versus real secrecy

MechanismWhat it actually achievesWhat it does not establish
Hardcoded hardware gateA beginner-friendly control-flow patching exercise.Real hardware-backed authentication or tamper resistance.
Manual comparison loopRemoves the direct strcmp/memcmp tracing shortcut.Immunity to debugging, instrumentation, or instruction-level analysis.
No early mismatch returnRemoves a common prefix-dependent early-exit signal.A measured or formally proven constant-time guarantee.
Position-dependent xorshift bytePrevents solving with one flat additive offset.Cryptographic unpredictability when seed and algorithm are public.
Two XORed target arraysHides a straightforward readable password string from casual inspection.Secret separation when both arrays and the combining rule are shipped together.
PIE and stack canary in the ELFOrdinary execution/memory-hardening features.Protection against reading constants or understanding the intended validator.

Better production patterns

For a real authentication system, avoid shipping a recoverable shared password in a client-side checker. Put the authorization boundary in a trusted service; for stored passwords, use an appropriate salted password-hashing scheme rather than reversible byte obfuscation.

For genuine hardware-backed decisions, authenticate the hardware's response and keep enforcement inside the appropriate trust boundary. For cryptographic comparisons, use vetted primitives appropriate to the threat model, rather than treating a hand-written accumulator as a complete security argument.

This is not an exploit of a memory bug

The documented solve reads constants and changes intended control flow in an owned training binary. No buffer overflow, injection vulnerability, or hidden operating-system privilege escalation is needed to recover this answer.

Self-check

  • Can I explain why jne is not taken in the original lock?
  • Can I identify the difference between the instruction at 0x1235 and the immediate at 0x1238?
  • Can I explain why input length means bytes, not Unicode characters?
  • Can I explain why the generator reseeds at each index?
  • Can I distinguish 32-bit state wrapping from 8-bit transformed-byte wrapping?
  • Can I show why OR-accumulated mismatches cannot cancel?
  • Can I derive the password equation without brute force?
  • Can I explain why zero process status is not proof of password acceptance?

Useful follow-up topics

ELF load segments and relocation; x86 conditional branches; compiler integer promotions; logical versus arithmetic shifts; decompiler type recovery; library-call tracing versus debugger inspection; and the difference between obfuscation and cryptographic secrecy.

Files & source notes

Provenance & read-only snapshots

Unlike the Fly collection, madx includes its source and executable. This page records the exact artifact, the supplied helper, and the limits of the review.

Reviewed file inventory

Supplied fileRoleReview
madx/madx.c83-line C source: lock, keystream, target arrays, comparison, and input flow.Read in full; core logic checked against ELF disassembly.
madx/madx19,968-byte ELF64 x86-64 PIE executable, not stripped.Read-only headers, symbols, machine code, and target-byte inspection. Never executed or patched.
madx/solve.py20-line arithmetic recovery helper.Read in full; not executed.
madx/README.mdAuthor walkthrough, patch notes, arrays, formula, and answer.Read in full; execution transcripts treated as author-reported.
madx/madx.zipPlayer archive containing a single member named madx.Member read as data and compared byte-for-byte with the local executable; identical. No extraction or execution needed.
Arshlaan_s Write-ups/madx - Reverse Engineering Write-up.pdfFive-page write-up corresponding to the README's solve.Extracted text read. Original PDF not embedded in this HTML.

Corrections to retain with the original write-up

  • “Patch at 0x1235”: that is the assignment instruction's start. Its immediate begins at 0x1238 in the reviewed binary. Do not overwrite the first opcode byte.
  • “29 characters”: the actual gate is strlen == 29, so it counts bytes before NUL after newline removal.
  • Widened pseudo-C: the transformed sum is truncated to an unsigned byte before XOR comparison. Source and assembly make the modulo-256 behavior explicit.
  • “No dynamic-tracing shortcut available”: there is no ordinary libc comparison leak. Other dynamic analysis remains possible; the source includes no anti-debugger mechanism.
  • “Constant-time-ish” / “un-brute-forceable”: no early exit removes one common signal, but does not establish absolute timing security.
  • Flag output: the helper prints the recovered password. The ELF prints an access-granted message, not the password.
  • Success status: both accepted and incorrect 29-byte inputs return zero in main.

Where to look in the source

  • Lines 5–6: password length and seed.
  • Lines 9–16: hardcoded hardware lock.
  • Lines 22–28: position-dependent keystream.
  • Lines 34–43: two 29-byte target arrays.
  • Lines 51–59: wrapped byte comparison and mismatch accumulator.
  • Lines 61–83: prompt, input, newline handling, length check, result messages, and return status.
Read the original madx.c · complete snapshot

Preserved as inert text, including the original author's stronger security claims in comments. Those claims are qualified above.

madx/madx.c · original source
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define PW_LEN 29
#define SEED   0xC0FFEE42u

/* --- Stage 1: hardware lock (unchanged from v1) ------------------------- */
void lock_check(void) {
    int is_locked = 1;
    if (is_locked == 1) {
        puts("[!] FATAL ERROR: System Locked. Hardware key missing.");
        exit(1);
    }
    puts("[*] Hardware Lock bypassed! Welcome to MADX.");
}

/* --- Stage 2: keystream generator (Change 2) ----------------------------
 * Small xorshift-style PRNG, reseeded per index. Deterministic, but not a
 * flat additive constant -- every position produces a different byte.
 * ------------------------------------------------------------------------ */
unsigned char keystream(int i) {
    unsigned int x = SEED ^ (unsigned int)(i * 0x9E3779B1u);
    x ^= x << 13;
    x ^= x >> 17;
    x ^= x << 5;
    return (unsigned char)(x & 0xFF);
}

/* --- Stage 3: target bytes, split across two arrays (Change 3) ----------
 * Neither half is the real target on its own; the real comparison bytes
 * only exist transiently on the stack inside check_password().
 * ------------------------------------------------------------------------ */
static const unsigned char target_a[PW_LEN] = {
    0xBB,0x54,0xAA,0xC4,0xB8,0x9D,0xC8,0x68,0xBA,0x37,
    0xD9,0xCC,0x21,0xB2,0xCE,0xCE,0x9F,0x09,0xB4,0x3C,
    0xEB,0x7E,0x57,0xA0,0xEA,0x87,0x66,0x22,0x16
};
static const unsigned char target_b[PW_LEN] = {
    0xDD,0x1D,0xF4,0x04,0xC2,0xF1,0x06,0x22,0xFD,0xA9,
    0x43,0x01,0x50,0xD2,0xC6,0x7B,0x49,0x1E,0x67,0x36,
    0x32,0x30,0xC5,0xDF,0x4F,0x03,0x46,0x47,0xE3
};

/* --- Stage 4: comparison with no libc call and no early exit (Change 1) -
 * Hand-rolled loop -- never calls strcmp/memcmp, so it never shows up in
 * an ltrace log. The loop always walks all 29 bytes and only makes its
 * decision at the very end (constant-time-ish, and un-brute-forceable
 * one byte at a time).
 * ------------------------------------------------------------------------ */
int check_password(const char *input) {
    unsigned int diff = 0;
    for (int i = 0; i < PW_LEN; i++) {
        unsigned char target_byte = target_a[i] ^ target_b[i];
        unsigned char transformed = (unsigned char)(input[i] + keystream(i));
        diff |= (transformed ^ target_byte);
    }
    return diff == 0;
}

int main(void) {
    lock_check();

    char input[100];
    printf("Enter the vault password: ");
    fflush(stdout);
    if (!fgets(input, sizeof(input), stdin)) {
        return 1;
    }
    input[strcspn(input, "\n")] = '\0';

    if (strlen(input) != PW_LEN) {
        puts("[-] Access Denied. Incorrect length.");
        return 1;
    }

    if (check_password(input)) {
        puts("[+] Access Granted. Vault unlocked.");
    } else {
        puts("[-] Access Denied. Incorrect password.");
    }
    return 0;
}
Read the original solve.py · complete snapshot and spoilers

The supplied helper is reproduced below as text only. Reading or copying it does not execute it.

madx/solve.py · original helper
def keystream(i):
    x = ((i * 0x9e3779b1) ^ 0xc0ffee42) & 0xFFFFFFFF
    x ^= (x << 13) & 0xFFFFFFFF
    x ^= (x >> 17)
    x ^= (x << 5) & 0xFFFFFFFF
    return x & 0xFF

target_a = bytes.fromhex(
    "bb54aac4b89dc868ba37d9cc21b2cece9f09b43ceb7e57a0ea87662216"
)
target_b = bytes.fromhex(
    "dd1df404c2f10622fda9430150d2c67b491e67363230c5df4f034647e3"
)

flag = ""
for i in range(29):
    combined = target_a[i] ^ target_b[i]
    flag += chr((combined - keystream(i)) & 0xFF)

print(flag)

Review boundaries

  • Checked statically: file inventory, ZIP/binary equality, ELF architecture and symbols, lock bytes, comparator narrowing and loop, and both target arrays.
  • Read from supplied material: source, helper, README, and extracted PDF text. Historical runtime transcripts remain the author's observations.
  • Not performed: launching the ELF, running the supplied solver, patching any artifact, compiling C, tracing, or accessing a live challenge.
  • Not embedded: the executable, ZIP, original PDF, or Git history. The complete C and Python text snapshots are embedded above.
One HTML file, no external assets or network requests. Copy buttons copy text; printing and page switching are browser features, not lab execution.