CWE-1241 Base Brouillon

Use of Predictable Algorithm in Random Number Generator

This vulnerability occurs when a device or application relies on a predictable algorithm to generate pseudo-random numbers, making the output sequence foreseeable.

Définition

What is CWE-1241?

This vulnerability occurs when a device or application relies on a predictable algorithm to generate pseudo-random numbers, making the output sequence foreseeable.
Pseudo-random number generators (PRNGs) create numbers using deterministic algorithms, meaning they have a finite internal state that will eventually repeat. This predictability makes them vulnerable to attacks where an adversary can analyze past outputs to deduce future values or uncover the generator's internal state, compromising the security of any system that depends on this randomness. For robust security, especially in encryption, key generation, or session tokens, it's critical to use hardware-based True Random Number Generators (TRNGs). TRNGs derive randomness from unpredictable physical processes like electrical noise, producing outputs that are unbiased, independent, and fundamentally unpredictable, thereby providing a much stronger foundation for security-critical operations.
Impact réel

Real-world CVEs caused by CWE-1241

  • PHP framework uses mt_rand() function (Marsenne Twister) when generating tokens

Comment les attaquants l'exploitent

Parcours de l'attaquant étape par étape

  1. 1

    Suppose a cryptographic function expects random value to be supplied for the crypto algorithm.

  2. 2

    During the implementation phase, due to space constraint, a cryptographically secure random-number-generator could not be used, and instead of using a TRNG (True Random Number Generator), a LFSR (Linear Feedback Shift Register) is used to generate a random value. While an LFSR will provide a pseudo-random number, its entropy (measure of randomness) is insufficient for a cryptographic algorithm.

  3. 3

    The example code is taken from the PRNG inside the buggy OpenPiton SoC of HACK@DAC'21 [REF-1370]. The SoC implements a pseudo-random number generator using a Linear Feedback Shift Register (LFSR).

  4. 4

    An example of LFSR with the polynomial function P(x) = x 6+x 4+x 3+1 is shown in the figure.

  5. 5

    A LFSR's input bit is determined by the output of a linear function of two or more of its previous states. Therefore, given a long cycle, a LFSR-based PRNG will enter a repeating cycle, which is predictable.

Exemple de code vulnérable

Vulnerable Verilog

An example of LFSR with the polynomial function P(x) = x 6+x 4+x 3+1 is shown in the figure.

Vulnérable Verilog
**reg in_sr, entropy16_valid;** 

 **reg [15:0] entropy16;** 


 **assign entropy16_o = entropy16;** 

 **assign entropy16_valid_o = entropy16_valid;** 


 **always @ (*)** 

 **begin** 

```
```
in_sr = ^ (poly_i [15:0] & entropy16 [15:0]);** 
  
 **end**
Exemple de code sécurisé

Secure pseudo

Sécurisé pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
  const safe = validateAndEscape(input);
  return executeWithGuards(safe);
}
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Liste de contrôle de prévention

How to prevent CWE-1241

  • Architecture and Design A true random number generator should be specified for cryptographic algorithms.
  • Implementation A true random number generator should be implemented for cryptographic algorithms.
Signaux de détection

How to detect CWE-1241

SAST High

Exécuter une analyse statique (SAST) sur le code source à la recherche du motif non sécurisé dans le flux de données.

DAST Moderate

Exécuter des tests de sécurité applicative dynamique (DAST) contre le point de terminaison en ligne.

Runtime Moderate

Surveiller les journaux runtime pour détecter des traces d'exception inhabituelles, des entrées malformées ou des tentatives de contournement d'autorisation.

Code review Moderate

Revue de code : signaler tout nouveau code qui traite les entrées de cette surface sans utiliser les helpers du framework validés.

Correction automatique Plexicus

Plexicus détecte automatiquement CWE-1241 et ouvre une PR de correction en moins de 60 secondes.

Codex Remedium analyse chaque commit, identifie cette faiblesse précise et livre une pull request prête à être relue avec le correctif. Pas de tickets. Pas de transferts.

Questions fréquentes

Frequently asked questions

Qu'est-ce que CWE-1241 ?

This vulnerability occurs when a device or application relies on a predictable algorithm to generate pseudo-random numbers, making the output sequence foreseeable.

Quelle est la gravité de CWE-1241 ?

MITRE n'a pas publié de note de probabilité d'exploitation pour cette faiblesse. Traitez-la comme un impact moyen jusqu'à ce que votre modèle de menace prouve le contraire.

Quels langages ou plateformes sont affectés par CWE-1241 ?

MITRE lists the following affected platforms: System on Chip.

Comment puis-je prévenir CWE-1241 ?

A true random number generator should be specified for cryptographic algorithms. A true random number generator should be implemented for cryptographic algorithms.

Comment Plexicus détecte et corrige CWE-1241 ?

Le moteur SAST de Plexicus reconnaît la signature de flux de données de CWE-1241 à chaque commit. Lorsqu'une correspondance est trouvée, notre agent Codex Remedium ouvre une PR de correction avec le code corrigé, les tests et un résumé d'une ligne pour le relecteur.

Où puis-je en savoir plus sur CWE-1241 ?

MITRE publie la définition canonique à https://cwe.mitre.org/data/definitions/1241.html. Vous pouvez également consulter la documentation OWASP et NIST pour des conseils adjacents.

Faiblesses associées

Weaknesses related to CWE-1241

CWE-330 Parent

Use of Insufficiently Random Values

This vulnerability occurs when an application uses random values that are not sufficiently unpredictable in security-sensitive operations,…

CWE-1204 Frère

Generation of Weak Initialization Vector (IV)

This vulnerability occurs when software uses a weak or predictable Initialization Vector (IV) for cryptographic operations. Many…

CWE-331 Frère

Insufficient Entropy

This vulnerability occurs when a system's random number generator or algorithm lacks sufficient unpredictability, creating patterns or…

CWE-334 Frère

Small Space of Random Values

This vulnerability occurs when a system uses a random number generator that produces too few possible values. Attackers can easily predict…

CWE-335 Frère

Incorrect Usage of Seeds in Pseudo-Random Number Generator (PRNG)

This vulnerability occurs when a Pseudo-Random Number Generator (PRNG) is used, but its initial seed value is not handled securely or…

CWE-338 Frère

Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG)

This vulnerability occurs when software uses a pseudo-random number generator (PRNG) that is not cryptographically strong for…

CWE-340 Frère

Generation of Predictable Numbers or Identifiers

This vulnerability occurs when a system creates numbers or identifiers that are too easy to guess, undermining security mechanisms that…

CWE-344 Frère

Use of Invariant Value in Dynamically Changing Context

This vulnerability occurs when code uses a fixed, unchanging value (like a hardcoded string, number, or reference) in a situation where…

Prêt quand vous l'êtes

Arrêtez de payer par développeur.
Commencez à fermer la boucle.

Plexicus est l'ASPM natif IA qui scanne, filtre, corrige, penteste et explique — de façon autonome. Développeurs illimités, dépôts illimités, actions IA à usage équitable. Vrai niveau gratuit, €269/mo annuel quand vous êtes prêt.