Skip to main content
Definition Website Computer and Technology

Command Injection

Subject: Computer and Technology noun /kəˈmænd ɪnˈdʒɛk.ʃən/ 1 definition

  1. Definition (noun)

    Entry #330 · Updated

    Command Injection is an injection vulnerability in which an application embeds untrusted user input into a command string passed to a host operating system shell or command interpreter without proper neutralization. When user-controlled strings containing shell metacharacters—such as ;, &&, |, backticks, or $() command substitutions—are concatenated into functions like C's system() or /bin/sh -c, the interpreter treats those tokens as control syntax rather than literal data and executes attacker-supplied instructions. Because the injected commands inherit the operating system privileges of the vulnerable process, exploitation enables unauthorized file access, data tampering, lateral network movement, or full system compromise. Unlike code injection—which injects syntax evaluated inside the application's own language runtime—command injection targets the underlying OS or downstream command processor, and is mitigated primarily by avoiding shell invocation through parameterized process APIs like execve alongside strict input allowlisting.

    Common Types

    • In-Band (Direct) Command Injection: Occurs when the vulnerable application executes the injected command and returns its standard output or error stream directly to the caller, such as inside an HTTP response or terminal output.

    • Blind Command Injection: Occurs when injected commands run on the host without returning output to the user, forcing attackers to confirm execution and extract data via time delays (sleep) or out-of-band DNS and HTTP callbacks.

    • Stored (Second-Order) Command Injection: Arises when untrusted input is saved safely in a database, filename, or configuration record and later interpolated into a shell command by a background worker, cron job, or administrative script.

    • Argument Injection: Exploits applications that invoke executables directly without a shell wrapper by supplying unvalidated input prefixed with - or --, tricking the target binary into treating user data as command-line options or flags.

    Example

    A web-based network diagnostics endpoint accepts a host parameter in an HTTP POST body, invokes Python's subprocess.run(f"ping -c 1 {host}", shell=True, capture_output=True), and returns stdout in the JSON response. When an attacker submits 127.0.0.1; cat /etc/passwd, /bin/sh interprets the semicolon as a command separator and executes cat /etc/passwd after ping, leaking host account entries.