Attacking Go's Lagged Fibonacci Generator
Go's default math/rand package uses a lagged Fibonacci generator whose internal state can be fully recovered from 607 consecutive outputs, allowing an attacker to predict all future and past values. The seed used to initialise the generator can also be cracked, so secrets generated with this non-cryptographic PRNG are predictable.
Published on leviathansecurity.com
Application Security
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Go's math/rand package uses a non-cryptographically secure additive lagged Fibonacci generator that exposes its internal state directly as output, making state recovery and seed cracking feasible.
What the attacker needed
Access to 607 consecutive outputs; use of math/rand for secrets
The fix
Developers should use crypto/rand instead of math/rand for security-sensitive purposes; Go is also looking at alternatives to the lagged Fibonacci generator.
How it was found
- Record 607 consecutive outputs from Go's math/rand generator.
- Use those 607 values to reconstruct the complete internal state of the lagged Fibonacci generator.
- Continue the sequence to generate all future values without further interaction with the source.
- Apply the inverse operation (subtraction) recursively to recover all past values.
- Brute-force the unknown bits of the LCG state used during seeding to recover the original seed.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A random number generator (PRNG) is a program that produces numbers that look random but are actually calculated from a starting value called a seed. Go's standard math/rand package uses a simple algorithm that is not designed to keep secrets. If you can see enough of its output, you can work out the internal state and predict every number it will produce, including ones used as passwords or tokens.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.