Writeup · Cyberweek Africa 2026 - National CTF (Finals)

Thirty-Two Questions

cryptohardsolvedFlag: FLAG{REDACTED}

Overview

A diagnostic oracle exposes four bits per query about a 96-bit release key K (12 bytes, little-endian). Each authorised account gets exactly 32 probes; the budget is server-side and persistent. The goal is to reconstruct K, then authenticate and decrypt the team’s encrypted release vault to recover the real flag.

The leakage (per DIAGNOSTIC_NOTES.txt) for taps T = [0, 11, 37, 61]:

response_bit_j = popcount(K AND ROTL_96(M, T[j])) mod 2    (j = 0..3)

packed as one hex digit bit_0 + 2*bit_1 + 4*bit_2 + 8*bit_3.

Prerequisites / Setup

  • Python 3 (requests, hashlib)
  • Network access to hxxp://chal1[.]hackathon[.]ke:8091/
  • The public QA sample qa_reference.json (for offline testing only — its flag is a decoy)

Recon

Step 1 — Enumerate endpoints

Goal: Confirm the oracle surface.

  • GET /api/status (free): returns used/remaining/max probes.
  • GET /api/vault (free): returns the team’s sealed record {nonce_hex, ciphertext_hex, tag_hex, version}.
  • POST /api/probe (1 probe): JSON {"mask_hex": "<24 hex digits>"} → {"response_hex": "0..f", ...}.
  • Zero/malformed masks return 400 and do not consume budget.

Vulnerability Analysis

The flaw class is Linear / Chosen-Plaintext Leakage — a linear oracle over GF(2) that reveals the secret bit-by-bit.

Exploitation

Step 2 — Probe single-bit masks

Goal: Recover all 96 key bits within the 32-probe budget.

A set cover over p ∈ [0, 96) with taps {0, 11, 37, 61} needs only 31 single-bit masks to touch all 96 positions — inside the 32-probe budget with one spare. For each mask M = 1<<p, the four response bits are placed at key positions (p + T[j]) mod 96.

Solver (solve.py):

  1. GET /api/status (free) to confirm budget.
  2. Probe the 31 precomputed single-bit masks M = 1<<p; extract the 4 response bits and place them at key positions (p + T[j]) mod 96.
  3. Assemble the 96 key bits → 12 bytes little-endian.
  4. GET /api/vault (free); verify the HMAC-SHA256 tag then XOR-decrypt with the SHA256-derived keystream (reference_protocol.unseal).

Recovered key (hex): 27a81a83f8853ac9737bd27c — 31 probes used, 1 remaining.

Decrypted record:

{
  "case": "SC06/RELEASE",
  "team_id": "SC06-07",
  "status": "AUTHORISED",
  "flag": "FLAG{REDACTED}",
  "notice": "QA calibration is NOT a release."
}

Flag

FLAG{REDACTED}

Lessons / Takeaways

  • “Four bits of integrity” that are linear in the secret fully leak the key given enough chosen masks: linearity over GF(2) is fatal when the attacker controls the input.
  • Single-bit masks read key bits directly here because each tap maps one mask bit to exactly one key bit — no Gaussian elimination was needed.
  • Always validate the attack path offline against the public QA sample before spending live, non-resetting probes.
  • The authenticated tag (HMAC-SHA256) is what makes the recovered plaintext authoritative; an unauthenticated XOR stream alone would not be trustworthy.

Mitigations

  • Never expose a linear oracle over a secret: add non-linearity (e.g. a real MAC, a PRF, or noise) so that responses do not leak linear equations in the key.
  • Use a bounded, per-session budget that resets and cannot be exhausted across accounts; better, do not expose a stateful oracle at all.
  • Authenticate all responses (HMAC-SHA256 or AEAD) so an attacker cannot forge or replay vault records.

Techniques

  • Linear Cryptanalysis
  • Chosen-Plaintext Attack
  • GF(2) Linear Algebra
  • Oracle Attack

References