Second-Order Command Injection
Web developers often secure obvious code execution entry points with proper filters. However, many applications implement background tasks that interact with the OS. Testing all input fields for command injection is crucial, even without obvious entry points.
Testing the Web Application
Obvious Entry Point: /ping
Web application allows setting and pinging an IP address. This is an obvious entry point for command injection.
Testing for Command Injection
Simple payload attempt:
POST /update HTTP/1.1
Host: 172.17.0.2:1337
Content-Type: application/json
{"deviceIP":"${whoami}","password":""}Response:
HTTP/1.1 400 Bad Request
{"message": "Invalid Characters in DeviceIP!"}Result: Filter blocks special characters.
Fuzzing Allowed Characters
Using wfuzz with SecLists special-chars.txt:
Result:
Only . is allowed β Cannot inject command execution payload here.
Discovering Hidden Functionality
Analyzing Logout Response
When logging out, response contains:
Key insight: Web application logs data based on user profile! If logging uses system commands without sanitization, there may be command injection opportunity.
Testing User Registration
Register new user with special characters in name and username parameters:
Login, then logout. Analyze response:
Command injection confirmed! The username is passed to a shell command.
Exploitation
Register Malicious User
Use backticks for command injection:
Trigger Execution
Login as the new user
Logout
Check response:
Result: whoami executed β returned root
Attack Flow
Key Takeaways
Filter at one endpoint β Filter everywhere
Background processes (logging, cron jobs, etc.) may use user data unsafely
Test ALL input fields for injection vulnerabilities
Debug messages can reveal hidden functionality
Automated scanners help, but manual testing on critical fields is essential
User profile data (username, name, email) is often used in background processes
Question Walkthrough
Task: Exploit second-order command injection to obtain the flag.
Step 1: Register Malicious User
Navigate to /register
Set username to (with backticks):
Step 2: Login
Login with the newly created account.
Step 3: Logout and Capture Response
With Burp intercepting, logout and send request to Repeater.
Step 4: Check Response
The logout response contains:
Flag is displayed in the response!
Last updated