CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')

BaseStableExploit Likelihood: High🏆 #8 in Top 25 (2024)

The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component.

View on MITRE
415Related CVEs
16.44Severity Score
Back to CWE Lookup

Extended Description

This weakness can lead to a vulnerability in environments in which the attacker does not have direct access to the operating system, such as in web applications. Alternately, if the weakness occurs in a privileged program, it could allow the attacker to specify commands that normally would not be accessible, or to call alternate commands with privileges that the attacker does not have. The problem is exacerbated if the compromised process does not follow the principle of least privilege, because the attacker-controlled commands may run with special system privileges that increases the amount of damage. There are at least two subtypes of OS command injection: The application intends to execute a single, fixed program that is under its own control. It intends to use externally-supplied inputs as arguments to that program. For example, the program might use system("nslookup [HOSTNAME]") to run nslookup and allow the user to supply a HOSTNAME, which is used as an argument. Attackers cannot prevent nslookup from executing. However, if the program does not remove command separators from the HOSTNAME argument, attackers could place the separators into the arguments, which allows them to execute their own program after nslookup has finished executing. The application accepts an input that it uses to fully select which program to run, as well as which commands to use. The application simply redirects this entire command to the operating system. For example, the program might use "exec([COMMAND])" to execute the [COMMAND] that was supplied by the user. If the COMMAND is under attacker control, then the attacker can execute arbitrary commands or programs. If the command is being executed using functions like exec() and CreateProcess(), the attacker might not be able to combine multiple commands together in the same line. From a weakness standpoint, these variants represent distinct programmer errors. In the first variant, the programmer clearly intends that input from untrusted parties will be part of the arguments in the command to be executed. In the second variant, the programmer does not intend for the command to be accessible to any untrusted party, but the programmer probably has not accounted for alternate ways in which malicious attackers can provide input.

Technical Details

Structure
Simple
Vulnerability Mapping
ALLOWED

Applicable To

Languages
Not Language-Specific
Platforms

🏆 CWE Top 25 Historical Ranking

2023:#5
Score: 15.65
398 CVEs
2024:#8↓3
Score: 16.44
415 CVEs
Trend:Improving (moved up 3 ranks)

Source-backed guidance

Additional facts reviewed against primary or authoritative security sources.

Combine review and analysis around the CWE-78 trust boundary

MITRE identifies automated static analysis, automated dynamic analysis, manual static analysis as applicable detection approaches. Use them to find every process-launch and shell boundary, including helper scripts and wrappers, and trace whether an external value can alter the command, argument structure, or environment. Require a reproducible source-to-sink or policy-to-enforcement trace, record coverage gaps, and confirm suspected findings dynamically where safe; no single scanner can establish complete coverage for this weakness.

CWE-78: detection methods and operational guidanceMITRE CWE

Replace shell execution with purpose-built APIs

Avoid invoking operating-system commands when a language or platform library can perform the required operation. If command execution is unavoidable, keep the command fixed, separate data into arguments, and apply strict allowlist validation to those arguments. Run the process with the minimum privileges required and isolate single-purpose command execution where possible.

OS Command Injection Defense Cheat SheetOWASP Foundation

Apply lessons from CVE-2025-11953 in React Native Community CLI

NVD maps CVE-2025-11953 to CWE-78; an exposed Metro development server endpoint could accept unauthenticated POST requests and launch arbitrary executables, with arbitrary shell commands possible on Windows. Use the case to keep development services off untrusted networks, remove shell interpretation, authenticate privileged endpoints, and test platform-specific argument handling.

CVE-2025-11953 DetailNIST National Vulnerability Database

Prioritize CWE-78 using its 2025 CWE Top 25 evidence

CWE-78 ranked #9 in the 2025 CWE Top 25 with a score of 7.85. The ranking table recorded 20 mapped vulnerabilities in CISA KEV for this measurement window. Use the rank to prioritize systemic prevention, detection coverage, and recurring-root-cause metrics across the portfolio, while retaining asset exposure and business impact for individual finding severity decisions.

2025 CWE Top 25 Most Dangerous Software WeaknessesMITRE CWE

Exercise command and argument injection at each process boundary

Inventory parameters that can reach operating-system commands, including filenames, hostnames, diagnostics, converters, and administrative utilities. Test shell metacharacters, argument separators, option injection, whitespace variants, encodings, and platform-specific syntax with harmless markers or timing effects. Verify the fix uses a purpose-built API or fixed executable with separated, allowlisted arguments.

Testing for Command InjectionOWASP Foundation

Frequently Asked Questions

What is CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')?+

CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') is a Common Weakness Enumeration (CWE) entry maintained by MITRE. The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component. This weakness can lead to a vulnerability in environments in which the attacker does not have direct access to the operating system, such as in web applications. Alternately, if the weakness occurs in a privileged program, it could allow the attacker to specify commands that normally would not be accessible, or to call alternate commands with privileges that the attacker does not have. The problem is exacerbated if the compromised process does not follow the principle of least privilege, because the attacker-controlled commands may run with special system privileges that increases the amount of damage. There are at least two subtypes of OS command injection: The application intends to execute a single, fixed program that is under its own control. It intends to use externally-supplied inputs as arguments to that program. For example, the program might use system("nslookup [HOSTNAME]") to run nslookup and allow the user to supply a HOSTNAME, which is used as an argument. Attackers cannot prevent nslookup from executing. However, if the program does not remove command separators from the HOSTNAME argument, attackers could place the separators into the arguments, which allows them to execute their own program after nslookup has finished executing. The application accepts an input that it uses to fully select which program to run, as well as which commands to use. The application simply redirects this entire command to the operating system. For example, the program might use "exec([COMMAND])" to execute the [COMMAND] that was supplied by the user. If the COMMAND is under attacker control, then the attacker can execute arbitrary commands or programs. If the command is being executed using functions like exec() and CreateProcess(), the attacker might not be able to combine multiple commands together in the same line. From a weakness standpoint, these variants represent distinct programmer errors. In the first variant, the programmer clearly intends that input from untrusted parties will be part of the arguments in the command to be executed. In the second variant, the programmer does not intend for the command to be accessible to any untrusted party, but the programmer probably has not accounted for alternate ways in which malicious attackers can provide input.

Is CWE-78 in the CWE Top 25 Most Dangerous Software Weaknesses?+

Yes. CWE-78 ranked #8 in the CWE Top 25 for 2024, associated with 415 CVEs that year. The CWE Top 25 highlights the most common and impactful software weaknesses based on real-world vulnerability data.

What are the security consequences of Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')?+

If exploited, CWE-78 (Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')) it can compromise Confidentiality, Integrity, Availability and Non-Repudiation, leading to outcomes such as Execute Unauthorized Code or Commands, DoS: Crash, Exit, or Restart, Read Files or Directories, Modify Files or Directories, Read Application Data and Modify Application Data.

How do you prevent or mitigate Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')?+

Recommended mitigations for CWE-78 include: If at all possible, use library calls rather than external processes to recreate the desired functionality. For any data that will be used to generate a command to be executed, keep as much of that data out of external control as possible. For example, in web applications, this may require storing the data locally in the session's state instead of sending it out to the client in a hidden form field. If the program to be executed allows arguments to be specified within an input file or from standard input, then consider using that mode to pass arguments instead of the command line.

How is Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') detected?+

CWE-78 can be detected using Automated Static Analysis - Binary or Bytecode, Dynamic Analysis with Automated Results Interpretation, Dynamic Analysis with Manual Results Interpretation, Manual Static Analysis - Source Code, Automated Static Analysis - Source Code and Architecture or Design Review. Combining automated tooling with manual review typically yields the best coverage.

Which programming languages are affected by Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')?+

CWE-78 commonly affects Not Language-Specific. Note that weaknesses are often language-agnostic patterns, so secure coding practices apply broadly.

What are real-world examples of Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')?+

MITRE documents real CVEs mapped to CWE-78, including CVE-2024-53899, CVE-2025-44844, CVE-2024-6091, CVE-2024-41316 and CVE-2024-44335. You can look up the full details of each CVE, including CVSS scores and remediation guidance, on our CVE Lookup tool.

What is the difference between a CWE and a CVE?+

A CWE (Common Weakness Enumeration) like CWE-78 describes a category of software weakness — the underlying flaw type. A CVE (Common Vulnerabilities and Exposures) identifies a specific, real-world vulnerability in a particular product. In short, a CWE is the kind of mistake, and a CVE is an instance of that mistake being found in software.

Learn More

Advertisement
CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') | #8 in CWE Top 25 2024 | CWE Lookup | InventiveHQ