| Impact | Details |
|---|---|
|
Read Files or Directories; Read Application Data |
Scope: Confidentiality
The injected code could access restricted data / files.
|
|
Bypass Protection Mechanism |
Scope: Access Control
In some cases, injectable code controls authentication; this may lead to a remote vulnerability.
|
|
Gain Privileges or Assume Identity |
Scope: Access Control
Injected code can access resources that the attacker is directly prevented from accessing.
|
|
Execute Unauthorized Code or Commands |
Scope: Integrity, Confidentiality, Availability, Other
Code injection attacks can lead to loss of data integrity in nearly all cases as the control-plane data injected is always incidental to data recall or writing. Additionally, code injection can often result in the execution of arbitrary code.
|
|
Hide Activities |
Scope: Non-Repudiation
Often the actions performed by injected control code are unlogged.
|
| Phase(s) | Mitigation |
|---|---|
|
Implementation |
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. |
|
Implementation |
Strategy: Output Encoding Perform proper output validation and escaping to neutralize all code syntax from data written to code files.
|
| Nature | Type | ID | Name |
|---|---|---|---|
| ChildOf | Base Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. | 94 | Improper Control of Generation of Code ('Code Injection') |
| ParentOf | Variant Variant - a weakness that is linked to a certain type of product, typically involving a specific language or technology. More specific than a Base weakness. Variant level weaknesses typically describe issues in terms of 3 to 5 of the following dimensions: behavior, property, technology, language, and resource. | 97 | Improper Neutralization of Server-Side Includes (SSI) Within a Web Page |
| Nature | Type | ID | Name |
|---|---|---|---|
| MemberOf | Category Category - a CWE entry that contains a set of other entries that share a common characteristic. | 1019 | Validate Inputs |
| Phase | Note |
|---|---|
| Implementation | REALIZATION: This weakness is caused during implementation of an architectural security tactic. |
| Implementation | This issue is frequently found in PHP applications that allow users to set configuration variables that are stored within executable PHP files. Technically, this could also be performed in some compiled code (e.g., by byte-patching an executable), although it is highly unlikely. |
PHP (Undetermined Prevalence)
Perl (Undetermined Prevalence)
Class: Interpreted (Undetermined Prevalence)
Example 1
This example attempts to write user messages to a message file and allow users to view them.
While the programmer intends for the MessageFile to only include data, an attacker can provide a message such as:
which will decode to the following:
The programmer thought they were just including the contents of a regular data file, but PHP parsed it and executed the code. Now, this code is executed any time people view messages.
Notice that XSS (CWE-79) is also possible in this situation.
Note: this is a curated list of examples for users to understand the variety of ways in which this weakness can be introduced. It is not a complete list of all CVEs that are related to this CWE entry.
| Reference | Description |
|---|---|
|
Perl code directly injected into CGI library file from parameters to another CGI program.
|
|
|
Direct PHP code injection into supporting template file.
|
|
|
Direct code injection into PHP script that can be accessed by attacker.
|
|
|
PHP code from User-Agent HTTP header directly inserted into log file implemented as PHP script.
|
|
|
chain: execution after redirect allows non-administrator to perform static code injection.
|
| Ordinality | Description |
|---|---|
|
Primary
|
(where the weakness exists independent of other weaknesses)
|
| Nature | Type | ID | Name |
|---|---|---|---|
| MemberOf | ViewView - a subset of CWE entries that provides a way of examining CWE content. The two main view structures are Slices (flat lists) and Graphs (containing relationships between entries). | 884 | CWE Cross-section |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 990 | SFP Secondary Cluster: Tainted Input to Command |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1347 | OWASP Top Ten 2021 Category A03:2021 - Injection |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1409 | Comprehensive Categorization: Injection |
Rationale
This CWE entry is at the Base level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.Comments
Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.Relationship
| Mapped Taxonomy Name | Node ID | Fit | Mapped Node Name |
|---|---|---|---|
| PLOVER | Direct Static Code Injection | ||
| Software Fault Patterns | SFP24 | Tainted Input to Command |
| Submissions | |||
|---|---|---|---|
| Submission Date | Submitter | Organization | |
|
2006年07月19日
(CWE Draft 3, 2006年07月19日) |
PLOVER | ||
| Modifications | |||
| Modification Date | Modifier | Organization | |
| 2023年06月29日 | CWE Content Team | MITRE | |
| updated Mapping_Notes | |||
| 2023年04月27日 | CWE Content Team | MITRE | |
| updated Modes_of_Introduction, Relationships, Time_of_Introduction | |||
| 2023年01月31日 | CWE Content Team | MITRE | |
| updated Description | |||
| 2022年10月13日 | CWE Content Team | MITRE | |
| updated Relationships, Taxonomy_Mappings | |||
| 2021年10月28日 | CWE Content Team | MITRE | |
| updated Relationships | |||
| 2021年03月15日 | CWE Content Team | MITRE | |
| updated Demonstrative_Examples | |||
| 2020年06月25日 | CWE Content Team | MITRE | |
| updated Potential_Mitigations | |||
| 2020年02月24日 | CWE Content Team | MITRE | |
| updated Potential_Mitigations, Relationships, Taxonomy_Mappings | |||
| 2017年11月08日 | CWE Content Team | MITRE | |
| updated Affected_Resources, Applicable_Platforms, Causal_Nature, Demonstrative_Examples, Enabling_Factors_for_Exploitation, Modes_of_Introduction, Relationships | |||
| 2017年05月03日 | CWE Content Team | MITRE | |
| updated Related_Attack_Patterns | |||
| 2014年07月30日 | CWE Content Team | MITRE | |
| updated Relationships, Taxonomy_Mappings | |||
| 2014年06月23日 | CWE Content Team | MITRE | |
| updated Enabling_Factors_for_Exploitation, Other_Notes, Relationship_Notes | |||
| 2013年02月21日 | CWE Content Team | MITRE | |
| updated Observed_Examples | |||
| 2012年10月30日 | CWE Content Team | MITRE | |
| updated Potential_Mitigations | |||
| 2012年05月11日 | CWE Content Team | MITRE | |
| updated Common_Consequences, Demonstrative_Examples, Relationships | |||
| 2011年06月01日 | CWE Content Team | MITRE | |
| updated Common_Consequences | |||
| 2010年06月21日 | CWE Content Team | MITRE | |
| updated Potential_Mitigations | |||
| 2010年04月05日 | CWE Content Team | MITRE | |
| updated Description, Name | |||
| 2009年05月27日 | CWE Content Team | MITRE | |
| updated Description, Name | |||
| 2008年09月08日 | CWE Content Team | MITRE | |
| updated Applicable_Platforms, Relationships, Other_Notes, Taxonomy_Mappings, Weakness_Ordinalities | |||
| 2008年07月01日 | Eric Dalci | Cigital | |
| updated Potential_Mitigations, Time_of_Introduction | |||
| Previous Entry Names | |||
| Change Date | Previous Entry Name | ||
| 2008年04月11日 | Direct Static Code Injection | ||
| 2009年05月27日 | Insufficient Control of Directives in Statically Saved Code (Static Code Injection) | ||
| 2010年04月05日 | Improper Sanitization of Directives in Statically Saved Code ('Static Code Injection') | ||
Use of the Common Weakness Enumeration (CWE™) and the associated references from this website are subject to the Terms of Use. CWE is sponsored by the U.S. Department of Homeland Security (DHS) Cybersecurity and Infrastructure Security Agency (CISA) and managed by the Homeland Security Systems Engineering and Development Institute (HSSEDI) which is operated by The MITRE Corporation (MITRE). Copyright © 2006–2025, The MITRE Corporation. CWE, CWSS, CWRAF, and the CWE logo are trademarks of The MITRE Corporation.