Command Injection is the abuse of an application's behavior to execute operating system commands. Because the commands run with the same privileges as the application, successful exploitation can lead to sensitive file access, data exposure, and full remote code execution (RCE).
Key idea: If user input is inserted into a system command (directly or indirectly) and executed, operators like ;, &&, & can often be used to chain attacker-controlled commands.
Command injection happens when an application passes attacker-controlled input into a system shell or command execution function, allowing unintended commands to be executed on the server.
Example: If an app runs ping <user_input>, then input like 127.0.0.1; whoami may execute whoami too.
Applications sometimes use language features/libraries to execute OS commands (PHP, Python, NodeJS, etc.). If the input is not strictly validated or if the command is passed to a shell, attackers can inject operators to add new commands.
Typical danger pattern: concatenating user input into a command string and executing it through a shell.
Command injection is typically identified as one of two types:
whoami is displayed).whoami, id, ls).If output isn’t visible, use time delays or forced output:
sleep 5 (Linux), ping -n 6 127.0.0.1 (Windows), timeout 5 (Windows).curl/wget to call your server and confirm execution.Example (URL encoded): curl http://vulnerable.app/process.php%3Fsearch%3DThe%20Beatles%3B%20whoami
whoami — identify the running userid — user + group contextls — discover files/configssleep 5 — blind timing testping -c 5 127.0.0.1 — blind timing testcat /etc/passwd — test file read (only if safe/authorized)whoami — running userdir — list directorytimeout 5 — blind timing testping -n 6 127.0.0.1 — blind timing testChaining operators: commonly ;, &&, |, & (behavior varies by shell/OS).
Reducing command injection risk usually comes down to removing shell execution from the equation.
Filter bypasses exist. Input filtering alone is fragile; design away shell execution where possible.
In the practical portion, test payloads to confirm whether command injection exists. If blind, use timing/OAST. Goal: retrieve the flag in /home/tryhackme/flag.txt.
Cheat sheet / payload list: payload-box/command-injection-payload-list
Tip: Try multiple approaches; different filters/OS targets can require different syntax.