[Forgot Password]
Login  Register Subscribe












Paid content will be excluded from the download.

Download | Alert*
view XML

Improper Neutralization of Directives in Statically Saved Code ('Static Code Injection')

ID: 96Date: (C)2012-05-14   (M)2012-11-08
Type: weaknessStatus: DRAFT
Abstraction Type: Base


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 Platforms
Language: PHP
Language: Perl
Language Class: All Interpreted Languages

Time Of Introduction

  • Architecture and Design
  • Implementation

Related Attack Patterns

Common Consequences

ScopeTechnical ImpactNotes
Read files or directories
Read application data
The injected code could access restricted data / files.
Bypass protection mechanism
In some cases, injectable code controls authentication; this may lead to a remote vulnerability.
Gain privileges / assume identity
Injected code can access resources that the attacker is directly prevented from accessing.
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.
Hide activities
Often the actions performed by injected control code are unlogged.

Detection Methods

Potential Mitigations

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.
Output Encoding
Perform proper output validation and escaping to neutralize all code syntax from data written to code files.


Related CWETypeViewChain
CWE-96 ChildOf CWE-896 Category CWE-888  

Demonstrative Examples   (Details)

  1. This example attempts to write user messages to a message file and allow users to view them. (Demonstrative Example Id DX-32)

Observed Examples

  1. CVE-2002-0495 : Perl code directly injected into CGI library file from parameters to another CGI program.
  2. CVE-2005-1876 : Direct PHP code injection into supporting template file.
  3. CVE-2005-1894 : Direct code injection into PHP script that can be accessed by attacker.
  4. 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

Black Box Definitions

Taxynomy Mappings

PLOVER  Direct Static Code Injection


© SecPod Technologies