Ejecuta análisis estático (SAST) sobre el código buscando el patrón inseguro en el flujo de datos.
Improper Neutralization of Directives in Statically Saved Code ('Static Code Injection')
Static Code Injection occurs when an application incorporates unvalidated or improperly sanitized user input directly into a static, executable resource like a configuration file, template, or…
What is CWE-96?
Real-world CVEs caused by CWE-96
-
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.
Ruta del atacante paso a paso
- 1
This example attempts to write user messages to a message file and allow users to view them.
- 2
While the programmer intends for the MessageFile to only include data, an attacker can provide a message such as:
- 3
which will decode to the following:
- 4
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.
- 5
Notice that XSS (CWE-79) is also possible in this situation.
Vulnerable PHP
This example attempts to write user messages to a message file and allow users to view them.
$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);
} While the programmer intends for the MessageFile to only include data, an attacker can provide a message such as:
name=h4x0r
message=%3C?php%20system(%22/bin/ls%20-l%22);?%3E Secure pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
const safe = validateAndEscape(input);
return executeWithGuards(safe);
} How to prevent CWE-96
- Implementation 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 Perform proper output validation and escaping to neutralize all code syntax from data written to code files.
How to detect CWE-96
Ejecuta pruebas dinámicas de seguridad de aplicaciones (DAST) contra el endpoint en vivo.
Vigila los logs en tiempo de ejecución para detectar trazas de excepción inusuales, entradas malformadas o intentos de bypass de autorización.
Revisión de código: marca cualquier código nuevo que maneje entrada desde esta superficie sin usar los helpers validados del framework.
Plexicus detecta automáticamente CWE-96 y abre un PR de corrección en menos de 60 segundos.
Codex Remedium escanea cada commit, identifica esta debilidad concreta y entrega un pull request listo para revisión con el parche. Sin tickets. Sin traspasos.
Frequently asked questions
¿Qué es CWE-96?
Static Code Injection occurs when an application incorporates unvalidated or improperly sanitized user input directly into a static, executable resource like a configuration file, template, or library. Because this input is saved and later executed, it allows an attacker to inject malicious code that becomes a permanent part of the application's logic.
¿Qué gravedad tiene CWE-96?
MITRE no ha publicado una calificación de probabilidad de explotación para esta debilidad. Trátala como de impacto medio hasta que tu modelo de amenazas demuestre lo contrario.
¿Qué lenguajes o plataformas se ven afectados por CWE-96?
MITRE lists the following affected platforms: PHP, Perl, Interpreted.
¿Cómo puedo prevenir CWE-96?
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…
¿Cómo detecta y corrige Plexicus CWE-96?
El motor SAST de Plexicus detecta la firma de flujo de datos para CWE-96 en cada commit. Cuando hay coincidencia, nuestro agente Codex Remedium abre un PR de corrección con el código corregido, las pruebas y un resumen de una línea para el revisor.
¿Dónde puedo aprender más sobre CWE-96?
MITRE publica la definición canónica en https://cwe.mitre.org/data/definitions/96.html. También puedes consultar la documentación de OWASP y NIST para guías relacionadas.
Weaknesses related to CWE-96
Improper Control of Generation of Code ('Code Injection')
This vulnerability occurs when an application builds executable code using unvalidated external input, such as user data. Because the…
Improper Neutralization of Special Elements Used in a Template Engine
This vulnerability occurs when an application uses a template engine to process user-controlled input but fails to properly sanitize…
Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection')
This vulnerability occurs when an application takes user input and passes it directly into a dynamic code execution function, like eval(),…
Improper Neutralization of Server-Side Includes (SSI) Within a Web Page
This vulnerability occurs when a web application dynamically generates pages but fails to properly sanitize user-supplied input that could…
Deja de pagar por desarrollador.
Empieza a cerrar el bucle.
Plexicus es el ASPM nativo de IA que escanea, filtra, corrige, pentestea y explica — de forma autónoma. Desarrolladores ilimitados, repos ilimitados, acciones de IA de uso justo. Nivel gratuito real, €269/mo anual cuando estés listo.