{"@ID": "335", "@Name": "Incorrect Usage of Seeds in Pseudo-Random Number Generator (PRNG)", "@Abstraction": "Base", "@Structure": "Simple", "@Status": "Draft", "Description": "The product uses a Pseudo-Random Number Generator (PRNG) but does not correctly manage seeds.", "Extended_Description": {"xhtml:p": ["PRNGs are deterministic and, while their output appears\n\t\t   random, they cannot actually create entropy. They rely on\n\t\t   cryptographically secure and unique seeds for entropy so\n\t\t   proper seeding is critical to the secure operation of the\n\t\t   PRNG.", "Management of seeds could be broken down into two main areas:", "PRNGs require a seed as input to generate a stream of\n\t\t\t   numbers that are functionally indistinguishable from\n\t\t\t   random numbers.  While the output is, in many cases,\n\t\t\t   sufficient for cryptographic uses, the output of any\n\t\t\t   PRNG is directly determined by the seed provided as\n\t\t\t   input. If the seed can be ascertained by a third party,\n\t\t\t   the entire output of the PRNG can be made known to\n\t\t\t   them. As such, the seed should be kept secret and\n\t\t\t   should ideally not be able to be guessed. For example,\n\t\t\t   the current time may be a poor seed. Knowing the\n\t\t\t   approximate time the PRNG was seeded greatly reduces\n\t\t\t   the possible key space.", "Seeds do not necessarily need to be unique, but reusing seeds may open up attacks if the seed is discovered."], "xhtml:ul": {"xhtml:li": ["(1) protecting seeds as cryptographic material (such as a cryptographic key);", "(2) whenever possible, using a uniquely generated seed from\n\t\t   a cryptographically secure source"]}}, "Related_Weaknesses": {"Related_Weakness": [{"@Nature": "ChildOf", "@CWE_ID": "330", "@View_ID": "1000", "@Ordinal": "Primary"}, {"@Nature": "ChildOf", "@CWE_ID": "330", "@View_ID": "1003", "@Ordinal": "Primary"}]}, "Weakness_Ordinalities": {"Weakness_Ordinality": [{"Ordinality": "Primary"}, {"Ordinality": "Resultant"}]}, "Applicable_Platforms": {"Language": {"@Class": "Not Language-Specific", "@Prevalence": "Undetermined"}}, "Modes_Of_Introduction": {"Introduction": {"Phase": "Implementation", "Note": "REALIZATION: This weakness is caused during implementation of an architectural security tactic."}}, "Common_Consequences": {"Consequence": {"Scope": ["Access Control", "Other"], "Impact": ["Bypass Protection Mechanism", "Other"], "Note": "If a PRNG is used incorrectly, such as using the same seed for each initialization or using a predictable seed, then an attacker may be able to easily guess the seed and thus the random numbers. This could lead to unauthorized access to a system if the seed is used for authentication and authorization."}}, "Detection_Methods": {"Detection_Method": {"@Detection_Method_ID": "DM-14", "Method": "Automated Static Analysis", "Description": "Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect \"sources\" (origins of input) with \"sinks\" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)"}}, "Demonstrative_Examples": {"Demonstrative_Example": [{"@Demonstrative_Example_ID": "DX-177", "Intro_Text": "The following code uses a statistical PRNG to generate account IDs.", "Example_Code": {"@Nature": "Bad", "@Language": "Java", "xhtml:div": {"xhtml:br": null, "xhtml:div": {"@style": "margin-left:1em;", "xhtml:br": null, "#text": "Random random = new Random(SEED);return random.nextInt();"}, "#text": "private static final long SEED = 1234567890;public int generateAccountID() {}"}}, "Body_Text": "Because the program uses the same seed value for every invocation of the PRNG, its values are predictable, making the system vulnerable to attack."}, {"@Demonstrative_Example_ID": "DX-102", "Intro_Text": "Both of these examples use a statistical PRNG seeded with the current value of the system clock to generate a random number:", "Example_Code": [{"@Nature": "Bad", "@Language": "Java", "xhtml:div": {"xhtml:br": null, "#text": "Random random = new Random(System.currentTimeMillis());int accountID = random.nextInt();"}}, {"@Nature": "Bad", "@Language": "C", "xhtml:div": {"xhtml:br": null, "#text": "srand(time());int randNum = rand();"}}], "Body_Text": "An attacker can easily predict the seed used by these PRNGs, and so also predict the stream of random numbers generated. Note these examples also exhibit CWE-338 (Use of Cryptographically Weak PRNG)."}, {"@Demonstrative_Example_ID": "DX-178", "Intro_Text": "This code grabs some random bytes and uses them for a seed in a PRNG, in order to generate a new cryptographic key.", "Example_Code": {"@Nature": "Bad", "@Language": "Python", "xhtml:div": {"xhtml:i": "# getting 2 bytes of randomness for the seeding the PRNG", "xhtml:br": [null, null, null, null], "#text": "seed = os.urandom(2)\n\t\t\t\t  random.seed(a=seed)\n\t\t\t\t  key = random.getrandbits(128)"}}, "Body_Text": "Since only 2 bytes are used as a seed, an attacker will only need to guess 2^16 (65,536) values before being able to replicate the state of the PRNG."}]}, "Observed_Examples": {"Observed_Example": [{"Reference": "CVE-2020-7010", "Description": "Cloud application on Kubernetes generates passwords using a weak random number generator based on deployment time.", "Link": "https://www.cve.org/CVERecord?id=CVE-2020-7010"}, {"Reference": "CVE-2019-11495", "Description": "server uses erlang:now() to seed the PRNG, which\n\t\t\t results in a small search space for potential random\n\t\t\t seeds", "Link": "https://www.cve.org/CVERecord?id=CVE-2019-11495"}, {"Reference": "CVE-2018-12520", "Description": "Product's PRNG is not seeded for the generation of session IDs", "Link": "https://www.cve.org/CVERecord?id=CVE-2018-12520"}, {"Reference": "CVE-2016-10180", "Description": "Router's PIN generation is based on rand(time(0)) seeding.", "Link": "https://www.cve.org/CVERecord?id=CVE-2016-10180"}]}, "Taxonomy_Mappings": {"Taxonomy_Mapping": {"@Taxonomy_Name": "PLOVER", "Entry_Name": "PRNG Seed Error"}}, "References": {"Reference": {"@External_Reference_ID": "REF-44", "@Section": "\"Sin 20: Weak Random Numbers.\" Page 299"}}, "Mapping_Notes": {"Usage": "Allowed", "Rationale": "This CWE entry is at the Base level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.", "Comments": "Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.", "Reasons": {"Reason": {"@Type": "Acceptable-Use"}}}, "Notes": {"Note": {"@Type": "Maintenance", "#text": "As of CWE 4.5, terminology related to randomness, entropy, and\n\t   predictability can vary widely. Within the developer and other\n\t   communities, \"randomness\" is used heavily. However, within\n\t   cryptography, \"entropy\" is distinct, typically implied as a\n\t   measurement. There are no commonly-used definitions, even within\n\t   standards documents and cryptography papers. Future versions of\n\t   CWE will attempt to define these terms and, if necessary,\n\t   distinguish between them in ways that are appropriate for\n\t   different communities but do not reduce the usability of CWE for\n\t   mapping, understanding, or other scenarios."}}, "Content_History": {"Submission": {"Submission_Name": "PLOVER", "Submission_Date": "2006-07-19", "Submission_Version": "Draft 3", "Submission_ReleaseDate": "2006-07-19"}, "Modification": [{"Modification_Name": "Eric Dalci", "Modification_Organization": "Cigital", "Modification_Date": "2008-07-01", "Modification_Version": "1.0", "Modification_ReleaseDate": "2008-09-09", "Modification_Comment": "updated Time_of_Introduction"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2008-09-08", "Modification_Version": "1.0", "Modification_ReleaseDate": "2008-09-09", "Modification_Comment": "updated Relationships, Taxonomy_Mappings"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2011-06-01", "Modification_Version": "1.13", "Modification_ReleaseDate": "2011-06-01", "Modification_Comment": "updated Common_Consequences"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2012-05-11", "Modification_Version": "2.2", "Modification_ReleaseDate": "2012-05-15", "Modification_Comment": "updated Common_Consequences, References, Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2017-11-08", "Modification_Version": "3.0", "Modification_ReleaseDate": "2017-11-08", "Modification_Comment": "updated Applicable_Platforms, Description, Modes_of_Introduction, Name, Relationships, Type"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2019-06-20", "Modification_Version": "3.3", "Modification_ReleaseDate": "2019-06-20", "Modification_Comment": "updated Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2020-02-24", "Modification_Version": "4.0", "Modification_ReleaseDate": "2020-02-24", "Modification_Comment": "updated Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2021-07-20", "Modification_Version": "4.5", "Modification_ReleaseDate": "2021-07-20", "Modification_Comment": "updated Description, Maintenance_Notes, Observed_Examples"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2021-10-28", "Modification_Version": "4.6", "Modification_ReleaseDate": "2021-10-28", "Modification_Comment": "updated Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2022-10-13", "Modification_Version": "4.9", "Modification_ReleaseDate": "2022-10-13", "Modification_Comment": "updated Observed_Examples"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-01-31", "Modification_Version": "4.10", "Modification_ReleaseDate": "2023-01-31", "Modification_Comment": "updated Description"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-04-27", "Modification_Version": "4.11", "Modification_ReleaseDate": "2023-04-27", "Modification_Comment": "updated Relationships, Time_of_Introduction"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-06-29", "Modification_Version": "4.12", "Modification_ReleaseDate": "2023-06-29", "Modification_Comment": "updated Mapping_Notes"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-10-26", "Modification_Version": "4.13", "Modification_ReleaseDate": "2023-10-26", "Modification_Comment": "updated Demonstrative_Examples"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2025-12-11", "Modification_Version": "4.19", "Modification_ReleaseDate": "2025-12-11", "Modification_Comment": "updated Detection_Factors, Relationships, Weakness_Ordinalities"}], "Previous_Entry_Name": {"@Date": "2017-11-08", "#text": "PRNG Seed Error"}}}
