OS command injection meaning, in plain words

OS command injection makes a server run commands an attacker slipped in. How it arises, what it can do, and the root fix of avoiding a shell, per IPA and MITRE.

Written by: Mio Kanzaki(Security Analyst (AI))Reviewed by: 千葉圭介Updated

OS command injection is a technique that makes a server run commands an attacker slipped in. IPA describes it as a flaw in a feature that builds and runs an OS command (an instruction to the server's basic software) from a value supplied from outside. If that value is crafted, an unintended command can be run. MITRE's CWE-78 organises the same type of weakness.

How does OS command injection work?

Imagine a receptionist who reads a customer's words straight out over the office loudspeaker. A request for "one copy of the document" is harmless. If a second instruction is tacked on, the loudspeaker broadcasts it without telling the two apart, and the staff carry out every instruction they hear.

On a website, features such as converting images, creating PDFs or compressing files may call an outside program inside the server. If the text a visitor typed is built into the command as part of it, the same thing can happen.

The root fix is to avoid features that call a shell (the mechanism that interprets instructions to the OS) at all. IPA points to substituting other functions. If you must use one, limit the characters used in the arguments to an allowed set. How to check your own site is gathered on the OS command injection vulnerability page.

Why does OS command injection matter?

The impacts IPA lists are broad: viewing, altering and deleting files inside the server, and leaking important information such as configuration files. User accounts can also be added and malicious programs installed. The server can be used as a stepping stone to attack other systems.

So it can mean losing control of the server itself, not only the site's content. It is also an entrance to tampering and information leaks, which makes it one of the weaknesses with large consequences.

IPA does not recommend listing forbidden symbols, because that leaves gaps, and advises deciding which characters are allowed. As with SQL injection, a WAF is an emergency measure, and the root fix is correcting the program.

If you want to see what your site shows from outside before going further, the free URL check reads only what anyone can see.

Related terms

  • SQL injection: a technique that shares the problem of mixing input into a command.
  • Tampering: damage that can follow when a server is taken over.
  • WAF: an extra defence that stops suspicious traffic at the entrance.
  • Path traversal: a technique that reads files inside the server beyond the intended range.

Next step

Start by listing the features on your site that call an outside program, such as image conversion or PDF output. How to check and fix them is on the OS command injection vulnerability page, and the overall defences are in hacking measures. If you already see suspicious activity, use the emergency guide. To talk it through, contact us.

Frequently asked questions

Can OS command injection happen on a WordPress site?

It can. A plugin or theme that calls an outside program on the server, for example to process images or convert files, can be the entrance. Keep the parts you use up to date, and consider replacing any whose updates have stopped.

Is removing dangerous characters enough to prevent it?

It tends to leave gaps and is not recommended. IPA advises letting through only an allowed combination of characters, not listing the symbols to forbid. The root fix is a build that does not invoke a shell.

Frequently asked questions

Can OS command injection happen on a WordPress site?

It can. A plugin or theme that calls an outside program on the server, for example to process images or convert files, can be the entrance. Keep the parts you use up to date, and consider replacing any whose updates have stopped.

Is removing dangerous characters enough to prevent it?

It tends to leave gaps and is not recommended. IPA advises letting through only an allowed combination of characters, not listing the symbols to forbid. The root fix is a build that does not invoke a shell.

See what an attacker can see, today

The free URL check returns a grade in under a minute. For costs and next steps, book a free consultation.