HTTP Response Injection
Overview
Instead of file-based exfiltration, inject command output directly into the HTTP response.
Possible Responses in /generate/
403
Unauthorized
No auth
403
Invalid input
Non-admin
403
Verbose message
Admin + bad char
500
Could not generate QR code
General errors
Target: Verbose message (403) - only one with user-controlled content.
Understanding the Catch Block
try {
// ...SNIP...
} catch (e) {
if (e.statusCode === 403) {
return next(e); // β Shows 'e.message'
} else {
return next({
message: "Could not generate QR code.",
statusCode: 500, // β Static message
});
}
}Key Insight
To get custom message displayed:
Must have
statusCode === 403Our injection was missing
statusCode!
Controlling the Response
Test Payload
Result
Response:
β Custom message displayed!
Injecting Command Output
Original onError String
After Injection
Adding Command Execution
Goal: Replace test message with command output.
Payload Structure
Full Payload
Final eval String
Testing the Payload
Response:
β Command output in HTTP response!
Why Backticks?
Problem
Multiple quote types in payload:
JSON uses
"JavaScript string uses
'Need another quote type
Solution
Use backticks ` for the final quote:
This avoids escaping hell in JSON/curl.
Practical Exploitation
Step 1: Get Admin Token
Step 2: Find the Flag
Base64 encode the find command:
Execute via injection:
Response:
Step 3: Read the Flag
Response:
Payload Template
Generic Form
With Base64 (for complex commands)
Why Base64?
Problems Without Encoding
Quotes break JSON
cat "file"
Spaces in paths
cat /path with spaces/
Special chars
grep -E "pattern"
Pipes/redirects
`cmd1
Solution
Comparison: Methods
Console log
Simple
Local only
File write
Persistent
Need read access
Webshell
Full control
Modifies app
HTTP response
No file changes
Limited output length
Updated Checklist
1-7
Previous steps
β
8
Reach command execution
β
9
Blindly verify execution
β
10
Automate exploitation
β³
Key Takeaways
Understand response logic - Know what controls output
statusCode matters - Must be 403 to show message
Quote management - Use backticks to avoid escaping
Base64 encoding - Essential for complex commands
Response injection - Cleaner than file-based methods
Last updated