Improper Neutralization of Directives in Statically Saved Code ('Static Code Injection')ID: 96 | Date: (C)2012-05-14 (M)2022-10-10 |
Type: weakness | Status: DRAFT |
Abstraction Type: Base |
Description
The software receives input from an upstream component, but it
does not neutralize or incorrectly neutralizes code syntax before inserting the
input into an executable resource, such as a library, configuration file, or
template.
Applicable PlatformsLanguage: PHPLanguage: PerlLanguage Class: All Interpreted Languages
Time Of Introduction
- Architecture and Design
- Implementation
Related Attack Patterns
Common Consequences
Scope | Technical Impact | Notes |
---|
Confidentiality | Read files or
directoriesRead application
data | The injected code could access restricted data / files. |
Access_Control | Bypass protection
mechanism | In some cases, injectable code controls authentication; this may lead
to a remote vulnerability. |
Access_Control | Gain privileges / assume
identity | Injected code can access resources that the attacker is directly
prevented from accessing. |
IntegrityConfidentialityAvailabilityOther | Execute unauthorized code or
commands | 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. |
Non-Repudiation | Hide activities | Often the actions performed by injected control code are
unlogged. |
Detection MethodsNone
Potential Mitigations
Phase | Strategy | Description | Effectiveness | Notes |
---|
Implementation | Input Validation | Assume all input is malicious. Use an "accept known good" input
validation strategy, i.e., use a whitelist 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
(i.e., do not rely on a blacklist). A blacklist 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, blacklists can be useful for detecting potential
attacks or determining which inputs are so malformed that they should be
rejected outright. | | |
Implementation | Output Encoding | Perform proper output validation and escaping to neutralize all code
syntax from data written to code files. | | |
Relationships
Related CWE | Type | View | Chain |
---|
CWE-96 ChildOf CWE-896 | Category | CWE-888 | |
Demonstrative Examples (Details)
- This example attempts to write user messages to a message file and
allow users to view them. (Demonstrative Example Id DX-32)
Observed Examples
- CVE-2002-0495 : Perl code directly injected into CGI library file from parameters to another CGI program.
- CVE-2005-1876 : Direct PHP code injection into supporting template file.
- CVE-2005-1894 : Direct code injection into PHP script that can be accessed by attacker.
- CVE-2003-0395 : PHP code from User-Agent HTTP header directly inserted into log file implemented as PHP script.
For more examples, refer to CVE relations in the bottom box.
White Box Definitions None
Black Box Definitions None
Taxynomy Mappings
Taxynomy | Id | Name | Fit |
---|
PLOVER | | Direct Static Code Injection | |
References:None