Target Function
Overview
Before exploitation, plan the attack as action points to track progress and identify issues.
Attack Plan Checklist
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
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.io to decode:
Dynamic Verification (Debug)
Add breakpoint to line 30 (
service-controllers.js)Right-click
roleon line 17 β "Add to Watch"Send request with admin token
Check WATCH pane β
role: "admin"
β Step 3 Complete: Admin role obtained
Step 4: Reaching the Vulnerable Code
validateString Conditions
Condition Analysis
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
'
Breaks strings
"
Breaks strings
`
Breaks template literals
;
Safest - doesn't break onError string
Test with Semicolon
Response:
What This Confirms
β We reached the
evalfunctionβ
onErrorstring evaluated successfullyβ We see the verbose admin error message
β Our input (
;) appears in the message
β Step 4 Complete: Reached vulnerable code
Updated Checklist
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
Prepare payload - Inject code without breaking syntax
Confirm injection - Verify code executes
Achieve RCE - Execute system commands
Verify blindly - Confirm execution without output
Write exploit - Automate the process
Key Takeaways
Plan before exploit - Track progress, identify issues early
Understand conditions - Know exactly how to reach vulnerable code
Choose input wisely -
;triggers eval without breaking stringVerify each step - Don't skip ahead, confirm before proceeding
Use debugger - Watch variables to verify understanding
Last updated