Writeup · Cyberweek Africa 2026 - National CTF (Finals)

Restore the System

reversinghardsolvedFlag: FLAG{REDACTED}

Overview

CTRL-A is contained but offline. The task: decrypt an encrypted RVM6 recovery firmware using the B5 token recovered in the_incident_desk, read its six-stage restoration policy, and pick the one chain of signed recovery jobs that satisfies every gate. Many jobs are correctly signed but unsafe, so a valid signature (SIGNATURE_VALID) is never enough. The console only accepts the one defensible chain, and SEAL then opens an authenticated capsule containing the flag.

flowchart LR
    B5[B5 from Ch.5] --> ROM[Decrypt ENC6 firmware]
    ROM --> POL[6 policy records]
    POL --> DFS[Per-stage gate checks over jobs + approvals + witnesses]
    DFS --> CH[Unique 6-job chain]
    CH --> SEAL[SEAL opens capsule]
    SEAL --> FLAG[Flag]

Recon

Provided files

File Role
recovery_firmware.rvm ENC6 + 12-byte nonce + XOR ciphertext (the policy)
firmware_spec.txt Firmware format, key schemes, gate semantics
recovery_jobs.csv 31 signed jobs across the six stages
recovery_approvals.csv Authorisation tickets
clock_calibration.csv Per-device clock offsets
monitor_tx/rx.csv, health_tx/rx.csv Independent witness receipts
restore_console.py Simulator (AUTH, ROM, JOBS, CHECK, LOAD, STATUS, SEAL)
sealed_recovery_capsule.json AEAD-style capsule holding the flag

Firmware decryption

KEY       = SHA256("BP06-ROM|" + B5)                         # raw 32 bytes
keystream = HMAC-SHA256(KEY, NONCE || uint32_be(n)), n = 0,1,...
payload   = ciphertext XOR keystream
payload   = "RVM6" | 0x01 | 0x06 | 6 x 17-byte records | SHA256(records)[0:8]

A correct B5 is confirmed by the RVM6\x01\x06 magic and the trailing 8-byte hash, so the wrong token fails immediately.

Policy records (decoded with the correct B5)

Each 17-byte record is opcode, device, min_tick, max_tick, epoch, flags, param_digest(8).

# Stage Opcode Device Corrected tick window Epoch Flags
1 VAULT 31 AUDIT-VAULT 520–560 47 01
2 REKEY 52 IAM-GW 540–580 48 03
3 PATCH 73 BEX-CONTROL 548–600 49 03
4 SHADOW 94 SHADOW-NODE 558–610 50 03
5 ATTEST B5 SENTINEL 570–625 51 07
6 RELEASE D6 CTRL-A 580–650 52 0B

Flag bits: 01 exact digest chain, 02 corrected ticks strictly increasing with a gap of 4–16, 04 two independent ATTEST witnesses, 08 two independent HEALTH witnesses.

Gate rules (per job)

  • Correct step order, device, BEX-3.1 firmware, case IR-51A2 and epoch.
  • param_a|param_b hashes (SHA-256, first 8 bytes) to the record’s parameter digest.
  • Job digest = SHA256(first 11 fields)[0:12] and tag HMAC valid under B5.
  • Corrected tick = local_tick − offset(device) inside the record’s window.
  • prev_digest equals SHA256("BP06|GENESIS|" + B5 + "|IR-51A2")[0:12] for stage 1, then the previous job’s digest.
  • One same ticket for all stages: GRANTED, role IR_LEAD, scope CTRL-A-RESTORE, signed, window covering the job tick, and valid_to at least the RELEASE minimum tick (580), so early-expiring tickets fail.
  • Stages 5 and 6 need a TX/RX witness pair with the same witness ID, matching job digest, at job tick +1 and +2.

Exploitation

The simulator already exposes the exact gate function, so the cleanest approach is a depth-first search: at each stage, expand only jobs the console’s own eligible() accepts, then commit the single complete chain. Solver: restore_system_solver.py.

python3 restore_system_solver.py --b5 <B5>

The search finds exactly one chain:

Stage Job Notes
1 VAULT J-B249335F ticket RC-61A7, genesis prev_digest, epoch 47
2 REKEY J-C048A48C REVOKE_LEGACY/EPOCH_48, chained to VAULT digest
3 PATCH J-B4489CF3 NONCE_BOUND/ANTI_REPLAY_ON, tick inside window and 4–16 after REKEY
4 SHADOW J-77F041C9 ISOLATED_BOOT/INTEGRITY_PASS
5 ATTEST J-7AB6CD1C witnesses W-4EECEED + W-7AEBCD3 (same SENTINEL ID)
6 RELEASE J-01A91481 CTRL-A-PROD/READ_WRITE, witnesses W-645B3ED + W-EFC5CEE

Committing these in order gives STAGES 6/6, and SEAL decrypts the capsule.

Decoy types seen in the data

Seal derivation

seal_key = SHA256("BP06-SEAL|" + B5 + "|" + job_ids + "|" + witness_ids + "|" + ROM_fingerprint)
capsule  = XOR stream under seal_key, authenticated with HMAC(seal_key, nonce || ciphertext)[0:24]

Any deviation in the chain or witness IDs changes the key, so the capsule only opens for the true chain, which is why the search must find the exact chain, not just a plausible one.

Flag

Lessons / Takeaways

Techniques

  • HMAC Authentication
  • Hash Chains
  • Clock Skew Normalisation
  • Custom XOR Stream Cipher
  • Firmware Policy Decoding