结构: Simple
Abstraction: Base
状态: Draft
被利用可能性: unkown
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.
cwe_Nature: ChildOf cwe_CWE_ID: 94 cwe_View_ID: 1000 cwe_Ordinal: Primary
cwe_Nature: ChildOf cwe_CWE_ID: 94 cwe_View_ID: 699 cwe_Ordinal: Primary
Language: [{'cwe_Name': 'PHP', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'Perl', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Class': 'Interpreted', 'cwe_Prevalence': 'Undetermined'}]
范围 | 影响 | 注释 |
---|---|---|
Confidentiality | ['Read Files or Directories', 'Read 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 or Assume Identity | Injected code can access resources that the attacker is directly prevented from accessing. |
['Integrity', 'Confidentiality', 'Availability', 'Other'] | 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. |
策略: 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.
This example attempts to write user messages to a message file and allow users to view them.
bad PHP
While the programmer intends for the MessageFile to only include data, an attacker can provide a message such as:
attack
which will decode to the following:
attack
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.
标识 | 说明 | 链接 |
---|---|---|
CVE-2002-0495 | Perl code directly injected into CGI library file from parameters to another CGI program. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-0495 |
CVE-2005-1876 | Direct PHP code injection into supporting template file. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2005-1876 |
CVE-2005-1894 | Direct code injection into PHP script that can be accessed by attacker. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2005-1894 |
CVE-2003-0395 | PHP code from User-Agent HTTP header directly inserted into log file implemented as PHP script. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2003-0395 |
CVE-2007-6652 | chain: execution after redirect allows non-administrator to perform static code injection. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-6652 |
映射的分类名 | ImNode ID | Fit | Mapped Node Name |
---|---|---|---|
PLOVER | Direct Static Code Injection | ||
Software Fault Patterns | SFP24 | Tainted input to command |