CWEweakness

CWE-78 Improper Neutralization of Special Elements used in an OS Command

High Official page ↗
Alternate terms
Shell injection, Shell metacharacters, OS Command Injection
Abstraction
Base
Structure
Simple
Status
Stable
Likelihood of exploit
High
Languages
Not Language-Specific, Python
CWE version
5.0

Description

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 before it is sent to a downstream component.

Common consequences

• Confidentiality, Integrity, Availability, Non-Repudiation: 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 — 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.

Potential mitigations

• [Architecture and Design] If at all possible, use library calls rather than external processes to recreate the desired functionality. • [Architecture and Design, Operation] 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. • [Architecture and Design] 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. • [Architecture and Design] 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. • [Architecture and Design] 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 [REF-45] or a similar tool, library, or framework. These will help the programmer encode outputs in a manner less prone to error. • [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). • [Implementation] 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. • [Architecture and Design] 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. • [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. 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. • [Architecture and Design] 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. • [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). • [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). • [Implementation] 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] 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. • [Operation] 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 [REF-1481]. • [Architecture and Design, Operation] Run your code using the lowest privileges that are required to accomplish the necessary tasks [REF-76]. 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. • [Operation, Implementation] 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.

Detection methods

• 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 [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 • 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 • 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 • 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 • 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 • 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.)

Observed examples

• CVE-2024-53899: Virtual environment builder does not correctly quote "magic" template strings, allowing OS command injection using a directory whose name contains shell metacharacters • CVE-2025-44844: file upload functionality in wireless access point allows OS command injection via shell metacharacters through the file name in a Content-Disposition header • CVE-2024-6091: Chain: AI agent platform does not restrict pathnames containing internal "/./" sequences (CWE-55), leading to an incomplete denylist (CWE-184) that does not prevent OS command injection (CWE-78) • CVE-2024-41316: Lua application in network device allows OS command injection into os.execute() • CVE-2024-44335: Chain: filter only checks for some shell-injection characters (CWE-184), enabling OS command injection (CWE-78) • CVE-2024-52803: Platform for handling LLMs has OS command injection during training due to insecure use of the "Popen" function • CVE-2020-10987: OS command injection in Wi-Fi router, as exploited in the wild per CISA KEV. • CVE-2020-10221: Template functionality in network configuration management tool allows OS command injection, as exploited in the wild per CISA KEV. • CVE-2020-9054: Chain: improper input validation (CWE-20) in username parameter, leading to OS command injection (CWE-78), as exploited in the wild per CISA KEV. • CVE-1999-0067: Canonical example of OS command injection. CGI program does not neutralize "|" metacharacter when invoking a phonebook program. • CVE-2001-1246: Language interpreter's mail function accepts another argument that is concatenated to a string used in a dangerous popen() call. Since there is no neutralization of this argument, both OS Command Injection (CWE-78) and Argument Injection (CWE-88) are possible. • CVE-2002-0061: Web server allows command execution using "|" (pipe) character. • CVE-2003-0041: FTP client does not filter "|" from filenames returned by the server, allowing for OS command injection. • CVE-2008-2575: Shell metacharacters in a filename in a ZIP archive • CVE-2002-1898: Shell metacharacters in a telnet:// link are not properly handled when the launching application processes the link. • CVE-2008-4304: OS command injection through environment variable. • CVE-2008-4796: OS command injection through https:// URLs • CVE-2007-3572: Chain: incomplete denylist for OS command injection • CVE-2012-1988: Product allows remote users to execute arbitrary commands by creating a file whose pathname contains shell metacharacters.

Related

Attack pattern · CAPEC (5)

  • CAPEC-108 Command Line Execution through SQL Injection attack pattern
  • CAPEC-15 Command Delimiters attack pattern
  • CAPEC-43 Exploiting Multiple Input Interpretation Layers attack pattern
  • CAPEC-6 Argument Injection attack pattern
  • CAPEC-88 OS Command Injection attack pattern

Observed example · CVE (19)

  • CVE-2025-44844 TOTOLINK CA600-PoE V5.3c.6665_B20180820 was found to contain a command injection vulnerability in the setUpgradeFW function via the… vulnerability
  • CVE-2024-53899 virtualenv before 20.26.6 allows command injection through the activation scripts for a virtual environment. vulnerability
  • CVE-2024-52803 LLama Factory enables fine-tuning of large language models. vulnerability
  • CVE-2024-6091 A vulnerability in significant-gravitas/autogpt version 0.5.1 allows an attacker to bypass the shell commands denylist settings. vulnerability
  • CVE-2024-44335 D-Link DI-7003G v19.12.24A1, DI-7003GV2 v24.04.18D1, DI-7100G+V2 v24.04.18D1, DI-7100GV2 v24.04.18D1, DI-7200GV2 v24.04.18E1, DI-7300G+V2… vulnerability
  • CVE-2024-41316 TOTOLINK A6000R V1.0.1-B20201211.2000 was discovered to contain a command injection vulnerability via the ifname parameter in the… vulnerability
  • CVE-2020-10987 The goform/setUsbUnload endpoint of Tenda AC15 AC1900 version 15.03.05.19 allows remote attackers to execute arbitrary system commands via… vulnerability
  • CVE-2020-10221 lib/ajaxHandlers/ajaxAddTemplate.php in rConfig through 3.94 allows remote attackers to execute arbitrary OS commands via shell… vulnerability
  • CVE-2020-9054 Multiple ZyXEL network-attached storage (NAS) devices running firmware version 5.21 contain a pre-authentication command injection… vulnerability
  • CVE-2012-1988 Puppet 2.6.x before 2.6.15 and 2.7.x before 2.7.13, and Puppet Enterprise (PE) Users 1.0, 1.1, 1.2.x, 2.0.x, and 2.5.x before 2.5.1 allows… vulnerability
  • CVE-2008-4304 general/login.php in phpCollab 2.5 rc3 and earlier allows remote attackers to execute arbitrary commands via shell metacharacters in… vulnerability
  • CVE-2008-4796 The _httpsrequest function (Snoopy/Snoopy.class.php) in Snoopy 1.2.3 and earlier, as used in (1) ampache, (2) libphp-snoopy, (3) mahara,… vulnerability
  • CVE-2008-2575 cbrPager before 0.9.17 allows user-assisted remote attackers to execute arbitrary commands via shell metacharacters in a (1) ZIP (aka .cbz)… vulnerability
  • CVE-2007-3572 Incomplete blacklist vulnerability in cgi-bin/runDiagnostics.cgi in the web interface on the Yoggie Pico and Pico Pro allows remote… vulnerability
  • CVE-2003-0041 Kerberos FTP client allows remote FTP sites to execute arbitrary code via a pipe (|) character in a filename that is retrieved by the… vulnerability
  • CVE-2002-1898 Terminal 1.3 in Apple Mac OS X 10.2 allows remote attackers to execute arbitrary commands via shell metacharacters in a telnet:// link,… vulnerability
  • CVE-2002-0061 Apache for Win32 before 1.3.24, and 2.0.x before 2.0.34-beta, allows remote attackers to execute arbitrary commands via shell… vulnerability
  • CVE-2001-1246 PHP 4.0.5 through 4.1.0 in safe mode does not properly cleanse the 5th parameter to the mail() function, which allows local users and… vulnerability
  • CVE-1999-0067 phf CGI program allows remote command execution through shell metacharacters. vulnerability

Can also be · CWE (1)

  • CWE-88 Improper Neutralization of Argument Delimiters in a Command weakness

Child of · CWE (2)

  • CWE-74 Improper Neutralization of Special Elements in Output Used by a Downstream Component weakness
  • CWE-77 Improper Neutralization of Special Elements used in a Command weakness

Referenced by CAPEC · weakness (5)

  • CAPEC-108 Command Line Execution through SQL Injection attack pattern
  • CAPEC-15 Command Delimiters attack pattern
  • CAPEC-43 Exploiting Multiple Input Interpretation Layers attack pattern
  • CAPEC-6 Argument Injection attack pattern
  • CAPEC-88 OS Command Injection attack pattern

Referenced by CVE · weakness (7,156)

  • CVE-2026-104308 IBM Langflow OSS 1.0.0 through 1.12.3 could allow a remote authenticated attacker to cause a denial of service due to improper… vulnerability
  • CVE-2026-107326 IBM Langflow OSS 1.0.0 through 1.12.4 could allow a remote authenticated attacker to execute arbitrary code due to improper neutralization… vulnerability
  • CVE-2026-115805 Improper handling of local filesystem paths in Rapid7 Insight Agent on Linux and macOS may allow authenticated local users to gain elevated… vulnerability
  • CVE-2026-118905 Node Version Manager (nvm) is a POSIX-compliant shell function for managing multiple node.js versions. vulnerability
  • CVE-2026-119025 open 7.2.0 before 11.0.0 contains an OS command injection vulnerability that allows attackers to execute PowerShell code by supplying… vulnerability
  • CVE-2026-33924 Two OS command injection vulnerabilities were discovered in the update installation functionality due to insufficient validation of the… vulnerability
  • CVE-2026-66088 In openEQUELLA before 2026.1, the system.execute() function available to the scripting engine runs supplied operating system commands… vulnerability
  • CVE-2026-90865 An OS command injection vulnerability in Progress Software WS_FTP Server versions prior to 2024.0.7 and 2025.0.4 on Windows could allow… vulnerability
  • CVE-2026-90868 An OS command injection vulnerability in Progress Software WS_FTP Server versions prior to 2024.0.7 and 2025.0.4 on Windows could allow… vulnerability
  • CVE-2026-97854 Yamaha wireless LAN router NWR100 provided by Yamaha Corporation contains an OS command injection vulnerability. vulnerability
  • CVE-2013-20007 Linksys WAG200G through 1.01.06 contains an OS command injection vulnerability that allows authenticated attackers to execute commands by… vulnerability
  • CVE-2026-103403 An Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') vulnerability in AccessManager in Juniper… vulnerability
  • CVE-2026-103406 An Improper Neutralization of Special Elements used in an OS Command vulnerability in the AutomatedProvisioner in Juniper Networks Session… vulnerability
  • CVE-2026-106079 An Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') vulnerability in AccessManager in Juniper… vulnerability
  • CVE-2026-110541 Dell PowerProtect Data Domain, Feature Release versions 7.7.1.0 through 8.8, LTS2024 release versions 7.13.1.0 through 7.13.1.80, LTS2025… vulnerability
  • CVE-2026-114278 The che-machine-exec service constructs a shell command by concatenating user-controlled input (the username and namespace fields from the… vulnerability
  • CVE-2026-115904 Topluyo is a social networking platform. vulnerability
  • CVE-2026-116778 FOG is a free open-source cloning/imaging/rescue suite/inventory management system. vulnerability
  • CVE-2026-118477 The ei_git_repo_url parameter in the Git remote configuration endpoint of KaliFast is vulnerable to OS Command Injection. vulnerability
  • CVE-2026-118607 Alpine iLX-F511 diagapp Command Injection Vulnerability. vulnerability
  • CVE-2026-118615 Ultralytics torch_safe_load Command Injection Remote Code Execution Vulnerability. vulnerability
  • CVE-2026-118692 CherryTree through 1.7.2 contains an OS command injection vulnerability in CtActions::link_clicked that allows attackers to execute… vulnerability
  • CVE-2026-118755 Volmarg Personal Management System through 2.1.0 contains an OS command injection vulnerability that allows authenticated users to execute… vulnerability
  • CVE-2026-61567 AVideo is a video-sharing Platform. vulnerability
  • CVE-2026-67074 HCL BigFix AEX is affected by a Remote Code Execution Vulnerability . vulnerability
  • CVE-2026-78674 The BPMN System REST APIs do not sufficiently validate input parameters, allowing authenticated users to submit crafted requests that can… vulnerability
  • CVE-2026-86379 Dell PowerProtect Data Domain Management Center, Feature Release versions 7.7.1.0 through 8.8, LTS2024 release versions 7.13.1.0 through… vulnerability
  • CVE-2026-86394 Dell PowerProtect Data Domain, Feature Release versions 7.7.1.0 through 8.8, LTS2024 release versions 7.13.1.0 through 7.13.1.80, LTS2025… vulnerability
  • CVE-2026-86395 Dell PowerProtect Data Domain Virtual Edition, Feature Release versions 7.7.1.0 through 8.8, LTS2024 release versions 7.13.1.0 through… vulnerability
  • CVE-2026-86396 Dell PowerProtect Data Domain, Feature Release versions 7.7.1.0 through 8.8, LTS2024 release versions 7.13.1.0 through 7.13.1.80, LTS2025… vulnerability
Show all 7,156 ›

Referenced by CWE · can precede (1)

  • CWE-184 Incomplete List of Disallowed Inputs weakness

Referenced by CWE · has member (9)

  • CWE-1200 Weaknesses in the 2019 CWE Top 25 Most Dangerous Software Errors view
  • CWE-1337 Weaknesses in the 2021 CWE Top 25 Most Dangerous Software Weaknesses view
  • CWE-1350 Weaknesses in the 2020 CWE Top 25 Most Dangerous Software Weaknesses view
  • CWE-1387 Weaknesses in the 2022 CWE Top 25 Most Dangerous Software Weaknesses view
  • CWE-1425 Weaknesses in the 2023 CWE Top 25 Most Dangerous Software Weaknesses view
  • CWE-1430 Weaknesses in the 2024 CWE Top 25 Most Dangerous Software Weaknesses view
  • CWE-1435 Weaknesses in the 2025 CWE Top 25 Most Dangerous Software Weaknesses view
  • CWE-635 Weaknesses Originally Used by NVD from 2008 to 2016 view
  • CWE-884 CWE Cross-section view

Referenced by OWASP · mapped cwe (2)