CWE-77: CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection')
Description
View on MITREExtended Description
Extended Description
Technical Details
- Structure
- Simple
- Vulnerability Mapping
- ALLOWED
Applicable To
🏆 CWE Top 25 Historical Ranking
Security Consequences
Scope
Impact
Mitigation Strategies
Phase
Description
If at all possible, use library calls rather than external processes to recreate the desired functionality.
Phase
Description
If possible, ensure that all external commands called from the program are statically created.
Phase
Description
Strategy: Input Validation Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does. When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, "boat" may be syntactically valid because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as "red" or "blue." Do not rely exclusively on looking for malicious or malformed inputs. This is likely to miss at least one undesirable input, especially if the code's environment changes. This can give attackers enough room to bypass the intended validation. However, denylists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright.
Phase
Description
Run time: Run time policy enforcement may be used in an allowlist fashion to prevent use of any non-sanctioned commands.
Phase
Description
Assign permissions that prevent the user from accessing/opening privileged files.
Detection Methods
No detection method information available for this CWE.
Code Examples & CVEs
No examples or observed CVEs available for this CWE.
Frequently Asked Questions
What is CWE-77: CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection')?+
CWE-77: CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection') is a Common Weakness Enumeration (CWE) entry maintained by MITRE. Description Extended Description
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 CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection')?+
If exploited, CWE-77 (CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection')) it can compromise Execute Unauthorized Code or Commands, leading to outcomes such as Scope: Integrity, Confidentiality, Availability If a malicious user injects a character (such as a semi-colon) that delimits the end of one command and the beginning of another and it may be possible to then insert an entirely new and unrelated command that was not intended to be executed. This gives an attacker a privilege or capability that they would not otherwise have..
How do you prevent or mitigate CWE-77: 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. Strategy: Input Validation Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does. When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, "boat" may be syntactically valid because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as "red" or "blue." Do not rely exclusively on looking for malicious or malformed inputs. This is likely to miss at least one undesirable input, especially if the code's environment changes. This can give attackers enough room to bypass the intended validation. However, denylists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright.
Which programming languages are affected by CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection')?+
CWE-77 commonly affects Languages. Note that weaknesses are often language-agnostic patterns, so secure coding practices apply broadly.
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
Search for vulnerabilities that exploit CWE-77
See how this weakness ranks against others
Understanding vulnerabilities vs weaknesses
How vulnerability severity is measured
Complete technical details and references