alpha

isc • 1000 points (Dynamic Decay) • Insane

DYNAMIC SCORING Current: 1000 pts Range: 1000 pts → 200 pts • Solves: 0 The seal is stored encoded, but the encoding changes depending on what you give it. Target: https://cyber-arena-2026.s3.ap-south-1.amazonaws.com/scs/binary/chall7/alpha Launch Target Submit Flag* CTF{...}

Dr.Binary
run_sandbox
run_sandbox
run_sandbox
run_sandbox
run_sandbox
run_sandbox
run_sandbox
dump_data
run_sandbox
run_sandbox
run_sandbox
run_sandbox
run_sandbox
run_sandbox
run_sandbox
run_sandbox
run_sandbox
run_sandbox
run_sandbox

The binary is a static stripped x86-64 ELF that prompts seal> and prints accepted/rejected. Ghidra found the main logic in FUN_00401660. Let me verify the details against the assembly before writing an inverter.

run_sandbox
run_sandbox
run_sandbox
run_sandbox

The assembly confirms the algorithm in FUN_00401660. Let me extract the target string and the byte at 0x47c01d, then build an exact forward model.

run_sandbox
run_sandbox

0x47c01d is "\r\n" (input terminator strip). Target is 56 chars. Now I'll write a bit-exact forward model (verified against the binary) and then invert it.

write_file
run_sandbox
edit_file
run_sandbox

No result — my model may diverge from the binary somewhere. Let me validate it directly by using gdb as an oracle: break right before the final strcmp and read the actual encoded string the binary produces for known inputs.

run_sandbox
run_sandbox

gdb works as an oracle. Now let me check my forward model against these ground-truth pairs.

run_sandbox

My model produces the correct digits as a suffix but with extra leading digits — the transformed buffer differs. Let me dump the binary's intermediate state (shuffled alphabet + transformed buffer) with gdb to find the divergence.

run_sandbox
run_sandbox

Alphabet shuffle matches exactly. Now compare the transformed buffer:

run_sandbox

The transform and alphabet match gdb exactly, yet the encoded strings differ. Let me trace the base-52 encode loop in gdb pass-by-pass to see what number it actually encodes.

run_sandbox

The trace shows 6 digits — my earlier oracle printed $rdi before LEA RDI,[RSP+0x140] executed (stale pointer), so "cND" was stale stack data. Let me redo the oracle correctly, breaking at the strcmp call itself.

run_sandbox

The model is now verified exact against the binary. Let me instrument the solver to see where inversion fails per candidate length.

run_sandbox

The full pipeline is verified, yet no length inverts. Let me double-check the comparison target string directly in memory via gdb:

run_sandbox

The model matches, but inversion fails. Let me test the inverse directly on a known plaintext/ciphertext pair from the binary (ABCD → fab5f2b8):

run_sandbox

The inverse fails on a known pair — let me trace the true intermediate values for ABCD to see where the backward chain breaks:

run_sandbox

Found it — the output block stores hi.b1 first, so reconstructing hi3 needs (o0<<8)|o1, not the swap I wrote. Fixing dec_block:

edit_file
run_sandbox

Found it — len=40 yields clean ASCII: CACTF{b4s3_f1fty_tw0_sh4k3n_n0t_st1rr3d}. Let me confirm against the binary itself:

run_sandbox

accepted ✅ — solved.

Flag

CACTF{b4s3_f1fty_tw0_sh4k3n_n0t_st1rr3d}

How it works

alpha is a static, stripped x86-64 ELF. All the logic lives in FUN_00401660 (Ghidra), verified instruction-by-instruction against the assembly:

  1. Read a line via fgets (max 127 bytes), strip at \r\n, take strlen.
  2. Length-keyed alphabet — Fisher–Yates shuffles ABC…Zabc…z using an LCG (seed = len*0x9e37, seed = seed*0x343fd + 0x269ec3, digit = (seed>>16) % (i+1)), i from 51 down to 1 — this is the "encoding changes depending on what you give it" part.
  3. 4-round block cipher over each 4-byte block (LCG seed 0x5c5b7 persists across blocks): hi' = ((hi*0x9e37) & 0xffff) + (lcg>>16) ^ (hi>>5) ^ lo, Feistel-style (hi,lo) → (new, hi); output bytes are [hi₃.b1, hi₃.b0, hi₄.b1, hi₄.b0]. The 16-bit add can carry into bit 16 and propagate, so the inverse had to enumerate those upper carry bits.
  4. Base-52 encoding of the transformed buffer using the shuffled alphabet, compared to QgfCyGedKTyZUYrXTRHtJaZNRWHwFkWQXWygDtuZjsvfLTBkpJaTyqVe (56 chars).

Solution approach (solve.py in the workspace): since every step is invertible, I brute-forced the input length (the only unknown keying the alphabet), decoded the target back through base-52, and inverted each cipher block analytically — solving hi₂/hi₁/hi₀/lo₀ backward from the two leaked 16-bit words, with hi₀ < 0x10000 / lo₀ < 0x10000 as the pinning constraints — then re-encoded the candidate forward as a self-check.

Two verification steps along the way: I used gdb as an oracle (breaking at the strcmp at 0x4018e2) to confirm my Python model reproduced the binary's encoded output byte-for-byte (after fixing two bugs: reading $rdi before the LEA at the first breakpoint, and reconstructing hi low-words as (o0<<8)|o1 instead of the swapped order). With the corrected inverse, length 40 was the only candidate yielding printable ASCII:

$ echo 'CACTF{b4s3_f1fty_tw0_sh4k3n_n0t_st1rr3d}' | ./alpha
seal> accepted