CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection')

ClassDraftExploit Likelihood: High🏆 #20 in Top 25 (2024)

The product constructs all or part of a command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended command when it is sent to a downstream component.

View on MITRE
208Related CVEs
9.45Severity Score
Back to CWE Lookup

Extended Description

Many protocols and products have their own custom command language. While OS or shell command strings are frequently discovered and targeted, developers may not realize that these other command languages might also be vulnerable to attacks.

Technical Details

Structure
Simple

Applicable To

Languages
Not Language-Specific
Platforms

🏆 CWE Top 25 Historical Ranking

2023:#16
Score: 4.95
195 CVEs
2024:#20↓4
Score: 9.45
208 CVEs
Trend:Improving (moved up 4 ranks)

Source-backed guidance

Additional facts reviewed against primary or authoritative security sources.

Combine review and analysis around the CWE-77 trust boundary

MITRE identifies automated static analysis as applicable detection approaches. Use them to trace external data into every command-language grammar, including shells, database utilities, template commands, build tools, and arguments that can change interpreter behavior. Require a reproducible source-to-sink or policy-to-enforcement trace, record coverage gaps, and confirm suspected findings dynamically where safe; no single scanner can establish complete coverage for this weakness.

CWE-77: detection methods and operational guidanceMITRE CWE

Separate command instructions from all untrusted values

Avoid command interpreters when a purpose-built API exists. Otherwise keep the operation fixed, pass data through a parameterized interface, and allowlist any dynamic command or option choice that cannot be parameterized. Validate on the server and run with least privilege. General escaping is fragile because each downstream command language has its own grammar and argument semantics.

OWASP Top 10:2025 A05 InjectionOWASP Foundation

Apply lessons from CVE-2025-59689 in Libraesva Email Security Gateway

NVD maps CVE-2025-59689 to CWE-77; a crafted compressed email attachment could reach command construction and allow command injection. Use the case to treat archive and attachment processing as an interpreter boundary, isolate converters, reject unsafe metadata, and test nested content before it reaches privileged command-line tools.

CVE-2025-59689 DetailNIST National Vulnerability Database

Prioritize CWE-77 using its 2025 CWE Top 25 evidence

CWE-77 ranked #23 in the 2025 CWE Top 25 with a score of 3.15. The ranking table recorded 2 mapped vulnerabilities in CISA KEV for this measurement window. Use the rank to prioritize systemic prevention, detection coverage, and recurring-root-cause metrics across the portfolio, while retaining asset exposure and business impact for individual finding severity decisions.

2025 CWE Top 25 Most Dangerous Software WeaknessesMITRE CWE

Audit every interpreter boundary for argument injection

Inventory calls to shells, operating-system commands, and other command interpreters, then replace them with purpose-built library APIs wherever possible. For unavoidable calls, keep the command fixed, pass data as separate arguments, and strictly allowlist those arguments. Test shell metacharacters and argument-injection payloads even when the executable name itself cannot be changed.

OS Command Injection Defense Cheat SheetOWASP Foundation

Frequently Asked Questions

What is CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection')?+

CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection') is a Common Weakness Enumeration (CWE) entry maintained by MITRE. The product constructs all or part of a command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended command when it is sent to a downstream component. Many protocols and products have their own custom command language. While OS or shell command strings are frequently discovered and targeted, developers may not realize that these other command languages might also be vulnerable to attacks.

Is CWE-77 in the CWE Top 25 Most Dangerous Software Weaknesses?+

Yes. CWE-77 ranked #20 in the CWE Top 25 for 2024, associated with 208 CVEs that year. The CWE Top 25 highlights the most common and impactful software weaknesses based on real-world vulnerability data.

What are the security consequences of Improper Neutralization of Special Elements used in a Command ('Command Injection')?+

If exploited, CWE-77 (Improper Neutralization of Special Elements used in a Command ('Command Injection')) it can compromise Integrity, Confidentiality and Availability, leading to outcomes such as Execute Unauthorized Code or Commands.

How do you prevent or mitigate Improper Neutralization of Special Elements used in a Command ('Command Injection')?+

Recommended mitigations for CWE-77 include: If at all possible, use library calls rather than external processes to recreate the desired functionality. If possible, ensure that all external commands called from the program are statically created. Run time: Run time policy enforcement may be used in an allowlist fashion to prevent use of any non-sanctioned commands.

Which programming languages are affected by Improper Neutralization of Special Elements used in a Command ('Command Injection')?+

CWE-77 commonly affects Not Language-Specific. Note that weaknesses are often language-agnostic patterns, so secure coding practices apply broadly.

What are real-world examples of Improper Neutralization of Special Elements used in a Command ('Command Injection')?+

MITRE documents real CVEs mapped to CWE-77, including CVE-2022-1509, CVE-2024-5184, CVE-2020-11698, CVE-2019-12921 and CVE-2022-36069. You can look up the full details of each CVE, including CVSS scores and remediation guidance, on our CVE Lookup tool.

What is the difference between a CWE and a CVE?+

A CWE (Common Weakness Enumeration) like CWE-77 describes a category of software weakness — the underlying flaw type. A CVE (Common Vulnerabilities and Exposures) identifies a specific, real-world vulnerability in a particular product. In short, a CWE is the kind of mistake, and a CVE is an instance of that mistake being found in software.

Learn More

Advertisement