AI pentesting guides / Vulnerability classes

OS command injection

Command injection testing

Command injection testing checks whether input sent to an application can be executed as part of an operating-system command on the server. OS command injection is CWE-78 and part of OWASP Top 10 2021 A03: Injection, and it usually means full compromise of the host process.

It appears wherever applications call out to system utilities: network diagnostics (ping, traceroute), file conversion, image processing, archive handling and admin tooling. Many cases are blind, so the output never appears in the response.

Classification

  • CWE-78 Improper Neutralization of Special Elements used in an OS Command; related CWE-77 (command injection in general) and CWE-94 / CWE-95 for code and eval injection.
  • OWASP Top 10 2021: A03 Injection.
  • No dedicated OWASP API Security Top 10 2023 category.

How it is found

Identify parameters likely to reach a shell: hostnames, file names, formats and options passed to utilities. Test with shell metacharacters that separate or substitute commands, such as ;, |, && and $( ), in a textbook form like appending ;id to a hostname. Watch for changes in output, errors or timing. Because the output is often discarded, blind techniques are standard: a sleep that delays the response, or a command that makes an outbound DNS or HTTP request to a host you control. Server-side code injection (eval in JavaScript, Python or PHP) is closely related and tested similarly.

What counts as proof

Visible proof is command output in the response, such as the result of id or whoami. For blind injection, an out-of-band callback from the target host to your unique hostname is strong proof, because nothing else should cause that host to contact you. A timing delay that scales with an injected sleep is supporting evidence. Do not run destructive commands, and do not read sensitive files beyond what proves execution.

Remediation

Avoid the shell: use language APIs instead of calling utilities, or call executables with an argument array (execve-style) rather than a command string. Validate input against a strict allow-list, such as a hostname pattern. Never pass user input to eval or similar. Run the service with least privilege and in a container or sandbox to limit blast radius.

With Pentest-Swarm

How Pentest-Swarm tests for command injection

Command injection is one of the injection classes Pentest-Swarm proves, with an out-of-band oracle for blind cases.

  • An adaptive sweep injects a shell polyglot (semicolon, backtick, subshell and pipe breakouts) carrying an interactsh callback into query parameters.
  • The target fetching the callback is the proof, with no response signal needed; the finding is badged VERIFIED.
  • Shipped chains prove DVGA's systemDebug command injection and NodeGoat's server-side JavaScript eval injection.
  • Template injection is proven separately: an arithmetic expression evaluated by the engine in the attack response but not the control.

Where it falls short

The out-of-band oracle needs the target to have outbound network access; in egress-restricted environments a real injection may be reported Inconclusive. Injection in non-query inputs such as file uploads, headers or multi-step workflows may need manual follow-up. A code review with SAST (Pentest-Swarm integrates semgrep) is better at finding every shell call in a codebase.

Questions

What is the difference between command injection and code injection?

Command injection runs OS commands through a shell. Code injection runs code in the application's own language, for example through eval.

Is escaping shell metacharacters enough?

It is fragile. Avoiding the shell and passing arguments as an array is the reliable fix.

How is blind command injection detected?

Through side effects: a time delay, or an out-of-band DNS or HTTP request from the server to infrastructure the tester controls.

Sources

  1. CWE-78
  2. OWASP OS Command Injection Defense Cheat Sheet