What Is OS Command Injection? CWE-78 Explained
Security Beginner 6 min read

What Is OS Command Injection? CWE-78 Explained

OS command injection (CWE-78) lets attacker input reach the server's shell. How it happens, why it scores CVSS 9.8, and how to prevent and detect it.

Published: December 2, 2026 • Updated: December 2, 2026
command injectioncwe-78web securitysecure coding

OS command injection is a web application flaw where attacker-controlled input ends up inside a command that the server hands to the operating system shell. The attacker adds shell syntax to a parameter and the server runs it. It is tracked as CWE-78, it almost always scores CVSS 9.8 when reachable without a login, and it is behind the Movable Type installer flaw exploited this week. This article explains how it happens, how to find it and how to stop it.

What is OS command injection?

OS command injection is a vulnerability in which an application builds an operating system command from user input without neutralizing shell syntax, so the attacker's input is interpreted as additional commands. The commands run with the privileges of the application process, usually the web server account.

How does OS command injection happen?

It happens when code calls the shell with a string that includes user input, and the input contains characters the shell treats as control syntax such as semicolons, pipes or backticks. The shell cannot tell which part of the string the developer wrote and which part the attacker supplied.

The usual path looks like this. A script needs to do something the language cannot do natively, or the developer finds the shell quicker: resolve a hostname, convert an image, check a mail server, list a directory. The script concatenates a request parameter into a command string and passes it to a function that invokes the shell. An attacker then sets the parameter to a legitimate-looking value followed by a shell metacharacter and a second command. The shell executes both.

Installer and diagnostic scripts are a common home for this bug because they do exactly this kind of system probing. Movable Type's mt-wizard.cgi tests database and mail settings during setup. The Juniper Session Smart Conductor flaw covered earlier this week was a crafted identifier reaching a provisioning command. Mitel's MiCollab conferencing component had the same weakness class in a different product. The common factor is untrusted input meeting a shell.

Why does it score so high?

Three things push command injection to the top of the CVSS scale.

  • No authentication. Setup scripts, health checks and API endpoints often run before any login check. If the vulnerable code is reachable anonymously, the vector is network, privileges none.
  • Full control of the process. Unlike SQL injection, which is bounded by what the database can do, a shell command can read any file the process can read, write to the document root, start network connections and download further tooling. Confidentiality, integrity and availability all go to high.
  • Reliability. Command injection rarely depends on memory layout or timing. If the request reaches the shell, it works every time, which is why attackers move on it within days of disclosure.

The practical ceiling is the privilege of the web process. The Movable Type advisories do not claim root, and on a hardened host the damage stops at the web account. On a host where the web user can read configuration files with database credentials, or where the same account runs other sites, the blast radius is much larger. That is the argument for least privilege on web accounts: it does not prevent the bug, but it caps what the bug can do.

How is it different from code injection?

Code injection, such as the Perl code injection in Movable Type's April advisory, runs attacker input inside the application's own interpreter. OS command injection hands it to the operating system shell. The outcome overlaps, since code running in the interpreter can also spawn a shell, but the fixes differ. Code injection is fixed by never evaluating user input as code. Command injection is fixed by never building shell command strings from user input. Related but distinct is XML injection, where input reaches an XML parser rather than a shell.

How do you prevent OS command injection?

You prevent it by not invoking a shell with user-supplied data. Call the operating system through APIs that take the program and its arguments as a list, so no shell parsing occurs, and validate every argument against a strict allowlist before passing it.

In order of preference:

  1. Do not shell out. Most tasks that developers reach the shell for have a native library: DNS lookups, image processing, file listing, mail delivery. A library call has no shell to inject into.
  2. Use list-form execution. Every mainstream language has a way to run a program with an explicit argument array. The arguments are passed to the program directly and the shell never sees them. This removes the metacharacter problem entirely.
  3. Allowlist, never blocklist. If an argument must come from user input, define exactly what is acceptable (a hostname pattern, a numeric range, a fixed set of options) and reject everything else. Blocklisting individual characters fails because shells have many ways to express the same thing.
  4. Drop unneeded entry points. The Movable Type workaround is to delete the installer. An endpoint that does not exist cannot be injected into. Review every CGI script, admin tool and diagnostic page on a production server and remove the ones nobody uses.
  5. Run web processes with minimal rights. Separate accounts per application, read-only code directories, no write access outside upload and cache paths, no outbound network access the application does not need.
  6. Use a WAF as a stopgap, not a fix. Generic command injection signatures block the obvious payloads and buy time while you patch. Attackers encode around them, so do not treat a WAF rule as remediation.

How do you detect OS command injection attempts?

Look in two places: the web server access log and the process tree.

In the access log, requests to administrative or setup scripts from unexpected sources are the first signal. Parameters containing shell metacharacters, URL-encoded or not, are the second. For a script like an installer that should receive no traffic at all after setup, any request is worth investigating.

On the host, a web server process should not spawn shells, download tools or open outbound connections to unfamiliar addresses. Endpoint detection that alerts on a web server account launching a shell catches successful exploitation regardless of the payload. If you run Movable Type and want the specific checks, see how to check a Movable Type site for compromise.

What to do with this

Audit your own code and your vendors' products for the pattern: user input, string concatenation, shell call. Fix the pattern, not the individual payload. Remove installers and diagnostics from production. Give web accounts the minimum they need. And when a vendor says attacks are observed against a command injection bug, patch or disable the endpoint the same day, because this class does not require a skilled attacker to exploit.