Authentication
Case Study Overview
Practical whitebox pentesting exercise demonstrating advanced code injection that requires source code access to identify and exploit.
Requirements
VSCode installed
Node.js installed
Source code archive
Data Gathering
Scenario
Given code base in archive without further details (minimum requirement for whitebox pentest).
Setup
# Download and extract
wget <archive_url> && unzip intro_to_whitebox_pentesting.zip
cd intro_to_whitebox_pentesting
# Open in VSCode
code .Project Structure
Code Analysis
app.js - Entry Point
Key Points:
Express server on port 5000
JSON body parser β endpoints expect JSON body
Two route groups:
/api/authand/api/service
Server Startup
Authentication Routes
auth-routes.js
Endpoint: POST /api/auth/authenticate
Authentication Controllers
auth-controllers.js Functions
validateEmail
Validate email format
No (local)
getUserToken
Generate JWT token
Yes
verifyToken
Verify JWT token
Yes
validateEmail
Simple regex validation for email format.
getUserToken
Flow:
Get email from POST body (JSON)
Validate email format
Sign JWT with email and role
Return token
verifyToken
Flow:
Get token from
AuthorizationheaderIf no token β 403 Unauthorized
Verify JWT signature
Add decoded data to
req.userCall
next()to proceed
Usage: Middleware for authenticated endpoints
Using AI for Code Understanding
VSCode Copilot
Can use AI to:
β Confirm your understanding
β Clarify unclear code
β οΈ Don't overly rely on it
β οΈ Always double-check responses
Example Query
"What does this function do?"
AI explains JWT token generation with email and role claims.
Identifying Vulnerable Function
Service Controllers Analysis
Looking at service-controllers.js:
Why It's Vulnerable
eval() usage
Executes arbitrary code
User-controlled input
onError parameter
Blacklist filtering
Can be bypassed
Answer
Most likely vulnerable function: validateString
The use of eval() in validateString creates a security vulnerability that could potentially be exploited to execute arbitrary code.
Code Review Findings
Authentication (auth-controllers.js)
validateEmail
β Safe
Regex validation
getUserToken
β Safe
Proper JWT signing
verifyToken
β Safe
Proper JWT verification
Service (service-controllers.js)
validateString
π¨ VULNERABLE
eval() with user input
Next Steps
Analyze
validateString- Understand full contextTrace input flow - How does user input reach
eval()?Check filters - Can blacklist be bypassed?
Local Testing - Set up environment and test
Exploitation - Develop PoC
Key Takeaways
Start with entry points -
app.jsshows route structureFollow the code - CMD/CTRL + click in VSCode
Look for dangerous functions -
eval(),exec(), etc.Understand the flow - How data moves through app
Use AI wisely - Confirm, don't rely blindly
Last updated