Command Execution
Overview
With code injection confirmed, maximize exploitation by achieving Remote Code Execution (RCE).
Current Progress
1-7
Previous steps
β
8
Reach command execution or file writing
β³
9
Blindly verify command execution/file writing
β³
10
Automate exploitation (write exploit)
β³
Node.js Command Execution
Basic One-liner
require("child_process").execSync("touch pwned");Integrate into Payload
{
"text": "'}) + require('child_process').execSync('touch pwned')//"
}Test Locally
Result: File created! β Command execution achieved!
Note: If
requiredoesn't work (e.g.,"type": "module"in package.json), find alternative or use already imported packages.
Obtaining Command Output
Challenge
Code output only visible in backend console - need remote access to output.
Options Analysis
Console log
β Local only
Reverse shell
β Outbound blocked
HTTP exfiltration
β No internet
DNS exfiltration
β No internet
Database storage
β No database
File write + read
β οΈ Possible
HTTP response injection
β οΈ Possible
Boolean/timing
β οΈ Last resort
Method 1: Console Logging (Local Only)
Payload:
Output (in debug console):
β Works locally, β not for production
Method 2: File Write + Read
Requirements
Writable directory
Way to read file publicly
Options for Reading
Public directory
Write to ./public/
File read vuln
LFI, XXE, SQLi
Overwrite function
Replace route handler
Add new route
Inject middleware into app.js
This Application
No public directory in
app.jsNo file read vulnerability found
No database
Method 3: Inject Webshell into app.js
Target Code
Challenge
Must place route before 404 middleware, otherwise treated as 404.
Exploitation Steps
Step 1: Get Admin Token
Step 2: Create Webshell File
Base64 encode the webshell:
Output:
Write to file via command injection:
Step 3: Inject into app.js
Command to inject before 404 middleware:
Base64 encode:
Output:
Execute via command injection:
Step 4: Use Webshell
Or visit in browser:
Complete Attack Chain
Why Base64 Encoding?
Problems with Direct Commands
Quotes break JSON
Special characters need escaping
Complex commands hard to format
Solution
Avoids escaping issues
Works with any command complexity
Reliable execution
Key Takeaways
Code injection β RCE - Natural escalation path
Output exfiltration - Multiple methods, try each
Base64 encoding - Solves escaping problems
sed injection - Powerful for modifying files
Placement matters - Routes must be before 404 handler
Test environment - Auto-reload makes injection easier
Next Steps
Explore HTTP response injection
Automate with exploit script
Test on production target
Last updated