Command Injection

Platform: TryHackMe- Topic: Command Injection (RCE)- PT1 Exam Preparation

Overview

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.

What is Command Injection?

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.

How it happens (High-level)

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.

Detection Methods

Command injection is typically identified as one of two types:

Verbose testing

Blind testing

If output isn’t visible, use time delays or forced output:

Example (URL encoded): curl http://vulnerable.app/process.php%3Fsearch%3DThe%20Beatles%3B%20whoami

Useful Payloads

Linux

Windows

Chaining operators: commonly ;, &&, |, & (behavior varies by shell/OS).

Prevention / Remediation

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.

Practical (TryHackMe)

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.

Recap