Weakness · Critical
CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
What it is
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.
- Severity (our rating)
- Critical
- Likelihood of exploit
- High
- Introduced during
- Implementation
- Exploited in the wild
- 110 known exploited CVEs
In more detail
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.
What an attacker can do
- Execute Unauthorized Code or Commands (Confidentiality, Integrity, Availability, Non-Repudiation)
- DoS: Crash, Exit, or Restart (Confidentiality, Integrity, Availability, Non-Repudiation)
- Read Files or Directories (Confidentiality, Integrity, Availability, Non-Repudiation)
- Modify Files or Directories (Confidentiality, Integrity, Availability, Non-Repudiation)
- Read Application Data (Confidentiality, Integrity, Availability, Non-Repudiation)
- Modify Application Data (Confidentiality, Integrity, Availability, Non-Repudiation)
- Hide Activities (Confidentiality, Integrity, Availability, Non-Repudiation)
How to prevent it
Architecture and Design
- If at all possible, use library calls rather than external processes to recreate the desired functionality.
- Run the code in a "jail" or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict which files can be accessed in a particular directory or which commands can be executed by the software. OS-level examples include the Unix chroot jail, AppArmor, and SELinux. In general, managed code may provide some protection. For example, java.io.FilePermission in the Java SecurityManager allows the software to specify restrictions on file operations. This may not be a feasible solution, and it only limits the impact to the operating system; the rest of the application may still be subject to compromise. Be careful to avoid CWE-243 and other weaknesses related to jails.
- 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.
- For any security checks that are performed on the client side, ensure that these checks are duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side checks by modifying values after the checks have been performed, or by changing the client to remove the client-side checks entirely. Then, these modified values would be submitted to the server.
- Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid. For example, consider using the ESAPI Encoding control or a similar tool, library, or framework. These will help the programmer encode outputs in a manner less prone to error.
- If available, use structured mechanisms that automatically enforce the separation between data and code. These mechanisms may be able to provide the relevant quoting, encoding, and validation automatically, instead of relying on the developer to provide this capability at every point where output is generated. Some languages offer multiple functions that can be used to invoke commands. Where possible, identify any function that invokes a command shell using a single string, and replace it with a function that requires individual arguments. These functions typically perform appropriate quoting and filtering of arguments. For example, in C, the system() function accepts a string that contains the entire command to be executed, whereas execl(), execve(), and others require an array of strings, one for each argument. In Windows, CreateProcess() only accepts one command at a time. In Perl, if system() is provided with an array of arguments, then it will quote each of the arguments.
- When the set of acceptable objects, such as filenames or URLs, is limited or known, create a mapping from a set of fixed input values (such as numeric IDs) to the actual filenames or URLs, and reject all other inputs.
- Run your code using the lowest privileges that are required to accomplish the necessary tasks. If possible, create isolated accounts with limited privileges that are only used for a single task. That way, a successful attack will not immediately give the attacker access to the rest of the software or its environment. For example, database applications rarely need to run as the database administrator, especially in day-to-day operations.
Implementation
- While it is risky to use dynamically-generated query strings, code, or commands that mix control and data together, sometimes it may be unavoidable. Properly quote arguments and escape any special characters within those arguments. The most conservative approach is to escape or filter all characters that do not pass an extremely strict allowlist (such as everything that is not alphanumeric or white space). If some special characters are still needed, such as white space, wrap each argument in quotes after the escaping/filtering step. Be careful of argument injection (CWE-88).
- 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.
- 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. When constructing OS command strings, use stringent allowlists that limit the character set based on the expected value of the parameter in the request. This will indirectly limit the scope of an attack, but this technique is less important than proper output encoding and escaping. Note that proper output encoding, escaping, and quoting is the most effective solution for preventing OS command injection, although input validation may provide some defense-in-depth. This is because it effectively limits what will appear in output. Input validation will not always prevent OS command injection, especially if you are required to support free-form text fields that could contain arbitrary characters. For example, when invoking a mail program, you might need to allow the subject field to contain otherwise-dangerous inputs like ";" and ">" characters, which would need to be escaped or otherwise handled. In this case, stripping the character might reduce the risk of OS command injection, but it would produce incorrect behavior because the subject field would not be recorded as the user intended. This might seem to be a minor inconvenience, but it could be more important when the program relies on well-structured subject lines in order to pass messages to other components. Even if you make a mistake in your validation (such as forgetting one out of 100 input fields), appropriate encoding is still likely to protect you from injection-based attacks. As long as it is not done in isolation, input validation is still a useful technique, since it may significantly reduce your attack surface, allow you to detect some attacks, and provide other security benefits that proper encoding does not address.
- Ensure that error messages only contain minimal details that are useful to the intended audience and no one else. The messages need to strike the balance between being too cryptic (which can confuse users) or being too detailed (which may reveal more than intended). The messages should not reveal the methods that were used to determine the error. Attackers can use detailed information to refine or optimize their original attack, thereby increasing their chances of success. If errors must be captured in some detail, record them in log messages, but consider what could occur if the log messages can be viewed by attackers. Highly sensitive information such as passwords should never be saved to log files. Avoid inconsistent messaging that might accidentally tip off an attacker about internal state, such as whether a user account exists or not. In the context of OS Command Injection, error information passed back to the user might reveal whether an OS command is being executed and possibly which command is being used.
Operation
- Run the code in an environment that performs automatic taint propagation and prevents any command execution that uses tainted variables, such as Perl's "-T" switch. This will force the program to perform validation steps that remove the taint, although you must be careful to correctly validate your inputs so that you do not accidentally mark dangerous inputs as untainted (see CWE-183 and CWE-184).
- Run the code in an environment that performs automatic taint propagation and prevents any command execution that uses tainted variables, such as Perl's "-T" switch. This will force the program to perform validation steps that remove the taint, although you must be careful to correctly validate your inputs so that you do not accidentally mark dangerous inputs as untainted (see CWE-183 and CWE-184).
- Use runtime policy enforcement to create an allowlist of allowable commands, then prevent use of any command that does not appear in the allowlist. Technologies such as AppArmor are available to do this.
- Use an application firewall that can detect attacks against this weakness. It can be beneficial in cases in which the code cannot be fixed (because it is controlled by a third party), as an emergency prevention measure while more comprehensive software assurance measures are applied, or to provide defense in depth.
- When using PHP, configure the application so that it does not use register_globals. During implementation, develop the application so that it does not rely on this feature, but be wary of implementing a register_globals emulation that is subject to weaknesses such as CWE-95, CWE-621, and similar issues.
While the code is being fixed, a WAF in blocking mode stops OS command injection payloads, including Shellshock at the edge.
How to find it
- 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.
- 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.
- 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.
- Automated Static Analysis - Binary or Bytecode. According to SOAR, 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
- Dynamic Analysis with Automated Results Interpretation. According to SOAR, the following detection techniques may be useful: Cost effective for partial coverage: Web Application Scanner Web Services Scanner Database Scanners
- Dynamic Analysis with Manual Results Interpretation. According to SOAR, the following detection techniques may be useful: Cost effective for partial coverage: Fuzz Tester Framework-based Fuzzer
- Manual Static Analysis - Source Code. According to SOAR, 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
- Automated Static Analysis - Source Code. According to SOAR, the following detection techniques may be useful: Highly cost effective: Source code Weakness Analyzer Context-configured Source Code Weakness Analyzer
- Architecture or Design Review. According to SOAR, 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.)
Exploited in the wild: 110 CVEs
Vulnerabilities caused by CWE-78 that attackers have used, from CISA's Known Exploited Vulnerabilities catalog, newest first.
- CVE-2026-83549SonicWall SMA1000 Appliances OS Command Injection Vulnerability · added September 2, 2026
- CVE-2026-49869Kestra OSS OS Command Injection Vulnerability · added September 2, 2026
- CVE-2026-73570Zimbra Collaboration Suite (ZCS) OS Command Injection Vulnerability · added August 21, 2026
- CVE-2026-16812Arista VeloCloud Orchestrator On-Prem OS Command Injection Vulnerability · added July 27, 2026
- CVE-2026-39808Fortinet FortiSandbox OS Command Injection Vulnerability · added July 16, 2026
- CVE-2026-25089Fortinet FortiSandbox OS Command Injection Vulnerability · added July 16, 2026
- CVE-2025-67038Lantronix EDS5000 Code Injection Vulnerability · added June 23, 2026
- CVE-2026-10520Ivanti Sentry OS Command Injection Vulnerability · added June 11, 2026
- CVE-2026-42271BerriAI LiteLLM Command Injection Vulnerability · added June 8, 2026
- CVE-2026-25108Soliton Systems K.K FileZen OS Command Injection Vulnerability · added February 24, 2026
- CVE-2026-1731 ransomwareBeyondTrust Remote Support (RS) and Privileged Remote Access (PRA) OS Command Injection Vulnerability · added February 13, 2026
- CVE-2025-11953React Native Community CLI OS Command Injection Vulnerability · added February 5, 2026
- CVE-2025-64328Sangoma FreePBX OS Command Injection Vulnerability · added February 3, 2026
- CVE-2025-66644Array Networks ArrayOS AG OS Command Injection Vulnerability · added December 8, 2025
- CVE-2025-58034Fortinet FortiWeb OS Command Injection Vulnerability · added November 18, 2025
- CVE-2025-48703CWP Control Web Panel OS Command Injection Vulnerability · added November 4, 2025
- CVE-2014-6278GNU Bash OS Command Injection Vulnerability · added October 2, 2025
- CVE-2025-9377TP-Link Archer C7(EU) and TL-WR841N/ND(MS) OS Command Injection Vulnerability · added September 3, 2025
- CVE-2025-54948Trend Micro Apex One OS Command Injection Vulnerability · added August 18, 2025
- CVE-2023-39780ASUS RT-AX55 Routers OS Command Injection Vulnerability · added June 2, 2025
- CVE-2024-12987DrayTek Vigor Routers OS Command Injection Vulnerability · added May 15, 2025
- CVE-2024-11120GeoVision Devices OS Command Injection Vulnerability · added May 7, 2025
- CVE-2024-6047GeoVision Devices OS Command Injection Vulnerability · added May 7, 2025
- CVE-2023-44221SonicWall SMA100 Appliances OS Command Injection Vulnerability · added May 1, 2025
- CVE-2021-20035SonicWall SMA100 Appliances OS Command Injection Vulnerability · added April 16, 2025
- CVE-2025-1316Edimax IC-7100 IP Camera OS Command Injection Vulnerability · added March 19, 2025
- CVE-2024-40891Zyxel DSL CPE OS Command Injection Vulnerability · added February 11, 2025
- CVE-2024-40890Zyxel DSL CPE OS Command Injection Vulnerability · added February 11, 2025
- CVE-2018-9276Paessler PRTG Network Monitor OS Command Injection Vulnerability · added February 4, 2025
- CVE-2024-50603Aviatrix Controllers OS Command Injection Vulnerability · added January 16, 2025
- CVE-2024-12686BeyondTrust Privileged Remote Access (PRA) and Remote Support (RS) OS Command Injection Vulnerability · added January 13, 2025
- CVE-2021-40407Reolink RLC-410W IP Camera OS Command Injection Vulnerability · added December 18, 2024
- CVE-2019-11001Reolink Multiple IP Cameras OS Command Injection Vulnerability · added December 18, 2024
- CVE-2018-14933NUUO NVRmini Devices OS Command Injection Vulnerability · added December 18, 2024
- CVE-2024-1212Progress Kemp LoadMaster OS Command Injection Vulnerability · added November 18, 2024
- CVE-2024-9463Palo Alto Networks Expedition OS Command Injection Vulnerability · added November 14, 2024
- CVE-2024-8957PTZOptics PT30X-SDI/NDI Cameras OS Command Injection Vulnerability · added November 4, 2024
- CVE-2023-25280D-Link DIR-820 Router OS Command Injection Vulnerability · added September 30, 2024
- CVE-2020-15415DrayTek Multiple Vigor Routers OS Command Injection Vulnerability · added September 30, 2024
- CVE-2024-8190Ivanti Cloud Services Appliance OS Command Injection Vulnerability · added September 13, 2024
- CVE-2024-20399Cisco NX-OS Command Injection Vulnerability · added July 2, 2024
- CVE-2024-4577 ransomwarePHP-CGI OS Command Injection Vulnerability · added June 12, 2024
- CVE-2017-3506Oracle WebLogic Server OS Command Injection Vulnerability · added June 3, 2024
- CVE-2019-7256Nice Linear eMerge E3-Series OS Command Injection Vulnerability · added March 25, 2024
- CVE-2021-36380Sunhillo SureLine OS Command Injection Vulnerablity · added March 5, 2024
- CVE-2023-49897FXC AE1021, AE1021PE OS Command Injection Vulnerability · added December 21, 2023
- CVE-2023-47565QNAP VioStor NVR OS Command Injection Vulnerability · added December 21, 2023
- CVE-2023-20273Cisco IOS XE Web UI Command Injection Vulnerability · added October 23, 2023
- CVE-2017-6884 ransomwareZyxel EMG2926 Routers Command Injection Vulnerability · added September 18, 2023
- CVE-2017-18368Zyxel P660HN-T1A Routers Command Injection Vulnerability · added August 7, 2023
- CVE-2022-29303SolarView Compact Command Injection Vulnerability · added July 13, 2023
- CVE-2019-20500D-Link DWL-2600AP Access Point Command Injection Vulnerability · added June 29, 2023
- CVE-2019-17621D-Link DIR-859 Router Command Execution Vulnerability · added June 29, 2023
- CVE-2023-27992Zyxel Multiple NAS Devices Command Injection Vulnerability · added June 23, 2023
- CVE-2020-12641Roundcube Webmail Remote Code Execution Vulnerability · added June 22, 2023
- CVE-2023-28771Zyxel Multiple Firewalls OS Command Injection Vulnerability · added May 31, 2023
- CVE-2022-33891Apache Spark Command Injection Vulnerability · added March 7, 2023
- CVE-2022-28810Zoho ManageEngine ADSelfService Plus Remote Code Execution Vulnerability · added March 7, 2023
- CVE-2022-44877CWP Control Web Panel OS Command Injection Vulnerability · added January 17, 2023
- CVE-2022-36804Atlassian Bitbucket Server and Data Center Command Injection Vulnerability · added September 30, 2022
- CVE-2022-26258D-Link DIR-820L Remote Code Execution Vulnerability · added September 8, 2022
- CVE-2018-6530 ransomwareD-Link Multiple Routers OS Command Injection Vulnerability · added September 8, 2022
- CVE-2018-19949 ransomwareQNAP NAS File Station Command Injection Vulnerability · added May 24, 2022
- CVE-2022-30525Zyxel Multiple Firewalls OS Command Injection Vulnerability · added May 16, 2022
- CVE-2019-16057 ransomwareD-Link DNS-320 Remote Code Execution Vulnerability · added April 15, 2022
- CVE-2020-2509QNAP Network-Attached Storage (NAS) Command Injection Vulnerability · added April 11, 2022
- CVE-2021-45382D-Link Multiple Routers Remote Code Execution Vulnerability · added April 4, 2022
- CVE-2018-10562 ransomwareDasan GPON Routers Command Injection Vulnerability · added March 31, 2022
- CVE-2020-25223Sophos SG UTM Remote Code Execution Vulnerability · added March 25, 2022
- CVE-2020-9377D-Link DIR-610 Devices Remote Command Execution · added March 25, 2022
- CVE-2020-9054Zyxel Multiple NAS Devices OS Command Injection Vulnerability · added March 25, 2022
- CVE-2020-7247OpenSMTPD Remote Code Execution Vulnerability · added March 25, 2022
- CVE-2020-1956Apache Kylin OS Command Injection Vulnerability · added March 25, 2022
- CVE-2019-16920D-Link Multiple Routers Command Injection Vulnerability · added March 25, 2022
- CVE-2019-15107 ransomwareWebmin Command Injection Vulnerability · added March 25, 2022
- CVE-2019-12991Citrix SD-WAN and NetScaler Command Injection Vulnerability · added March 25, 2022
- CVE-2018-14839LG N1A1 NAS Remote Command Execution Vulnerability · added March 25, 2022
- CVE-2018-11138 ransomwareQuest KACE System Management Appliance Remote Command Execution Vulnerability · added March 25, 2022
- CVE-2018-6961VMware SD-WAN Edge by VeloCloud Command Injection Vulnerability · added March 25, 2022
- CVE-2017-6334NETGEAR DGN2200 Devices OS Command Injection Vulnerability · added March 25, 2022
- CVE-2016-11021D-Link DCS-930L Devices OS Command Injection Vulnerability · added March 25, 2022
- CVE-2017-6077NETGEAR DGN2200 Remote Code Execution Vulnerability · added March 7, 2022
- CVE-2014-7169GNU Bourne-Again Shell (Bash) Arbitrary Code Execution Vulnerability · added January 28, 2022
- CVE-2014-6271GNU Bourne-Again Shell (Bash) Arbitrary Code Execution Vulnerability · added January 28, 2022
- CVE-2021-25298Nagios XI OS Command Injection · added January 18, 2022
- CVE-2021-25297Nagios XI OS Command Injection · added January 18, 2022
- CVE-2021-25296Nagios XI OS Command Injection · added January 18, 2022
- CVE-2021-21315System Information Library for Node.JS Command Injection · added January 18, 2022
- CVE-2020-11978Apache Airflow Command Injection · added January 18, 2022
- CVE-2021-36260Hikvision Improper Input Validation · added January 10, 2022
- CVE-2019-10149Exim Mail Transfer Agent (MTA) Improper Input Validation · added January 10, 2022
- CVE-2021-35394Realtek Jungle SDK Remote Code Execution Vulnerability · added December 10, 2021
- CVE-2020-8816Pi-Hole AdminLTE Remote Code Execution Vulnerability · added December 10, 2021
- CVE-2021-27561Yealink Device Management Server-Side Request Forgery (SSRF) Vulnerability · added November 3, 2021
- CVE-2021-27104 ransomwareAccellion FTA OS Command Injection Vulnerability · added November 3, 2021
- CVE-2021-27102 ransomwareAccellion FTA OS Command Injection Vulnerability · added November 3, 2021
- CVE-2021-22502Micro Focus Operation Bridge Report (OBR) Remote Code Execution Vulnerability · added November 3, 2021
- CVE-2021-1498Cisco HyperFlex HX Data Platform Command Injection Vulnerability · added November 3, 2021
- CVE-2021-1497Cisco HyperFlex HX Installer Virtual Machine Command Injection Vulnerability · added November 3, 2021
- CVE-2020-25506D-Link DNS-320 Device Command Injection Vulnerability · added November 3, 2021
- CVE-2020-16846SaltStack Salt Shell Injection Vulnerability · added November 3, 2021
- CVE-2020-10987Tenda AC1900 Router AC15 Model Remote Code Execution Vulnerability · added November 3, 2021
- CVE-2020-10221rConfig OS Command Injection Vulnerability · added November 3, 2021
- CVE-2020-8515Multiple DrayTek Vigor Routers Web Management Page Vulnerability · added November 3, 2021
- CVE-2020-4428IBM Data Risk Manager Remote Code Execution Vulnerability · added November 3, 2021
- CVE-2020-4006Multiple VMware Products Command Injection Vulnerability · added November 3, 2021
- CVE-2019-19356Netis WF2419 Devices Remote Code Execution Vulnerability · added November 3, 2021
- CVE-2019-15949Nagios XI Remote Code Execution Vulnerability · added November 3, 2021
- CVE-2019-11539 ransomwareIvanti Pulse Connect Secure and Policy Secure Command Injection Vulnerability · added November 3, 2021
- CVE-2018-14558Tenda AC7, AC9, and AC10 Routers Command Injection Vulnerability · added November 3, 2021
The Dome
Block it at the edge while you fix it
The Dome's WAF runs the OWASP Core Rule Set in blocking mode and stops OS command injection payloads, including Shellshock before they reach your application.
See the DomeT Academy
Stop writing it in the first place
Learn to build software and systems without weaknesses like this one, with practice on real hosts in your browser, every objective checked on the machine.
Start freeSource: MITRE Common Weakness Enumeration, CWE version 4.19.1. CWE is a trademark of The MITRE Corporation.