What it is: Predictable Seed in Pseudo-Random Number Generator (PRNG) (CWE-337) is a type of cryptographic vulnerability where the PRNG is initialized from predictable values.
Why it matters: This can lead to compromised security by allowing attackers to predict future random numbers and compromise systems.
How to fix it: Use non-predictable inputs for seed generation, such as high-quality entropy sources.
TL;DR: Predictable Seed in Pseudo-Random Number Generator (PRNG) is a critical vulnerability that can be mitigated by using non-predictable seed values.
| Field | Value |
|---|---|
| CWE ID | CWE-337 |
| OWASP Category | A04:2025 - Cryptographic Failures |
| CAPEC | None known |
| Typical Severity | Critical |
| Affected Technologies | Cryptography libraries, random number generators |
| Detection Difficulty | Moderate |
| Last Updated | 2026-07-29 |
What is Predictable Seed in Pseudo-Random Number Generator (PRNG)?
Predictable Seed in Pseudo-Random Number Generator (PRNG) (CWE-337) is a type of cryptographic vulnerability that occurs when the PRNG is initialized from predictable values, such as process IDs or system time. As defined by the MITRE Corporation under CWE-337 and classified by the OWASP Foundation under A04:2025 - Cryptographic Failures, this weakness can severely compromise security.
Quick Summary
Predictable Seed in Pseudo-Random Number Generator (PRNG) is a critical vulnerability that occurs when PRNGs are initialized with predictable seed values. This allows attackers to predict future random numbers and compromise cryptographic systems. Understanding the root cause, attack flow, prerequisites for exploitation, and secure coding practices can help mitigate this risk.
Jump to: Quick Summary · Predictable Seed in Pseudo-Random Number Generator (PRNG) Overview · How Predictable Seed in Pseudo-Random Number Generator (PRNG) Works · Business Impact of Predictable Seed in Pseudo-Random Number Generator (PRNG) · Predictable Seed in Pseudo-Random Number Generator (PRNG) Attack Scenario · How to Detect Predictable Seed in Pseudo-Random Number Generator (PRNG) · How to Fix Predictable Seed in Pseudo-Random Number Generator (PRNG) · Framework-Specific Fixes for Predictable Seed in Pseudo-Random Number Generator (PRNG) · How to Ask AI to Check Your Code for Predictable Seed in Pseudo-Random Number Generator (PRNG) · Predictable Seed in Pseudo-Random Number Generator (PRNG) Best Practices Checklist · Predictable Seed in Pseudo-Random Number Generator (PRNG) FAQ · Vulnerabilities Related to Predictable Seed in Pseudo-Random Number Generator (PRNG) · References · Scan Your Own Site
Predictable Seed in Pseudo-Random Number Generator (PRNG) Overview
What
Predictable Seed in PRNG is a cryptographic vulnerability where the seed used to initialize a pseudo-random number generator (PRNG) is predictable.
Why it matters
This weakness compromises security by allowing attackers to predict future random numbers and exploit systems.
Where it occurs
It commonly occurs in applications that use PRNGs for cryptographic purposes, such as generating session keys or nonces.
Who is affected
Applications using PRNGs without proper seed initialization are at risk.
Who is NOT affected
Systems already using high-quality entropy sources to initialize their PRNGs are not vulnerable.
How Predictable Seed in Pseudo-Random Number Generator (PRNG) Works
Root Cause
The root cause of this vulnerability lies in the use of predictable values for seeding a pseudo-random number generator. Common examples include system time, process IDs, or other easily guessable sources.
Attack Flow
- Attacker identifies that the PRNG is seeded with a predictable value.
- Attacker predicts future random numbers based on the seed.
- Attacker exploits systems relying on these random values for security purposes.
Prerequisites to Exploit
- The attacker must know or be able to guess the initial seed value used by the PRNG.
- The system must rely on predictable seeds for generating cryptographic keys or other sensitive data.
Vulnerable Code
import random
random.seed(12345) # Predictable seed
This code initializes a PRNG with a fixed, predictable seed value. This makes it easy for an attacker to predict future random numbers.
Secure Code
import os
import random
# Use high-quality entropy source for seeding
random.seed(os.urandom(128))
Using os.urandom() provides a secure, unpredictable seed value that significantly reduces the risk of prediction attacks.
Business Impact of Predictable Seed in Pseudo-Random Number Generator (PRNG)
Confidentiality
Predictable seeds can lead to unauthorized access and exposure of sensitive data.
Integrity
Compromised random numbers may allow attackers to tamper with cryptographic operations, leading to integrity breaches.
Availability
Exploitation of predictable seeds can disrupt services by compromising the security mechanisms that ensure availability.
Predictable Seed in Pseudo-Random Number Generator (PRNG) Attack Scenario
- Attacker identifies a PRNG using a predictable seed.
- Attacker predicts future random numbers based on this seed.
- Attacker uses predicted values to compromise cryptographic keys or other sensitive data, leading to unauthorized access and potential data breaches.
How to Detect Predictable Seed in Pseudo-Random Number Generator (PRNG)
Manual Testing
- Review code for instances where PRNGs are seeded with predictable values like system time or process IDs.
- Verify that high-quality entropy sources are used for seeding PRNGs.
Automated Scanners (SAST / DAST)
Static analysis can detect hardcoded seeds, while dynamic testing can identify runtime issues related to seed predictability.
PenScan Detection
PenScan’s scanner engines such as ZAP and Wapiti can help identify predictable seed usage in code.
False Positive Guidance
False positives may occur if the PRNG is seeded with a non-predictable value that appears suspicious but is actually secure (e.g., os.urandom()).
How to Fix Predictable Seed in Pseudo-Random Number Generator (PRNG)
- Use non-predictable inputs for seed generation.
- Utilize high-quality entropy sources like
/dev/urandomoros.urandom(). - Periodically re-seed the PRNG with fresh entropy.
Framework-Specific Fixes for Predictable Seed in Pseudo-Random Number Generator (PRNG)
Python
import os
import random
# Use high-quality entropy source for seeding
random.seed(os.urandom(128))
This ensures that the seed used to initialize the PRNG is unpredictable and secure.
How to Ask AI to Check Your Code for Predictable Seed in Pseudo-Random Number Generator (PRNG)
Review the following Python code block for potential CWE-337 Predictable Seed in Pseudo-Random Number Generator (PRNG) vulnerabilities and rewrite it using non-predictable inputs: [paste code here]
Predictable Seed in Pseudo-Random Number Generator (PRNG) Best Practices Checklist
✅ Use high-quality entropy sources for PRNG seeding. ✅ Periodically re-seed the PRNG with fresh entropy. ✅ Avoid using predictable values like system time or process IDs as seeds.
Predictable Seed in Pseudo-Random Number Generator (PRNG) FAQ
How does predictable seed in PRNG work?
A pseudo-random number generator is initialized with a predictable value, such as the current time or process ID.
Why is predictable seed in PRNG dangerous?
It allows attackers to predict future random numbers and compromise cryptographic security.
How can I detect predictable seed in PRNG?
Use static analysis tools to identify instances where a PRNG is seeded with non-random values.
What are the best practices for fixing predictable seed in PRNG?
Ensure that the seed used to initialize the PRNG comes from a high-quality source of entropy.
Can you provide an example of vulnerable code for predictable seed in PRNG?
Initialize a PRNG with a fixed value like random.seed(12345).
How can I prevent predictable seed in PRNG using AI?
Use AI to review your code and suggest improvements based on best practices.
What are the real-world impacts of predictable seed in PRNG?
It can lead to data breaches, loss of sensitive information, and financial losses.
Vulnerabilities Related to Predictable Seed in Pseudo-Random Number Generator (PRNG)
| CWE | Name | Relationship |
|---|---|---|
| CWE-335 | Incorrect Usage of Seeds in Pseudo-Random Number Generator (PRNG) | ChildOf |
References
Scan Your Own Site
Manual code review catches what you know to look for. An automated scan catches what you didn’t. Scan your own website using PenScan to find Predictable Seed in Pseudo-Random Number Generator (PRNG) and other risks before an attacker does.