Purple-team RNG analysis toolkit: detect weak PRNG usage, prove exploitability by recovering generator state, and report the correct CSPRNG remediation.
Project description
deadpoint
A purple-team RNG analysis toolkit. Point it at a stream of "random" values from software or an embedded/OT device and it will tell you whether that randomness is predictable, prove it by recovering the generator's internal state and predicting future and past outputs, then tell you exactly what the code should have used instead.
DETECT -> EXPLOIT -> REMEDIATE (blue -> red -> blue)
Non-cryptographic PRNGs (Mersenne Twister / MT19937, LCGs, xorshift) are still routinely used where unpredictability actually matters: session tokens, password reset tokens, "random" device IDs, challenge nonces, key generation on embedded gear. These generators are built for statistical quality and speed, not unpredictability — their state is fully recoverable from observed output (CWE-338, CWE-330, CWE-337). deadpoint demonstrates that, and then points you at the fix.
What makes it different from randcrack
| Capability | randcrack |
deadpoint |
|---|---|---|
MT19937 from 624 clean getrandbits(32) |
✅ | ✅ |
| Partial / truncated outputs via an SMT (Z3) model | ❌ | ✅ random(), getrandbits(k<32), randint/randrange |
Rejection sampling (randint/randrange) handled exactly |
❌ | ✅ via seed recovery + real-generator replay |
Higher-level call modelling (random(), randint, …) |
❌ | ✅ |
| Backward prediction (rewind prior outputs) | ❌ | ✅ |
Multi-family: LCG, Java Random + Math.random, PHP mt_rand, V8 Math.random |
❌ | ✅ |
| Seed recovery (small / Unix-time seeds) by replay | ❌ | ✅ |
| Detect + remediate stages, risk-rated report | ❌ | ✅ |
| Capture on-ramps (pcap, live endpoint) + optional Rust core | ❌ | ✅ |
| Embedded/OT randomness-audit framing | ❌ | ✅ |
The Z3 partial-output solver is the headline: instead of needing 624 full 32-bit words, deadpoint builds a symbolic model of the MT19937 recurrence and tempering and solves for the state from whatever bits each call actually reveals.
Install
pip install deadpoint # core (z3-solver, numpy)
pip install "deadpoint[remediate]" # + cryptography for the secure AEAD helpers
Quickstart (library)
from deadpoint import ingest, analyze, MT19937Cracker, harden
stream = ingest("tokens.txt", fmt="hex", width=32)
report = analyze(stream) # -> DetectReport
report.verdict # Verdict.WEAK
report.suspected # PRNGType.MT19937
cr = MT19937Cracker(call="getrandbits", nbits=32)
cr.feed(stream.values)
cr.recover() # untemper + state recovery
cr.predict(10) # next 10 outputs
cr.rewind(5) # 5 PRIOR outputs
# partial-output example: values came from random.randint(0, 999)
# randint/randrange use rejection sampling; deadpoint recovers a small/time seed
# and replays the REAL generator, so rejection is handled exactly.
cr = MT19937Cracker(call="randint", lo=0, hi=999)
cr.feed(observed_ints)
if cr.recover(): # exact via seed replay, or best-effort state solve
cr.predict(3)
fixes = harden(report) # -> RemediateReport (mappings + patches)
Quickstart (CLI)
deadpoint analyze tokens.txt --fmt hex --width 32
deadpoint predict outputs.txt --call randint --lo 0 --hi 999 --forward 5
deadpoint recover tokens.txt --fmt hex
deadpoint harden app.py --snippet app.py
deadpoint report device_dump.hex --fmt hex --out audit.txt
report runs the full pipeline and prints a risk-rated, plain-text audit
(CRITICAL when state is recovered and predictions verify on a holdout); add
--json anywhere for machine-readable output.
How recovery works
- Clean path. Each
getrandbits(32)output is untempered back to its raw state word (the four tempering ops are bijections). 624 consecutive words clone the generator; the global output recurrenceW[k+624] = W[k+397] ^ twist(W[k], W[k+1])gives exact forward prediction, and inverting the twist recovers prior outputs (all but the single oldest per block — MT discards 31 bits each twist). - Partial path. A Z3 model of the recurrence + tempering is constrained by
the bits each call exposes (
random()→ 27+26 bits from two words;getrandbits(k)→ top k bits;randint/randrange→ reduced togetrandbits, best-effort becauserandbelowrejection-samples), and solved for the initial state. Every recovery is confirmed against a holdout the solver never saw, so a reported success is a proven one — and an unrecoverable case (e.g. a rejection landed in the window) returns cleanly instead of lying. - Seeds. Small integer and Unix-time seeds are recovered by bounded brute
force and confirmed by replay. For call-modelled streams this runs first
(it's fast and exact): because it replays CPython's own generator, it handles
randint/randrangerejection sampling — the "subtle case" — exactly, which the symbolic path only approximates.
Additional generators (stretch)
Beyond CPython's random, deadpoint recovers three more real-world generators:
-
JavaScript / V8
Math.random(xorshift128+). A 128-bit state recovered from ~4 observed doubles via a small Z3 model, then exact forward prediction. Handles V8's 64-value cache reversal (xorshift.v8_unbatch).from deadpoint.exploit import xorshift cr = xorshift.V8Cracker(); cr.feed_and_recover(observed_doubles) cr.predict(5) # next Math.random() values
-
Java
Math.random/Random.nextDouble(48-bit LCG). Recovers the state from a single double by brute-forcing 2²² low bits, then predicts.from deadpoint.exploit import lcg st = lcg.recover_java_from_double(observed_double) lcg.java_double_predict(st, 5)
-
PHP
mt_rand(MT19937 mode). PHP output istemper(word) >> 1— bit-for-bit CPythongetrandbits(31)— so rawmt_rand()feeds straight into the Z3 solver. Includes a faithful engine, seed recovery, and range unscaling. (The legacyMT_RAND_PHPreload variant is intentionally out of scope.)from deadpoint.exploit import php cr = php.recover(raw_mt_rand_outputs) # cr.predict(n) -> future mt_rand()
Capture on-ramps (pcap + live endpoints)
Beyond files/stdin, deadpoint can pull a value stream straight from a capture or a running service (both feed the same detect/exploit pipeline):
from deadpoint.pcap import extract_stream, offset_extractor
from deadpoint.web import sample_endpoint, regex_extractor
# Modbus transaction IDs at a fixed offset in each packet of a capture
stream = extract_stream("cap.pcap", offset_extractor(offset=2, nbytes=2), width=16)
# session tokens sampled live from an endpoint (fetch is injectable for testing)
stream = sample_endpoint("https://app.test/login", 700,
regex_extractor(r'"session":"([0-9a-f]+)"'), width=32)
Native acceleration (optional)
A Rust + PyO3 crate in native/ provides a compiled deadpoint_native module
(untempering + clean state solve). deadpoint imports it automatically when
built (cd native && maturin develop --release) and falls back to pure Python
otherwise — identical results, just faster. See native/README.md.
Diff-against-secrets demo
Run the same pipeline on a weak stream and a secrets stream side by side:
deadpoint demo --count 700
WEAK — random | STRONG — secrets
verdict : WEAK | verdict : STRONG
suspected : MT19937 | suspected : CSPRNG
EXPLOIT : state recovered, verified=True | EXPLOIT : not recoverable
One stream leaks its future; the other gives deadpoint nothing. That difference
is secrets / os.urandom.
Docs
docs/usage.md— full CLI/library reference, formats, minimum sample counts.docs/case-study-ot-pairing-code.md— predicting an embedded device's "random" pairing code.docs/case-study-session-token-prediction.md— predicting web session tokens.
Non-goals (design rules, not footnotes)
- N1. deadpoint does not implement a new random number generator.
- N2. deadpoint implements no cryptographic primitive by hand. The
remediation helpers wrap vetted libraries (
secrets,cryptography's AEAD) and nothing else. "Don't roll your own crypto" is enforced in code — seedeadpoint/remediate/secure_helpers.py, where every function's docstring states which vetted library it wraps. - The tool breaks weak RNGs and recommends vetted ones — the exact inverse of rolling your own.
- Precise about families: glibc
rand()is an additive-feedback generator, not a simple LCG, and is out of scope; the clean LCG targets are JavaRandomand textbook full-output LCGs.
Ethics / dual-use
deadpoint is an auditing / defensive-research tool for systems you own or are
authorized to test. Every example here is self-assessment or authorized
pentesting. Use it to prove a weakness so you can fix it — then fix it with
secrets / os.urandom.
Development
pip install -e ".[dev]"
pytest -m "not slow" # fast suite
pytest # includes the heavier Z3 random() recovery
Correctness is checkable against ground truth: property-based tests seed a known
random.Random, run recovery, and assert predictions exactly match the
reference generator's future and past outputs.
License
MIT — see LICENSE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file deadpoint-0.2.1.tar.gz.
File metadata
- Download URL: deadpoint-0.2.1.tar.gz
- Upload date:
- Size: 45.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58e9d497644db8701f3a865e6897053fb5a395ca9d12c2acb1ba775da360801a
|
|
| MD5 |
7e643fdbaa82b4ee88b3e376cbd9555c
|
|
| BLAKE2b-256 |
c2f2010c2c22bb2f9e769a4e08f1d1b1633c6d293404c1120025c5557254b570
|
Provenance
The following attestation bundles were made for deadpoint-0.2.1.tar.gz:
Publisher:
publish.yml on Londopy/deadpoint
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
deadpoint-0.2.1.tar.gz -
Subject digest:
58e9d497644db8701f3a865e6897053fb5a395ca9d12c2acb1ba775da360801a - Sigstore transparency entry: 2142652533
- Sigstore integration time:
-
Permalink:
Londopy/deadpoint@26d51f306aaf4d8fbfcaf861795475f0bf59f696 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/Londopy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@26d51f306aaf4d8fbfcaf861795475f0bf59f696 -
Trigger Event:
release
-
Statement type:
File details
Details for the file deadpoint-0.2.1-py3-none-any.whl.
File metadata
- Download URL: deadpoint-0.2.1-py3-none-any.whl
- Upload date:
- Size: 46.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
091b32c4bee0a3e2a887a7a1ae1c741028fed7712bb1d8eb205d8fb32a90be6e
|
|
| MD5 |
197d77a32c6993287971c426dc3d6498
|
|
| BLAKE2b-256 |
680adc1606916c062ed7d405351c855de7b3d97bb1d2e70effb2aa397ad920a1
|
Provenance
The following attestation bundles were made for deadpoint-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on Londopy/deadpoint
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
deadpoint-0.2.1-py3-none-any.whl -
Subject digest:
091b32c4bee0a3e2a887a7a1ae1c741028fed7712bb1d8eb205d8fb32a90be6e - Sigstore transparency entry: 2142652567
- Sigstore integration time:
-
Permalink:
Londopy/deadpoint@26d51f306aaf4d8fbfcaf861795475f0bf59f696 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/Londopy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@26d51f306aaf4d8fbfcaf861795475f0bf59f696 -
Trigger Event:
release
-
Statement type: