CWE-321 Variant Draft High likelihood

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.

Definition

What is CWE-321?

This vulnerability occurs when an application embeds a fixed, unchangeable cryptographic key directly within its source code or configuration files.
Hard-coding cryptographic keys is a common but dangerous practice that undermines the security of encrypted data. Since the key is the same in every instance of the application and cannot be changed without modifying the code, an attacker who discovers the key (e.g., by inspecting the source code, binaries, or configuration files) can decrypt any sensitive data the application protects. This flaw effectively renders encryption useless, as the secret is no longer secret. To fix this, developers should use secure key management systems that allow keys to be stored externally, rotated regularly, and accessed securely at runtime. While SAST tools can detect the hard-coded pattern, Plexicus uses AI to suggest the actual code fix—such as integrating with a secrets manager or environment variables—saving hours of manual refactoring and helping you enforce secure key handling across your entire application portfolio.
Vulnerability Diagram CWE-321
Hard-coded Cryptographic Key crypto.go var aesKey = []byte( "0123456789abcdef") cipher.Encrypt(aesKey, …) // same key on every install Attacker strings binary | grep hex → 0123456789abcdef decrypt all encrypted data, forge tokens, sign things A literal AES/HMAC key in code = one extracted key compromises every customer.
Auswirkungen in der Praxis

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

Wie Angreifer es ausnutzen

Angreiferpfad Schritt für Schritt

  1. 1

    The following code examples attempt to verify a password using a hard-coded cryptographic key.

  2. 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. 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. 4

    Multiple vendors used hard-coded keys for critical functionality in their OT products.

Verwundbares Codebeispiel

Vulnerable C

The following code examples attempt to verify a password using a hard-coded cryptographic key.

Verwundbar C
int VerifyAdmin(char *password) {
  		if (strcmp(password,"68af404b513073584c4b6f22b6c63e6b")) {
  				printf("Incorrect Password!\n");
  				return(0);
  		}
  		printf("Entering Diagnostic Mode...\n");
  		return(1);
  }
Sicheres Codebeispiel

Secure pseudo

Sicher 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.
Präventions-Checkliste

How to prevent CWE-321

  • Architecture and Design Prevention schemes mirror that of hard-coded password storage.
Erkennungssignale

How to detect CWE-321

Automated Static Analysis High

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.)

Plexicus Auto-Fix

Plexicus erkennt CWE-321 automatisch und öffnet in unter 60 Sekunden einen Fix-PR.

Codex Remedium scannt jeden Commit, identifiziert genau diese Schwachstelle und liefert einen reviewer-ready Pull Request mit dem Patch. Keine Tickets. Keine Hand-offs.

Häufig gestellte Fragen

Frequently asked questions

Was ist CWE-321?

This vulnerability occurs when an application embeds a fixed, unchangeable cryptographic key directly within its source code or configuration files.

Wie gravierend ist CWE-321?

MITRE stuft die Exploit-Wahrscheinlichkeit als hoch ein — diese Schwachstelle wird aktiv in freier Wildbahn ausgenutzt und sollte priorisiert behoben werden.

Welche Sprachen oder Plattformen sind von CWE-321 betroffen?

MITRE lists the following affected platforms: ICS/OT.

Wie kann ich CWE-321 verhindern?

Prevention schemes mirror that of hard-coded password storage.

Wie erkennt und behebt Plexicus CWE-321?

Die SAST-Engine von Plexicus erkennt die Datenfluss-Signatur von CWE-321 bei jedem Commit. Bei einem Treffer öffnet unser Codex-Remedium-Agent einen Fix-PR mit korrigiertem Code, Tests und einer einzeiligen Zusammenfassung für den Reviewer.

Wo erfahre ich mehr über CWE-321?

MITRE veröffentlicht die kanonische Definition unter https://cwe.mitre.org/data/definitions/321.html. Für ergänzende Hinweise kannst du auch die OWASP- und NIST-Dokumentation heranziehen.

Bereit, wenn du es bist

Schluss mit dem Bezahlen pro Entwickler.
Schließ den Kreislauf.

Plexicus ist die KI-native ASPM, die scannt, filtert, fixt, pentestet und erklärt — autonom. Unbegrenzte Entwickler, unbegrenzte Repos, Fair-Use-KI-Aktionen. Echter kostenloser Tarif, €269/mo jährlich, wenn du bereit bist.