What is CWE-78?
The product builds an operating system command from externally influenced input without correctly neutralizing special elements that can alter the intended command before it is executed.
The product builds an operating system command from externally influenced input without correctly neutralizing special elements that can alter the intended command before it is executed.
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.
This weakness can affect applications that execute operating system commands on behalf of users, including web applications where the attacker has no direct operating system access. It commonly occurs in two forms: untrusted data is intended to be an argument to a fixed program but command separators or other metacharacters allow additional programs to run, or untrusted input selects and supplies an entire command, enabling arbitrary command or program execution. Privileged processes can magnify the impact, especially when they do not follow least privilege, because attacker-controlled commands may run with permissions unavailable to the attacker directly.
This is a base-level, simple weakness introduced during implementation. It involves mixing control syntax and externally influenced data in an operating system command, either through a fixed executable's arguments or through selection of the executable and command itself. Related terminology includes shell injection, shell metacharacters, and OS command injection; it is distinct from, but can overlap with, argument injection.
An attacker may execute unauthorized operating system commands, disable or crash the product, and read or modify files, directories, or application data without the intended permissions. Malicious actions may appear to originate from the application or its owner, affecting confidentiality, integrity, availability, and non-repudiation, and potentially allowing the attacker to hide activities.
| Impact | Scope | Explanation |
|---|---|---|
| Execute Unauthorized Code or Commands, DoS: Crash, Exit, or Restart, Read Files or Directories, Modify Files or Directories, Read Application Data, Modify Application Data, Hide Activities | Confidentiality, Integrity, Availability, Non-Repudiation | Attackers could execute unauthorized operating system commands, which could then be used to disable the product, or read and modify data for which the attacker does not have permissions to access directly. Since the targeted application is directly executing the commands instead of the attacker, any malicious activities may appear to come from the application or the application's owner. |
Architecture and design: Prefer library calls over external processes, keep command-generating data outside external control where possible, and map fixed input values such as numeric IDs to known filenames or URLs. Duplicate client-side security checks on the server, and use vetted libraries or frameworks that separate data from code. Where available, use structured parameterization with individual arguments instead of a single command-shell string, such as argument-array interfaces rather than system-style calls.
Implementation: Properly quote arguments and escape special characters; use an extremely strict allowlist when feasible, and quote each argument after filtering or escaping. Prefer passing arguments through an input file or standard input when the executed program supports it. Apply accept-known-good validation based on the expected type, length, syntax, allowed values, and business rules, while treating validation as defense in depth rather than a replacement for encoding, escaping, and quoting. Keep error messages minimally informative and put necessary detail in carefully protected logs.
Operation and hardening: Use sandboxing or jails, runtime command allowlists, and the lowest required privileges, recognizing that these measures generally limit impact rather than remove the weakness. Automatic taint propagation can prevent command execution with tainted variables, but validation must correctly remove taint. An application firewall may provide temporary or defense-in-depth protection, although it can miss input vectors, be bypassed, or reject legitimate requests. When applicable, avoid PHP register_globals and do not recreate it insecurely. Avoid weaknesses related to jail design, including CWE-243.
Detection can combine manual and automated approaches. Manual source review, focused spot checks, architecture or design review, and formal methods can provide high or highly cost-effective coverage when all command-execution paths can be assessed. Automated source, binary, or bytecode static analysis can identify data flows into command execution, but may produce false positives when validation is not recognized and false negatives for custom APIs or unavailable third-party code; complete accuracy and coverage are not feasible.
Dynamic testing can use fuzzing, robustness testing, fault injection, web application and web service scanners, and database scanners. These approaches provide moderate or partial coverage and may slow operation, so the product should not become unstable, crash, or produce incorrect results during testing.
| Method | Approach | Effectiveness |
|---|---|---|
| Automated Static Analysis | This weakness can often be detected using automated static analysis tools. Many modern tools use data flow analysis or constraint-based techniques to minimize the number of false positives. Automated static analysis might not be able to recognize when proper input validation is being performed, leading to false positives - i.e., warnings that do not have any security consequences or require any code changes. Automated static analysis might not be able to detect the usage of custom API functions or third-party libraries that indirectly invoke OS commands, leading to false negatives - especially if the API/library code is not available for analysis.This is not a perfect solution, since 100% accuracy and coverage are not feasible. | — |
| Automated Dynamic Analysis | This weakness can be detected using dynamic tools and techniques that interact with the product using large test suites with many diverse inputs, such as fuzz testing (fuzzing), robustness testing, and fault injection. The product's operation may slow down, but it should not become unstable, crash, or generate incorrect results. | Moderate |
| Manual Static Analysis | Since this weakness does not typically appear frequently within a single software package, manual white box techniques may be able to provide sufficient code coverage and reduction of false positives if all potentially-vulnerable operations can be assessed within limited time constraints. | High |
| Automated Static Analysis - Binary or Bytecode | According to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Bytecode Weakness Analysis - including disassembler + source code weakness analysis Binary Weakness Analysis - including disassembler + source code weakness analysis | High |
| Dynamic Analysis with Automated Results Interpretation | According to SOAR [REF-1479], the following detection techniques may be useful: ``` Cost effective for partial coverage: ``` Web Application Scanner Web Services Scanner Database Scanners | SOAR Partial |
| Dynamic Analysis with Manual Results Interpretation | According to SOAR [REF-1479], the following detection techniques may be useful: ``` Cost effective for partial coverage: ``` Fuzz Tester Framework-based Fuzzer | SOAR Partial |
| Manual Static Analysis - Source Code | According to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Manual Source Code Review (not inspections) ``` Cost effective for partial coverage: ``` Focused Manual Spotcheck - Focused manual analysis of source | High |
| Automated Static Analysis - Source Code | According to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Source code Weakness Analyzer Context-configured Source Code Weakness Analyzer | High |
| Architecture or Design Review | According to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Formal Methods / Correct-By-Construction ``` Cost effective for partial coverage: ``` Inspection (IEEE 1028 standard) (can apply to requirements, design, source code, etc.) | High |
The official record lists these as representative examples, not an exhaustive list: CVE-2024-53899 involved unquoted template strings and shell metacharacters in a directory name; CVE-2025-44844 involved a wireless access point file upload path using a filename from a Content-Disposition header; CVE-2024-6091 and CVE-2024-44335 illustrate chains involving incomplete path or character denylists; CVE-2024-41316 involved os.execute in a Lua network-device application; and CVE-2024-52803 involved insecure use of Popen during LLM training. Earlier examples include command injection in Wi-Fi routers, network configuration and web-server functionality, FTP and telnet link handling, ZIP filenames, environment variables, HTTPS URLs, and files or parameters containing shell metacharacters, including CVE-2020-10987, CVE-2020-9054, CVE-1999-0067, CVE-2002-0061, CVE-2003-0041, CVE-2008-2575, CVE-2002-1898, CVE-2008-4304, CVE-2008-4796, CVE-2007-3572, and CVE-2012-1988. CVE-2001-1246 additionally demonstrates that OS command injection can coexist with argument injection.
Below are representative vulnerabilities related to this CWE, prioritized by severity.
CWE™ Program, operated by The MITRE Corporation. Copyright © 2006–2026, The MITRE Corporation. The MITRE Corporation hereby grants you a non-exclusive, royalty-free license to use CWE for research, development, and commercial purposes. CWE Terms of Use.
CyStack VulnScan continuously discovers assets, validates vulnerabilities, and helps security teams prioritize remediation across the organization.
Explore CyStack VulnScanen