Writeup · Cyberweek Africa 2026 - National CTF (Finals)

Kivuli 6: SignTwice

cryptomedium-hardsolvedFlag: FLAG{REDACTED}

Overview

A firmware-signing service exposed an ECDSA signing oracle over secp256k1, and 20 of its signatures were captured in signatures.json. Every captured signature used the identical r value — the tell-tale sign of nonce reuse — the same per-signature nonce k was used for every signature.

Reusing an ECDSA nonce completely breaks the scheme: from any two signatures sharing r, the nonce k and then the private signing key d can be recovered algebraically. With d in hand, we forged a valid admin firmware signature carrying the fragment recovered from Kivuli 5 (deadbeef12345678) and submitted it to /verify to claim the flag.

Prerequisites / Setup

  • Python 3
  • signatures.json (local challenge file)
  • Network access to chal1[.]hackathon[.]ke:5001 for /verify

Recon

Step 1 — Inspect signatures.json

Goal: Confirm that all 20 signatures share the same r value (nonce reuse).

The supplied signatures.json contains 20 signatures, each with index, msg, r, s, and msg_hash, plus the curve (secp256k1) and its order n. Inspecting the r field across all 20 entries shows a single repeated value:

r = 0xc8dcec5809e345d06c35cf637ef6f54b02a2b5f0233021da03198bd3a952a437

All 20 signatures share this r, confirming nonce reuse. The challenge also hints that Kivuli 5 recovered the admin fragment deadbeef12345678, which must be embedded in the forged firmware.

Vulnerability Analysis

The flaw class is ECDSA Nonce Reuse. For ECDSA, s = k⁻¹(z + r·d) mod n. For two signatures (r, s₁) over z₁ and (r, s₂) over z₂ with the same k:

s₁ − s₂ ≡ k⁻¹(z₁ − z₂) (mod n)
k ≡ (z₁ − z₂) / (s₁ − s₂) (mod n)

Exploitation

Step 2 — Recover the reused nonce k

Goal: Compute k from two signatures sharing the same r.

k = (z1 - z2) * pow(s1 - s2, -1, n) % n

Using signatures 0 and 1 from signatures.json:

k = 0x4fe6c484feb0830c400eb69c818df02cdfbe290c671c3b2d3d0e3335fb4061

Step 3 — Recover the private key d

Goal: Rearrange the signing equation to solve for d.

d = (s₁·k − z₁) · r⁻¹ mod n

This yields:

d = 0xdeadbeefcafebabedeadbeefcafebabedeadbeefcafebabedeadbeefcafebabe

Step 4 — Forge the admin firmware signature

Goal: Sign an admin firmware message with the recovered d and submit to /verify.

The verifier expects the firmware as hex-encoded bytes:

fragment = "deadbeef12345678"
firmware = b"ADMIN_FIRMWARE_" + fragment.encode()
firmware_hex = firmware.hex()
firmware_hash = sha256(firmware).hexdigest()

Using the recovered fixed nonce and r, the forged s is:

s = pow(k, -1, n) * (int(firmware_hash, 16) + r * d) % n

The accepted request to /verify:

{
  "firmware": "41444d494e5f4649524d574152455f64656164626565663132333435363738",
  "firmware_hash": "36d0a0c7f6057a1d0cd4aff4ebc1790d480fea1a0078b8e4b3cb5532e2149e63",
  "r": "0xc8dcec5809e345d06c35cf637ef6f54b02a2b5f0233021da03198bd3a952a437",
  "s": "0x26a865dab1894df4d66943f078874993c7f7fb60199d2c4c0219aec8bcab7253"
}

Flag

FLAG{REDACTED}

Returned by /verify for the forged admin firmware signature.

Lessons / Takeaways

  • ECDSA nonce reuse completely breaks the scheme: two signatures sharing r leak k and then d.
  • Never reuse k; use RFC 6979 deterministic nonces.
  • With d recovered, any message can be forged under the signing key.

Mitigations

  • Use RFC 6979 deterministic nonces (derive k from the private key and message hash via HMAC-DRBG).
  • Never reuse k across signatures; each signature must use a fresh, cryptographically random nonce.
  • Verify signatures strictly: check that r and s are in [1, n−1] and that the signature verifies against the expected public key.

Techniques

References