Writeup · Cyberweek Africa 2026 - National CTF (Finals)

Kivuli 7: CurveBreaker

cryptoeasysolvedFlag: FLAG{REDACTED}

Overview

The challenge is an ECDH-P256 key exchange in which the server never validates that a client’s public point actually lies on the P-256 curve — the classic invalid-curve attack. Because the server accepts any client point, an attacker can force the shared secret into a small-order subgroup on a related invalid curve, leaking the server’s private key one small prime at a time. The Chinese Remainder Theorem then reassembles the full private key, and the recovered shared secret decrypts the captured session.

This is a warm-up: the attack has already been carried out. The included solver carries the recovered shared secret and only needs to be run against session.enc to reveal the flag.

Prerequisites / Setup

  • Python 3 (hashlib)
  • exchange.json, server_pubkey.pem, session.enc, attack_script.py (local challenge files)

Recon

Step 1 — Inspect the challenge files

Goal: Read exchange.json, server_pubkey.pem, and confirm the invalid-curve weakness.

Files provided in the challenge folder:

  • exchange.json — describes the ECDH-P256 exchange, the server’s public key, and explicitly notes the weakness: “Server accepts any client public point without curve membership validation” / “Invalid curve attack — server does not validate that client point lies on P-256”.
  • server_pubkey.pem — the server’s P-256 public key (uncompressed point).
  • session.enc — the captured encrypted session (100 bytes: an 8-byte nonce followed by ciphertext).
  • attack_script.py — the solver stub that holds the recovered shared secret and decrypts session.enc.

The exchange.json note confirms the server performs no curve-membership validation on the client’s public point — exactly the precondition for an invalid-curve attack.

Vulnerability Analysis

The flaw class is Missing Curve Validation in ECDH (related to CWE-327: Use of a Broken or Risky Cryptographic Algorithm).

Exploitation

Step 4 — Run the solver

Goal: Decrypt session.enc using the recovered shared secret.

No new attack is required: the invalid-curve attack has already been performed and the recovered shared secret is embedded in attack_script.py:

shared_secret = hashlib.sha256(b"small_order_curve_1234").digest()

The script derives a keystream by repeatedly hashing the shared secret with SHA-256, strips the 8-byte nonce from session.enc, XORs the ciphertext with the keystream, and prints the plaintext:

with open("session.enc", "rb") as f:
    data = f.read()
nonce = data[:8]
ct = data[8:]
ks = hashlib.sha256(shared_secret).digest() * ((len(ct) // 32) + 1)
pt = bytes(a ^ b for a, b in zip(ct, ks))
print(pt.decode())

Running the solver from the challenge folder:

python3 attack_script.py

Output:

SESSION_DECRYPTED
===============
FLAG: FLAG{REDACTED}
SESSION_SECRET: [REDACTED]
Note: Combine with CRYPTO-03 output for CRYPTO-04

Flag

FLAG{REDACTED}

The session secret is retained for the chain — it is combined with the CRYPTO-03 output for CRYPTO-04.

Lessons / Takeaways

  • No curve-membership validation. The server accepted any client public point without checking that it lies on P-256 — this is the root cause.
  • Small-order subgroups leak the private key. By supplying a client point of small order on a related invalid curve, the shared secret collapses to a small set of possibilities, leaking the server’s private key modulo each small prime.
  • CRT reassembles the key. Once enough small-prime residues are collected, the Chinese Remainder Theorem reconstructs the full private key.

Mitigations

  • Always validate that a received ECDH public point lies on the agreed curve (check the curve equation and that the point is not the point at infinity) before computing the shared secret.
  • Use static or ephemeral-ephemeral ECDH with validated points; consider using X25519/X448 which use Montgomery curves with fewer validation pitfalls.

Techniques

  • Invalid Curve Attack
  • ECDH
  • ECC

References