HTTP Response Injection

Overview

Instead of file-based exfiltration, inject command output directly into the HTTP response.


Possible Responses in /generate/

Status
Message
Condition

403

Unauthorized

No auth

403

Invalid input

Non-admin

403

Verbose message

Admin + bad char

500

Could not generate QR code

General errors

Target: Verbose message (403) - only one with user-controlled content.


Understanding the Catch Block

try {
  // ...SNIP...
} catch (e) {
  if (e.statusCode === 403) {
    return next(e);  // ← Shows 'e.message'
  } else {
    return next({
      message: "Could not generate QR code.",
      statusCode: 500,  // ← Static message
    });
  }
}

Key Insight

To get custom message displayed:

  • Must have statusCode === 403

  • Our injection was missing statusCode!


Controlling the Response

Test Payload

Result

Response:

βœ… Custom message displayed!


Injecting Command Output

Original onError String

After Injection

Adding Command Execution

Goal: Replace test message with command output.

Payload Structure

Full Payload

Final eval String


Testing the Payload

Response:

βœ… Command output in HTTP response!


Why Backticks?

Problem

Multiple quote types in payload:

  • JSON uses "

  • JavaScript string uses '

  • Need another quote type

Solution

Use backticks ` for the final quote:

This avoids escaping hell in JSON/curl.


Practical Exploitation

Step 1: Get Admin Token

Step 2: Find the Flag

Base64 encode the find command:

Execute via injection:

Response:

Step 3: Read the Flag

Response:


Payload Template

Generic Form

With Base64 (for complex commands)


Why Base64?

Problems Without Encoding

Issue
Example

Quotes break JSON

cat "file"

Spaces in paths

cat /path with spaces/

Special chars

grep -E "pattern"

Pipes/redirects

`cmd1

Solution


Comparison: Methods

Method
Pros
Cons

Console log

Simple

Local only

File write

Persistent

Need read access

Webshell

Full control

Modifies app

HTTP response

No file changes

Limited output length


Updated Checklist

#
Step
Status

1-7

Previous steps

βœ…

8

Reach command execution

βœ…

9

Blindly verify execution

βœ…

10

Automate exploitation

⏳


Key Takeaways

  1. Understand response logic - Know what controls output

  2. statusCode matters - Must be 403 to show message

  3. Quote management - Use backticks to avoid escaping

  4. Base64 encoding - Essential for complex commands

  5. Response injection - Cleaner than file-based methods

Last updated