Writeup · Cyberweek Africa 2026 - National CTF (Finals)

Blackstar 4: The Telemetry Gateway

webhardsolvedFlag: FLAG{REDACTED}

Overview

The Blackstar Telemetry Gateway issues signed clearance tokens. Anyone who presents a valid flight-computer authorisation receives a viewer clearance token, but only operator clearance can authorise an abort and recover the abort key.

Each token consists of clearance data together with a sig computed as SHA-256(server_secret || data). Because SHA-256 is vulnerable to the length-extension attack when used in this prefix-MAC construction, we can forge a valid signature for data || padding || ";clearance=operator" without knowing the server secret — provided we guess the secret length.

Prerequisites / Setup

  • curl and python3
  • The BS02 relay token from the previous Blackstar stage (BS03: The Flight Computer) — or however the flight-computer authorisation is obtained

Recon

Step 1 — Identify the endpoints

Goal: Map the /session and /abort endpoints.

Endpoint Method Purpose
POST /session Body {"auth":"<flight-computer token>"} Issues a signed clearance token (data, sig)
GET /abort?data=<hex>&sig=<hex> — Returns the abort key when signed data carries operator clearance

Step 2 — Obtain a flight-computer authorisation

Goal: Get the BS03 relay token from the previous Blackstar stage.

The flight-computer authorisation comes from the previous Blackstar stage (BS03: The Flight Computer). Feeding the BS02 relay token into the flight-computer binary reveals the BS03 relay token:

RELAY_TOKEN=0D9E75EA984A

Step 3 — Get a viewer clearance token

Goal: POST the relay token as the flight-computer authorisation and obtain a viewer token.

curl -s -X POST "$TARGET/session" \
  -H 'Content-Type: application/json' \
  -d '{"auth":"0D9E75EA984A"}'

Response:

{
  "data": "73746174696f6e3d4e424f3b636c656172616e63653d766965776572",
  "sig": "40f7ccfc470c95a7e6b775672ddbb5cb6089ec444a00ae8e47bc771dc1bcad08"
}

Decoding the hex data:

echo '73746174696f6e3d4e424f3b636c656172616e63653d766965776572' | xxd -r -p
# station=NBO;clearance=viewer

Step 4 — Confirm /abort rejects viewer clearance

Goal: Verify that viewer clearance is insufficient and that the signature is otherwise valid.

curl -s "$TARGET/abort?data=73746174696f6e3d4e424f3b636c656172616e63653d766965776572&sig=40f7ccfc470c95a7e6b775672ddbb5cb6089ec444a00ae8e47bc771dc1bcad08"
{ "error": "viewer clearance cannot authorise an abort" }

The signature verifies (no “signature mismatch” error), but the clearance level is insufficient.

Vulnerability Analysis

The flaw class is Hash Length Extension on a broken MAC construction (SHA-256 prefix-MAC), leading to privilege escalation.

Exploitation

Step 6 — Forge an operator token via length extension

Goal: Extend the viewer token’s signature to append ;clearance=operator and grant operator clearance.

The server verifies SHA-256(server_secret || data). We know data (station=NBO;clearance=viewer) and its valid signature (the SHA-256 chaining state). For each candidate secret_len from 0 to 128:

  1. Compute pad(secret || data) — standard SHA-256 MD padding (0x80, zero bytes, 64-bit length in bits).
  2. Extend the signature with ;clearance=operator.
  3. Submit the forged (data, sig) to /abort. The correct length produces a 200 response instead of "signature mismatch".

Core of the length-extension forge (from solve.py):

ml_M = (secret_len + len(data)) * 8
zeros_bits = (448 - (ml_M + 8)) % 512
zeros_bytes = zeros_bits // 8
pad_M = b'\x80' + b'\x00' * zeros_bytes + struct.pack('>Q', ml_M)
padded_len_bits = ml_M + 8 + zeros_bits + 64

new_data = data + pad_M + b";clearance=operator"
new_state = sha256_extend(state, padded_len_bits, b";clearance=operator")
new_sig = b''.join(struct.pack('>I', x) for x in new_state).hex()

Step 7 — Recover the abort key

Goal: At the correct secret_len = 23, /abort returns the abort key.

{
  "abort_key": "14E529E26143",
  "flag_format": "FLAG{BS04_<abort_key>}",
  "note": "NULL's hostile uplink can be aborted - keep this token"
}

Flag

FLAG{REDACTED}

Derived from the abort key 14E529E26143 per the flag format FLAG{BS04_<abort_key>}.

Lessons / Takeaways

  • Never use SHA-256(secret || message) as a MAC. It is vulnerable to length-extension attacks. Use HMAC (HMAC-SHA256) or a modern AEAD/MAC construction instead.
  • When verifying signed tokens, the server must check both the signature and the authorization level embedded in the data. A valid signature over viewer data does not imply operator privileges.
  • Always treat data after the MAC boundary as untrusted until the full token (data + signature) is verified and authorised.

Mitigations

  • Use HMAC (HMAC-SHA256) instead of a plain prefix-MAC.
  • Use a modern AEAD/MAC construction (e.g. AES-GCM) for authenticated tokens.
  • Validate the full token (data + signature) and the embedded authorization level server-side before authorising any action.

Techniques

References