Planning

Overview

With code review complete and functions shortlisted, we now set up the web application locally for testing.


Setting Up Local Environment

Scenario

  • Provided: Source code + instructions

  • Backend: Debian-based Linux

  • No VM/Docker provided

Note: If using Windows, run on Linux VM or PwnBox to match production.

Installation

# Navigate to project
cd ./intro_to_whitebox_pentesting

# Install dependencies
npm install

Running the Application

Output:

Verify Application Works

Response:

βœ… Application running correctly!


Checking for Public Vulnerabilities

npm audit

Output:

If Vulnerabilities Found

Update Type
Action

Patch (x.x.X)

Safe to update

Minor (x.X.0)

Usually safe

Major (X.0.0)

May have breaking changes

Note: Major updates may require code changes - recommend developers implement.


Testing validateString

Test /api/service/generate Endpoint

Response:

βœ… QR code generated successfully!

Tip: To preview QR code, save to HTML file and open in browser.


Debugging with VSCode

Run in Debug Mode

  1. Open Run and Debug tab in VSCode

  2. Click Run icon next to "Launch Program"

  3. Bottom bar turns red = debug mode active

Add Breakpoint

  1. Open controllers/service-controllers.js

  2. Click on line number (or Shift+F9)

  3. Red dot appears = breakpoint enabled

Breakpoint on validateString (Line 4)

Re-send Request

Application breaks at breakpoint!

Inspect Variables

In VARIABLES pane:

  • input: "this is a test"

  • onError: "throw new Error('Invalid input for role: user')"


Breakpoint on Line 20 (generateQR)

Add Breakpoint

Line 20 in service-controllers.js (after try {):

Inspect Variables

Variable
Value

text

"this is a test"

role

"user"

req.user

{ email: "test@test.com", role: "user", ... }

Answer: The value of role is user


Debug Workflow Summary


VSCode Debug Controls

Button
Action

▢️ Continue

Resume execution

⏭️ Step Over

Execute next line

⏬ Step Into

Enter function call

⏫ Step Out

Exit current function

πŸ”„ Restart

Restart debugging

⏹️ Stop

Stop debugging


Key Findings So Far

Observation
Implication

role comes from JWT

Need to control JWT to inject

role = "user" for test@test.com

Role determined by email

onError contains role

Injection via role β†’ eval

No public CVEs

Must exploit custom code


Next Steps

  1. Understand eval injection - How to exploit eval()

  2. Control the role - How is role determined?

  3. Craft payload - Bypass filters, achieve execution

  4. Test exploitation - Confirm vulnerability

Last updated