$ cat writeup.md…
$ cat writeup.md…
Hack.lu 2026
Task: decrypt a captured TLS 1.3 session (X25519MLKEM768) between an admin bot and a Go server whose patched kernel uses a 96-bit shared PRNG. Solution: recover the PRNG state from ServerHello.random with z3, predict the X25519 private key and ML-KEM seed, shortcut the ML-KEM shared secret via SHA3, then run the full TLS 1.3 key schedule to read the flag.
Corporate is listening... SprintBoard is secured with TLS 1.3 and post-quantum cryptography, so it's all fine, right? Take a look at the traffic:
/monitoring/capture.pcapand tell us what the admin bot is submitting.
English summary: a QEMU VM runs a Go "SprintBoard" HTTPS server (TLS 1.3, CurvePreferences = [X25519MLKEM768, X25519], port 443). An admin bot (python:3.13, OpenSSL ≥ 3.5) runs on the host (strong RNG) and POSTs a ticket containing the flag to /api/tickets with HTTP Basic auth every 45 s. A tcpdump capture of TCP/443 taken inside the VM is downloadable unauthenticated at /monitoring/capture.pcap. The only difference from a normal setup: the VM boots a patched Linux 6.18.58 kernel where drivers/char/random.c is replaced by a custom src/kernel/rng.h. Objective: decrypt the captured TLS session and read the flag from the POST body.
Flag format: flag{...} (content redacted as flag{REDACTED} in this writeup).
src/kernel/rng.h replaces the kernel CSPRNG with a single global 96-bit state shared by every consumer — getrandom(2), /dev/urandom, and all in-kernel users:
#define RNG_BITS 96 #define RNG_MASK ((((rng_u128)1) << RNG_BITS) - 1) #define RNG_C ((((rng_u128)0x9E3779B97F4A7C15ULL) << 32) | 0xF39CC0DBULL) /* one step: add constant, then two xor-rotations */ rng_step(x): x = (x + RNG_C) & RNG_MASK; x ^= rotl(x, 40); x ^= rotl(x, 23); return x & RNG_MASK; /* fill: per 4-byte block, step once and emit the top 32 bits big-endian */ rng_fill: for each 4-byte block: x = rng_step(x); w = top32(x); emit 4 bytes of w big-endian;
The state is seeded once per boot and never reseeded. Modern random.c continuously mixes entropy from timers, interrupts and jitter into its pool; this replacement does not — output is a pure function of one 96-bit state. Consequently:
The Go server (crypto/tls) runs inside the affected VM, so its side of each TLS handshake uses the weak RNG. The admin bot runs on the host with a healthy OpenSSL, so only the server's ephemeral secrets are predictable — which is enough, because the server's private X25519 key and the ML-KEM encapsulation seed fully determine the handshake secrets.
Verified against Go crypto/tls (handshake_server_tls13.go, processClientHello) for X25519MLKEM768:
ServerHello.random (plaintext on the wire — the recovery oracle).hybrid.serverSharedSecret → ecdhKeyExchange.serverSharedSecret → curve.GenerateKey).m (mlkem.Encapsulate → drbg.Read; in non-FIPS mode this is a single sysrand.Read of 32 bytes).Hybrid shared secret (RFC 10024 / Go key_schedule.go, hybridKeyExchange) is the concatenation for X25519MLKEM768:
shared_secret = ML-KEM_ss || X25519_ss # ML-KEM first
Key-share layouts:
key_share (group 0x11EC): ML-KEM ek (1184) || X25519 pub (32)key_share (group 0x11EC): ML-KEM ciphertext (1088) || X25519 pub (32)0x1301 AES-128-GCM-SHA256 or 0x1303 ChaCha20-Poly1305).For the plain X25519 fallback (group 0x001D) only two RNG reads occur (server random + X25519 private key).
A naive attack would require implementing the full ML-KEM K-PKE decryption (NTT, message recovery from the ciphertext) to obtain the shared secret. That is unnecessary.
FIPS 203 ML-KEM.Encaps_internal computes:
(K, r) = G(m || H(ek)) with G = SHA3-512, H = SHA3-256
shared_secret = K # FIRST 32 bytes of the 64-byte G output
The shared secret K does not depend on the ciphertext at all — it depends only on the encapsulation randomness m (predicted from the RNG) and the client's public encapsulation key ek (public, from the ClientHello). Therefore:
kem_ss = SHA3-512(m || SHA3-256(ek))[:32]
No K-PKE, no NTT, no ciphertext parsing beyond skipping its bytes. This is the single biggest simplification in the solve.
ServerHello.random is 32 bytes = 8 consecutive 32-bit PRNG outputs. Model step() as 96-bit Z3 bitvectors (rotl implemented via shifts + z3.LShR, & MASK), constrain the top 32 bits of the first 8 steps to equal the observed words, and solve. The relation state → 8 outputs is not injective (96 bits → 256 bits, many pre-images), but empirically all states matching the 8 observed words produce identical subsequent outputs over 15 × 60 forward trials — so any model works. The objects are small and z3 returns a model in well under a second.
import z3 BITS = 96 MASK = (1 << BITS) - 1 RC = ((0x9E3779B97F4A7C15 << 32) | 0xF39CC0DB) & MASK K1, K2 = 40, 23 def z3_step(x): x = (x + RC) & MASK x = x ^ ((x << K1 | z3.LShR(x, BITS - K1)) & MASK) x = x ^ ((x << K2 | z3.LShR(x, BITS - K2)) & MASK) return x def recover_state(server_random): words = struct.unpack(">8I", server_random) s = z3.BitVec("s", BITS) cur, sol = s, z3.Solver() for w in words: cur = z3_step(cur) sol.add(z3.Extract(95, 64, cur) == z3.BitVecVal(w, 32)) assert sol.check() == z3.sat return sol.model()[s].as_long()
Then forward the byte stream with the Python model of rng_fill:
| RNG consumption | Bytes | Meaning |
|---|---|---|
| read 1 | 32 | ServerHello.random (already known) |
| read 2 | 32 | server X25519 private key |
| read 3 | 32 | ML-KEM-768 seed m (hybrid only) |
Sanity check: clamp the recovered 32-byte private key (X25519 clamping is done by the library), derive the public key, and compare it to the X25519 component of the ServerHello key_share. In the working solve, if it does not match, the script scans RNG offsets in 4-byte steps until the derived public key equals the observed one (guards against a slightly different read ordering), then takes m from the following 32 bytes.
ecdh_ss = X25519(server_priv, client_x25519_pub) # client pub from ClientHello kem_ss = SHA3-512(m || SHA3-256(ek))[:32] # ek: ML-KEM pub from ClientHello shared = kem_ss + ecdh_ss # ML-KEM first for X25519MLKEM768
Standard RFC 8446 key schedule (HKDF with the suite hash, HKDF-Expand-Label with "tls13 " prefix and the HkdfLabel structure):
early_secret = HKDF-Extract(0, 0).derived = Derive-Secret(early_secret, "derived", "").handshake_secret = HKDF-Extract(derived, shared).th_chsh = Hash(ClientHello || ServerHello); derive c hs traffic and s hs traffic.EncryptedExtensions, Certificate, CertificateVerify, Finished) with the server handshake traffic key, appending each decrypted handshake message to the transcript.derived2 = Derive-Secret(handshake_secret, "derived", ""); master_secret = HKDF-Extract(derived2, 0).th_full = Hash(transcript through server Finished); derive c ap traffic (client application traffic secret 0).POST /api/tickets JSON body → flag.The inner content type is the last byte of each AEAD plaintext (23 = application data, 22 = handshake); the transcript must be extended with the handshake messages recovered from the server flight, stopping at the server Finished.
Reassemble TLS records per flow, then match each client flow with its reverse. Note: scapy includes Ethernet padding past IP.len as TCP payload; slice the raw IP datagram to ip.len first, then skip ihl*4 + dataofs*4:
def tcp_segment_data(pkt): ip = pkt[IP] if pkt.haslayer(IP) else pkt[IPv6] raw = bytes(ip)[:ip.len] return raw[ip.ihl * 4 + pkt[TCP].dataofs * 4:]
Select a bot handshake by its large (~1466-byte) ClientHello offering X25519MLKEM768.
nonce = iv XOR (4 zero bytes || 8-byte big-endian seq). The sequence number goes into the last 8 bytes of the 12-byte IV, not the first 8. If built the other way, only the seq = 0 record decrypts and everything after fails authentication.EncryptedExtensions legitimately ends in 0x00 (empty ALPN/SNI extension area); stripping corrupts the transcript hash and breaks server-Finished and application-key derivation.0x0303) is used in the AAD even though it is legacy.IP.len.0x11EC (hybrid, 3 RNG reads, shared = kem || ecdh) and 0x001D (plain X25519, 2 RNG reads, shared = ecdh).m. Verify by re-deriving the X25519 public key from the recovered private key against the ServerHello key_share before trusting the ordering.#!/usr/bin/env python3 # Lauschangriff: pcap -> flag. Requires z3, scapy, cryptography. import sys, struct, hmac, hashlib import z3 from cryptography.hazmat.primitives.ciphers.aead import AESGCM, ChaCha20Poly1305 from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey, X25519PublicKey from scapy.all import rdpcap, TCP, IP, IPv6 # ---- RNG model (src/kernel/rng.h) ------------------------------------------ BITS, MASK = 96, (1 << 96) - 1 RC = ((0x9E3779B97F4A7C15 << 32) | 0xF39CC0DB) & MASK K1, K2 = 40, 23 def rotl(x, r): return ((x << r) | (x >> (BITS - r))) & MASK def step(x): x = (x + RC) & MASK; x ^= rotl(x, K1); x ^= rotl(x, K2); return x & MASK def rng_bytes(state, n): out = bytearray(); i = 0 while i < n: state = step(state); w = (state >> 64) & 0xFFFFFFFF for j in range(min(4, n - i)): out.append((w >> (24 - 8 * j)) & 0xFF) i += 4 return bytes(out), state def z3_step(x): x = (x + RC) & MASK x = x ^ ((x << K1 | z3.LShR(x, BITS - K1)) & MASK) x = x ^ ((x << K2 | z3.LShR(x, BITS - K2)) & MASK) return x def recover_state(server_random): words = struct.unpack(">8I", server_random) s = z3.BitVec("s", BITS); cur = s; sol = z3.Solver() for w in words: cur = z3_step(cur) sol.add(z3.Extract(95, 64, cur) == z3.BitVecVal(w, 32)) assert sol.check() == z3.sat return sol.model()[s].as_long() # ... TLS record/handshake parsers, HKDF-Expand-Label, key schedule ... # (see repository solve.py for the complete, tested implementation) def shared_secret(sh, ch): state = recover_state(sh["random"]) _, state = rng_bytes(state, 32) # consume ServerHello.random priv_raw, state = rng_bytes(state, 32) # server X25519 private key priv = X25519PrivateKey.from_private_bytes(priv_raw) assert priv.public_key().public_bytes_raw() == sh["x25519_pub"] ecdh = priv.exchange(X25519PublicKey.from_public_bytes(ch["x25519_pub"])) if sh["group"] == 0x11EC: m, state = rng_bytes(state, 32) kem = hashlib.sha3_512(m + hashlib.sha3_256(ch["mlkem_ek"]).digest()).digest()[:32] return kem + ecdh # ML-KEM first return ecdh
After recovering shared, run the RFC 8446 key schedule, decrypt the server flight, extend the transcript, derive c ap traffic, decrypt the client application records and read:
POST /api/tickets HTTP/1.1 Authorization: Basic ... {"title": "...", "body": "flag{REDACTED}", ...}
Use this technique when:
drivers/char/random.c, getrandom, or entropy.ServerHello.random is visible and the server's PRNG has a small state that can be constrained from 32 bytes of output → try z3 bitvector recovery of the generator state.X25519MLKEM768, group 0x11EC) and you have (or can predict) the encapsulation seed m → skip K-PKE and compute ML-KEM_ss = SHA3-512(m || SHA3-256(ek))[:32].$ cat /etc/motd
Liked this one?
Pro unlocks every complete writeup and expanded API access. $9/mo.
$ cat pricing.md$ grep --similar