Command Execution

Overview

With code injection confirmed, maximize exploitation by achieving Remote Code Execution (RCE).


Current Progress

#
Step
Status

1-7

Previous steps

βœ…

8

Reach command execution or file writing

⏳

9

Blindly verify command execution/file writing

⏳

10

Automate exploitation (write exploit)

⏳


Node.js Command Execution

Basic One-liner

require("child_process").execSync("touch pwned");

Integrate into Payload

{
  "text": "'}) + require('child_process').execSync('touch pwned')//"
}

Test Locally

Result: File created! βœ… Command execution achieved!

Note: If require doesn't work (e.g., "type": "module" in package.json), find alternative or use already imported packages.


Obtaining Command Output

Challenge

Code output only visible in backend console - need remote access to output.

Options Analysis

Method
Feasibility

Console log

❌ Local only

Reverse shell

❌ Outbound blocked

HTTP exfiltration

❌ No internet

DNS exfiltration

❌ No internet

Database storage

❌ No database

File write + read

⚠️ Possible

HTTP response injection

⚠️ Possible

Boolean/timing

⚠️ Last resort


Method 1: Console Logging (Local Only)

Payload:

Output (in debug console):

βœ… Works locally, ❌ not for production


Method 2: File Write + Read

Requirements

  1. Writable directory

  2. Way to read file publicly

Options for Reading

Option
Description

Public directory

Write to ./public/

File read vuln

LFI, XXE, SQLi

Overwrite function

Replace route handler

Add new route

Inject middleware into app.js

This Application

  • No public directory in app.js

  • No file read vulnerability found

  • No database


Method 3: Inject Webshell into app.js

Target Code

Challenge

Must place route before 404 middleware, otherwise treated as 404.


Exploitation Steps

Step 1: Get Admin Token

Step 2: Create Webshell File

Base64 encode the webshell:

Output:

Write to file via command injection:

Step 3: Inject into app.js

Command to inject before 404 middleware:

Base64 encode:

Output:

Execute via command injection:

Step 4: Use Webshell

Or visit in browser:


Complete Attack Chain


Why Base64 Encoding?

Problems with Direct Commands

  • Quotes break JSON

  • Special characters need escaping

  • Complex commands hard to format

Solution

  • Avoids escaping issues

  • Works with any command complexity

  • Reliable execution


Key Takeaways

  1. Code injection β†’ RCE - Natural escalation path

  2. Output exfiltration - Multiple methods, try each

  3. Base64 encoding - Solves escaping problems

  4. sed injection - Powerful for modifying files

  5. Placement matters - Routes must be before 404 handler

  6. Test environment - Auto-reload makes injection easier


Next Steps

  • Explore HTTP response injection

  • Automate with exploit script

  • Test on production target

Last updated