Target Function

Overview

Before exploitation, plan the attack as action points to track progress and identify issues.


Attack Plan Checklist

#
Step
Status

1

Hit the validateString function

βœ…

2

Trace how input looks within function

βœ…

3

Obtain an admin role

⏳

4

Confirm we reach the eval function

⏳

5

Prepare the payload

⏳

6

Confirm payload reaches target as intended

⏳

7

Inject code and confirm injection

⏳

8

Reach command execution or file writing

⏳

9

Blindly verify command execution/file writing

⏳

10

Automate exploitation (write exploit)

⏳


Step 3: Obtain Admin Role

Real-World Methods

Method
Description

Privilege escalation

Exploit to elevate permissions

Authorization flow

Legitimate admin access

XSS/CSRF

Attack admin user

Brute force

Guess admin credentials

Request access

Ask client for admin account

Note: If no vuln exists, request admin account. Impact is lower (only affects admin users).

Our Case: Email-based Role

Looking at getUserToken:

Solution: Use @hackthebox.com email domain!

Get Admin Token

Response:

Verify Role in JWT

Use jwt.ioarrow-up-right to decode:

Dynamic Verification (Debug)

  1. Add breakpoint to line 30 (service-controllers.js)

  2. Right-click role on line 17 β†’ "Add to Watch"

  3. Send request with admin token

  4. Check WATCH pane β†’ role: "admin"

βœ… Step 3 Complete: Admin role obtained


Step 4: Reaching the Vulnerable Code

validateString Conditions

Condition Analysis

Condition
Triggers eval?
Input in onError?

Not a string

βœ…

❌ No control

Empty string

βœ…

❌ No control

Bad characters

βœ…

βœ… Yes!

Must use Condition 3 - only way to have input in onError.

Bad Characters

Char
Effect

'

Breaks strings

"

Breaks strings

`

Breaks template literals

;

Safest - doesn't break onError string

Test with Semicolon

Response:

What This Confirms

  1. βœ… We reached the eval function

  2. βœ… onError string evaluated successfully

  3. βœ… We see the verbose admin error message

  4. βœ… Our input (;) appears in the message

βœ… Step 4 Complete: Reached vulnerable code


Updated Checklist

#
Step
Status

1

Hit the validateString function

βœ…

2

Trace how input looks within function

βœ…

3

Obtain an admin role

βœ…

4

Confirm we reach the eval function

βœ…

5

Prepare the payload

⏳

6

Confirm payload reaches target as intended

⏳

7

Inject code and confirm injection

⏳

8

Reach command execution or file writing

⏳

9

Blindly verify command execution/file writing

⏳

10

Automate exploitation (write exploit)

⏳


Current Attack Flow


Next Steps

  1. Prepare payload - Inject code without breaking syntax

  2. Confirm injection - Verify code executes

  3. Achieve RCE - Execute system commands

  4. Verify blindly - Confirm execution without output

  5. Write exploit - Automate the process


Key Takeaways

  1. Plan before exploit - Track progress, identify issues early

  2. Understand conditions - Know exactly how to reach vulnerable code

  3. Choose input wisely - ; triggers eval without breaking string

  4. Verify each step - Don't skip ahead, confirm before proceeding

  5. Use debugger - Watch variables to verify understanding

Last updated