818
This example also exhibits a Small Seed Space (CWE-339).
Example 2:
The following code uses a statistical PRNG to create a URL for a receipt that remains active for
some period of time after a purchase.
Example Language: Java (Bad)
String GenerateReceiptURL(String baseUrl) {
Random ranGen = new Random();
ranGen.setSeed((new Date()).getTime());
return(baseUrl + ranGen.nextInt(400000000) + ".html");
}
This code uses the Random.nextInt() function to generate "unique" identifiers for the receipt pages
it generates. Because Random.nextInt() is a statistical PRNG, it is easy for an attacker to guess
the strings it generates. Although the underlying design of the receipt system is also faulty, it would
be more secure if it used a random number generator that did not produce predictable receipt
identifiers, such as a cryptographic PRNG.
Observed Examples
Reference Description
CVE-2021-3692 PHP framework uses mt_rand() function (Marsenne Twister) when generating
tokens
https://www.cve.org/CVERecord?id=CVE-2021-3692
CVE-2020-7010 Cloud application on Kubernetes generates passwords using a weak random
number generator based on deployment time.
https://www.cve.org/CVERecord?id=CVE-2020-7010
CVE-2009-3278 Crypto product uses rand() library function to generate a recovery key, making
it easier to conduct brute force attacks.
https://www.cve.org/CVERecord?id=CVE-2009-3278
CVE-2009-3238 Random number generator can repeatedly generate the same value.
https://www.cve.org/CVERecord?id=CVE-2009-3238
CVE-2009-2367 Web application generates predictable session IDs, allowing session hijacking.
https://www.cve.org/CVERecord?id=CVE-2009-2367
CVE-2009-2158 Password recovery utility generates a relatively small number of random
passwords, simplifying brute force attacks.
https://www.cve.org/CVERecord?id=CVE-2009-2158
CVE-2009-0255 Cryptographic key created with a seed based on the system time.
https://www.cve.org/CVERecord?id=CVE-2009-0255
CVE-2008-5162 Kernel function does not have a good entropy source just after boot.
https://www.cve.org/CVERecord?id=CVE-2008-5162
CVE-2008-4905 Blogging software uses a hard-coded salt when calculating a password hash.
https://www.cve.org/CVERecord?id=CVE-2008-4905
CVE-2008-4929 Bulletin board application uses insufficiently random names for uploaded files,
allowing other users to access private files.
https://www.cve.org/CVERecord?id=CVE-2008-4929
CVE-2008-3612 Handheld device uses predictable TCP sequence numbers, allowing spoofing
or hijacking of TCP connections.
https://www.cve.org/CVERecord?id=CVE-2008-3612
CVE-2008-2433 Web management console generates session IDs based on the login time,
making it easier to conduct session hijacking.
https://www.cve.org/CVERecord?id=CVE-2008-2433
CVE-2008-0166 SSL library uses a weak random number generator that only generates 65,536
unique keys.
https://www.cve.org/CVERecord?id=CVE-2008-0166
CWE Version 4.14
CWE-330: Use of Insufficiently Random Values
CWE-330: Use of Insufficiently Random Values