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.)
Use of Hard-coded Cryptographic Key
This vulnerability occurs when an application embeds a fixed, unchangeable cryptographic key directly within its source code or configuration files.
What is CWE-321?
Real-world CVEs caused by CWE-321
-
Engineering Workstation uses hard-coded cryptographic keys that could allow for unathorized filesystem access and privilege escalation
-
Remote Terminal Unit (RTU) uses a hard-coded SSH private key that is likely to be used by default.
-
WiFi router service has a hard-coded encryption key, allowing root access
-
Communications / collaboration product has a hardcoded SSH private key, allowing access to root account
Parcours de l'attaquant étape par étape
- 1
The following code examples attempt to verify a password using a hard-coded cryptographic key.
- 2
The cryptographic key is within a hard-coded string value that is compared to the password. It is likely that an attacker will be able to read the key and compromise the system.
- 3
In 2022, the OT:ICEFALL study examined products by 10 different Operational Technology (OT) vendors. The researchers reported 56 vulnerabilities and said that the products were "insecure by design" [REF-1283]. If exploited, these vulnerabilities often allowed adversaries to change how the products operated, ranging from denial of service to changing the code that the products executed. Since these products were often used in industries such as power, electrical, water, and others, there could even be safety implications.
- 4
Multiple vendors used hard-coded keys for critical functionality in their OT products.
Vulnerable C
The following code examples attempt to verify a password using a hard-coded cryptographic key.
int VerifyAdmin(char *password) {
if (strcmp(password,"68af404b513073584c4b6f22b6c63e6b")) {
printf("Incorrect Password!\n");
return(0);
}
printf("Entering Diagnostic Mode...\n");
return(1);
} Secure pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
const safe = validateAndEscape(input);
return executeWithGuards(safe);
} How to prevent CWE-321
- Architecture and Design Prevention schemes mirror that of hard-coded password storage.
How to detect CWE-321
Plexicus détecte automatiquement CWE-321 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.
Frequently asked questions
Qu'est-ce que CWE-321 ?
This vulnerability occurs when an application embeds a fixed, unchangeable cryptographic key directly within its source code or configuration files.
Quelle est la gravité de CWE-321 ?
MITRE évalue la probabilité d'exploitation comme Élevée — cette faiblesse est activement exploitée et doit être priorisée pour la remédiation.
Quels langages ou plateformes sont affectés par CWE-321 ?
MITRE lists the following affected platforms: ICS/OT.
Comment puis-je prévenir CWE-321 ?
Prevention schemes mirror that of hard-coded password storage.
Comment Plexicus détecte et corrige CWE-321 ?
Le moteur SAST de Plexicus reconnaît la signature de flux de données de CWE-321 à 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-321 ?
MITRE publie la définition canonique à https://cwe.mitre.org/data/definitions/321.html. Vous pouvez également consulter la documentation OWASP et NIST pour des conseils adjacents.
Weaknesses related to CWE-321
Use of Hard-coded Credentials
This vulnerability occurs when software contains built-in, unchangeable authentication secrets like passwords or encryption keys within…
Use of Hard-coded Password
This vulnerability occurs when an application embeds a password directly into its source code or configuration files. This hard-coded…
Further reading
- MITRE — CWE-321 officiel https://cwe.mitre.org/data/definitions/321.html
- The CLASP Application Security Process https://cwe.mitre.org/documents/sources/TheCLASPApplicationSecurityProcess.pdf
- OT:ICEFALL: The legacy of "insecure by design" and its implications for certifications and risk management https://www.forescout.com/resources/ot-icefall-report/
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.