Bad randomness breaks everything built on it: predictable tokens,
recoverable keys, and guessable session IDs. This skill covers
authorized assessment: spotting weak generators, testing token
predictability, and reviewing entropy sources. Test on systems you
may assess, with harmless proofs.
Quick Workflow
- Find what needs randomness: tokens, keys, nonces, session IDs,
and password resets.
- Identify the generator: OS CSPRNG, language secure random, or
something weaker.
- Test predictability: collect outputs and look for patterns.
- Check seeding: time based, PID based, or fixed seeds are
findings.
- Review VM and container entropy: fresh clones share state.
- Check for nonce and IV reuse that implies RNG failure.
- Prove impact with a prediction on a test account, not a victim.
- Recommend the OS CSPRNG everywhere, with no custom mixing.
1. Generator review and prediction test
# Search for weak generators
grep -rn "Math.random()\|rand()\|srand\|Random()" \
--include="*.js" --include="*.py" --include="*.php" --include="*.java" \
src/ | grep -v -i "test" | head -20
# Math.random for tokens, rand() for keys, srand(time) = findings
# Safe: crypto.randomBytes, secrets module, SecureRandom, getrandom
#!/usr/bin/env python3
"""Token predictability screen (authorized test endpoint)."""
import collections
# Collect reset tokens for your own test accounts
toks = ["a3f9...", "b7e1..."] # fill from captured test traffic
print("checks:")
print("1. length and alphabet (short numeric = brute forcible)")
print("2. sequential or time correlated?")
print("3. does the token change per request (no reuse)?")
# Statistical: chi-square on nibbles is a quick randomness smell test
2. Seed and entropy review
# VM snapshot issue: cloned VMs with the same RNG state generate the
# same "random" keys. Check: does first boot seed from fresh entropy?
# Containers: check /proc/sys/kernel/random/entropy_avail at keygen time
cat /proc/sys/kernel/random/entropy_avail
# Review key generation ceremonies: where, when, and on what entropy
Edge cases
- The generator is fine but the token is too short. That is a
brute force issue, not RNG; rate limiting is the fix.
- Custom "mixing" of multiple sources. Usually harmless but
unreviewed; recommend the plain OS CSPRNG instead.
- Deterministic builds need deterministic randomness. Use a seeded
DRBG documented as non security, separate from security RNG.
Escalation
- Predictable tokens confirmed: demonstrate account takeover on
your test account, then report as critical.
- Weak PRNG in key generation: the keys are compromised by design;
recommend rotation after fixing the generator.
Detection and defender view
Defenders detect RNG failures through duplicate keys or nonces in
the wild, token prediction reports, and audits of the generator
choice. The fix is boring: use the OS CSPRNG (getrandom,
BCryptGenRandom, SecRandomCopyBytes), never seed it yourself, and
review every randomness call site. Post incident, rotate everything
the weak generator produced.
Key references
- CWE-330 (Use of Insufficiently Random Values).
- CWE-338 (Use of Cryptographically Weak PRNG).
- NIST SP 800-90A: DRBG constructions.
1---2name: rng-attacks3description: Use when assessing random number generation on an4 authorized engagement. Covers weak PRNGs, seed prediction, VM5 snapshot issues, and reviewing randomness sources in code. Also use6 when tokens, keys, or nonces look predictable.7version: 1.0.08domain: crypto9lifecycle: stable10last_verified: "2026-10-23"11requires: []12extends: []13relates: [crypto-fundamentals, ecc-crypto-attacks, web-sqli]14tools:15 - name: Python16 version: "3.12"17metadata:18 source: https://skillmd.com/skills/mizazhaider-ceh/rng-attacks19---2021Bad randomness breaks everything built on it: predictable tokens,22recoverable keys, and guessable session IDs. This skill covers23authorized assessment: spotting weak generators, testing token24predictability, and reviewing entropy sources. Test on systems you25may assess, with harmless proofs.2627## Quick Workflow28291. Find what needs randomness: tokens, keys, nonces, session IDs,30 and password resets.312. Identify the generator: OS CSPRNG, language secure random, or32 something weaker.333. Test predictability: collect outputs and look for patterns.344. Check seeding: time based, PID based, or fixed seeds are35 findings.365. Review VM and container entropy: fresh clones share state.376. Check for nonce and IV reuse that implies RNG failure.387. Prove impact with a prediction on a test account, not a victim.398. Recommend the OS CSPRNG everywhere, with no custom mixing.4041## 1. Generator review and prediction test4243```bash44# Search for weak generators45grep -rn "Math.random()\|rand()\|srand\|Random()" \46 --include="*.js" --include="*.py" --include="*.php" --include="*.java" \47 src/ | grep -v -i "test" | head -2048# Math.random for tokens, rand() for keys, srand(time) = findings49# Safe: crypto.randomBytes, secrets module, SecureRandom, getrandom50```5152```python53#!/usr/bin/env python354"""Token predictability screen (authorized test endpoint)."""55import collections5657# Collect reset tokens for your own test accounts58toks = ["a3f9...", "b7e1..."] # fill from captured test traffic59print("checks:")60print("1. length and alphabet (short numeric = brute forcible)")61print("2. sequential or time correlated?")62print("3. does the token change per request (no reuse)?")63# Statistical: chi-square on nibbles is a quick randomness smell test64```6566## 2. Seed and entropy review6768```bash69# VM snapshot issue: cloned VMs with the same RNG state generate the70# same "random" keys. Check: does first boot seed from fresh entropy?71# Containers: check /proc/sys/kernel/random/entropy_avail at keygen time72cat /proc/sys/kernel/random/entropy_avail73# Review key generation ceremonies: where, when, and on what entropy74```7576## Edge cases7778- The generator is fine but the token is too short. That is a79 brute force issue, not RNG; rate limiting is the fix.80- Custom "mixing" of multiple sources. Usually harmless but81 unreviewed; recommend the plain OS CSPRNG instead.82- Deterministic builds need deterministic randomness. Use a seeded83 DRBG documented as non security, separate from security RNG.8485## Escalation8687- Predictable tokens confirmed: demonstrate account takeover on88 your test account, then report as critical.89- Weak PRNG in key generation: the keys are compromised by design;90 recommend rotation after fixing the generator.9192## Detection and defender view9394Defenders detect RNG failures through duplicate keys or nonces in95the wild, token prediction reports, and audits of the generator96choice. The fix is boring: use the OS CSPRNG (getrandom,97BCryptGenRandom, SecRandomCopyBytes), never seed it yourself, and98review every randomness call site. Post incident, rotate everything99the weak generator produced.100101## Key references102103- CWE-330 (Use of Insufficiently Random Values).104- CWE-338 (Use of Cryptographically Weak PRNG).105- NIST SP 800-90A: DRBG constructions.