Logo
-

Byte Open Security

(ByteOS Network)

Log In

Sign Up

ByteOS

Security
Vulnerability Details
Registries
Custom Views
Weaknesses
Attack Patterns
Filters & Tools
CWE-96:Improper Neutralization of Directives in Statically Saved Code ('Static Code Injection')
Weakness ID:96
Version:v4.17
Weakness Name:Improper Neutralization of Directives in Statically Saved Code ('Static Code Injection')
Vulnerability Mapping:Allowed
Abstraction:Base
Structure:Simple
Status:Draft
Likelihood of Exploit:
DetailsContent HistoryObserved CVE ExamplesReports
▼Description

The product 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.

▼Extended Description

▼Alternate Terms
▼Relationships
Relevant to the view"Research Concepts - (1000)"
NatureMappingTypeIDName
ChildOfAllowed-with-ReviewB94Improper Control of Generation of Code ('Code Injection')
ParentOfAllowedV97Improper Neutralization of Server-Side Includes (SSI) Within a Web Page
Nature: ChildOf
Mapping: Allowed-with-Review
Type: Base
ID: 94
Name: Improper Control of Generation of Code ('Code Injection')
Nature: ParentOf
Mapping: Allowed
Type: Variant
ID: 97
Name: Improper Neutralization of Server-Side Includes (SSI) Within a Web Page
▼Memberships
NatureMappingTypeIDName
MemberOfProhibitedV884CWE Cross-section
MemberOfProhibitedC990SFP Secondary Cluster: Tainted Input to Command
MemberOfProhibitedC1019Validate Inputs
MemberOfProhibitedC1347OWASP Top Ten 2021 Category A03:2021 - Injection
MemberOfProhibitedC1409Comprehensive Categorization: Injection
Nature: MemberOf
Mapping: Prohibited
Type:View
ID: 884
Name: CWE Cross-section
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 990
Name: SFP Secondary Cluster: Tainted Input to Command
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1019
Name: Validate Inputs
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1347
Name: OWASP Top Ten 2021 Category A03:2021 - Injection
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1409
Name: Comprehensive Categorization: Injection
▼Tags
NatureMappingTypeIDName
MemberOfProhibitedBSBOSS-250Weaknesses in Software Written in Perl
MemberOfProhibitedBSBOSS-279Input Validation Strategy
MemberOfProhibitedBSBOSS-284Output Encoding Strategy
MemberOfProhibitedBSBOSS-293Interpreted Weaknesses
MemberOfProhibitedBSBOSS-311Execute Unauthorized Code or Commands (impact)
MemberOfProhibitedBSBOSS-316Bypass Protection Mechanism (impact)
MemberOfProhibitedBSBOSS-319Read Files or Directories (impact)
MemberOfProhibitedBSBOSS-322Hide Activities (impact)
MemberOfProhibitedBSBOSS-328Read Application Data (impact)
MemberOfProhibitedBSBOSS-332Gain Privileges or Assume Identity (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-250
Name: Weaknesses in Software Written in Perl
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-279
Name: Input Validation Strategy
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-284
Name: Output Encoding Strategy
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-293
Name: Interpreted Weaknesses
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-311
Name: Execute Unauthorized Code or Commands (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-316
Name: Bypass Protection Mechanism (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-319
Name: Read Files or Directories (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-322
Name: Hide Activities (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-328
Name: Read Application Data (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-332
Name: Gain Privileges or Assume Identity (impact)
▼Relevant To View
Relevant to the view"Architectural Concepts - (1008)"
NatureMappingTypeIDName
MemberOfProhibitedC1019Validate Inputs
Nature: MemberOf
Mapping: Prohibited
Type: Category
ID: 1019
Name: Validate Inputs
Relevant to the view"OWASP Top Ten (2021) - (1344)"
NatureMappingTypeIDName
MemberOfProhibitedC1347OWASP Top Ten 2021 Category A03:2021 - Injection
Nature: MemberOf
Mapping: Prohibited
Type: Category
ID: 1347
Name: OWASP Top Ten 2021 Category A03:2021 - Injection
Relevant to the view"Software Fault Pattern (SFP) Clusters - (888)"
NatureMappingTypeIDName
MemberOfProhibitedC990SFP Secondary Cluster: Tainted Input to Command
Nature: MemberOf
Mapping: Prohibited
Type: Category
ID: 990
Name: SFP Secondary Cluster: Tainted Input to Command
▼Background Detail

▼Common Consequences
ScopeLikelihoodImpactNote
ConfidentialityN/ARead Files or DirectoriesRead Application Data

The injected code could access restricted data / files.

Access ControlN/ABypass Protection Mechanism

In some cases, injectable code controls authentication; this may lead to a remote vulnerability.

Access ControlN/AGain Privileges or Assume Identity

Injected code can access resources that the attacker is directly prevented from accessing.

IntegrityConfidentialityAvailabilityOtherN/AExecute 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-RepudiationN/AHide Activities

Often the actions performed by injected control code are unlogged.

Scope: Confidentiality
Likelihood: N/A
Impact: Read Files or Directories, Read Application Data
Note:

The injected code could access restricted data / files.

Scope: Access Control
Likelihood: N/A
Impact: Bypass Protection Mechanism
Note:

In some cases, injectable code controls authentication; this may lead to a remote vulnerability.

Scope: Access Control
Likelihood: N/A
Impact: Gain Privileges or Assume Identity
Note:

Injected code can access resources that the attacker is directly prevented from accessing.

Scope: Integrity, Confidentiality, Availability, Other
Likelihood: N/A
Impact: Execute Unauthorized Code or Commands
Note:

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.

Scope: Non-Repudiation
Likelihood: N/A
Impact: Hide Activities
Note:

Often the actions performed by injected control code are unlogged.

▼Potential Mitigations
Phase:Implementation
Mitigation ID: MIT-5
Strategy: Input Validation
Effectiveness:
Description:

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.

Note:


Phase:Implementation
Mitigation ID:
Strategy: Output Encoding
Effectiveness:
Description:

Perform proper output validation and escaping to neutralize all code syntax from data written to code files.

Note:

▼Modes Of Introduction
Phase: Implementation
Note:

REALIZATION: This weakness is caused during implementation of an architectural security tactic.

Phase: Implementation
Note:

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.

▼Applicable Platforms
Languages
Class: PHP(Undetermined Prevalence)
Class: Perl(Undetermined Prevalence)
Class: Interpreted(Undetermined Prevalence)
▼Demonstrative Examples
Example 1

This example attempts to write user messages to a message file and allow users to view them.

Language: ( code)
N/A

Language: PHP(Bad code)
$MessageFile = "messages.out"; if ($_GET["action"] == "NewMessage") { $name = $_GET["name"]; $message = $_GET["message"]; $handle = fopen($MessageFile, "a+"); fwrite($handle, "<b>$name</b> says '$message'<hr>\n"); fclose($handle); echo "Message Saved!<p>\n"; } else if ($_GET["action"] == "ViewMessages") { include($MessageFile); }

Language: ( code)
N/A

While the programmer intends for the MessageFile to only include data, an attacker can provide a message such as:

Language: (Attack code)
name=h4x0r message=%3C?php%20system(%22/bin/ls%20-l%22);?%3E

Language: ( code)
N/A

which will decode to the following:

Language: (Attack code)
<?php system("/bin/ls -l");?>

Language: ( code)
N/A

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.

Language: ( code)
N/A

Notice that XSS (CWE-79) is also possible in this situation.

▼Observed Examples
ReferenceDescription
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.
CVE-2007-6652
chain: execution after redirect allows non-administrator to perform static code injection.
Reference: CVE-2002-0495
Description:
Perl code directly injected into CGI library file from parameters to another CGI program.
Reference: CVE-2005-1876
Description:
Direct PHP code injection into supporting template file.
Reference: CVE-2005-1894
Description:
Direct code injection into PHP script that can be accessed by attacker.
Reference: CVE-2003-0395
Description:
PHP code from User-Agent HTTP header directly inserted into log file implemented as PHP script.
Reference: CVE-2007-6652
Description:
chain: execution after redirect allows non-administrator to perform static code injection.
▼Affected Resources
  • File or Directory
▼Functional Areas
    ▼Weakness Ordinalities
    OrdinalityDescription
    Primary
    N/A
    Ordinality: Primary
    Description:
    N/A
    ▼Detection Methods
    ▼Vulnerability Mapping Notes
    Usage:Allowed
    Reason:Acceptable-Use
    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.

    Suggestions:
    ▼Notes
    Relationship

    "HTML injection" (see CWE-79: XSS) could be thought of as an example of this, but the code is injected and executed on the client side, not the server side. Server-Side Includes (SSI) are an example of direct static code injection.

    N/A

    ▼Taxonomy Mappings
    Taxonomy NameEntry IDFitEntry Name
    PLOVERN/AN/ADirect Static Code Injection
    Software Fault PatternsSFP24N/ATainted Input to Command
    Taxonomy Name: PLOVER
    Entry ID: N/A
    Fit: N/A
    Entry Name: Direct Static Code Injection
    Taxonomy Name: Software Fault Patterns
    Entry ID: SFP24
    Fit: N/A
    Entry Name: Tainted Input to Command
    ▼Related Attack Patterns
    IDName
    CAPEC-35
    Leverage Executable Code in Non-Executable Files
    CAPEC-73
    User-Controlled Filename
    CAPEC-77
    Manipulating User-Controlled Variables
    CAPEC-81
    Web Server Logs Tampering
    CAPEC-85
    AJAX Footprinting
    ID: CAPEC-35
    Name: Leverage Executable Code in Non-Executable Files
    ID: CAPEC-73
    Name: User-Controlled Filename
    ID: CAPEC-77
    Name: Manipulating User-Controlled Variables
    ID: CAPEC-81
    Name: Web Server Logs Tampering
    ID: CAPEC-85
    Name: AJAX Footprinting
    ▼References
    Details not found