Skip to content
RCE Disclosed report Intermediate

RCE in 'Copy as Node Request' BApp via code injection

The Copy as Node Request Burp extension failed to escape single quotes when generating Node.js code from a request's cookie header. An attacker could place crafted content in a cookie so that, once the user copies the request as Node.js code and runs it, arbitrary Node.js code executes on their machine.

ryotak Follow

Originally disclosed on HackerOne

Informational View original
  • Triaged in 29 hours
  • Fixed in 2 days
  • Disclosed after 4 days

Description

Copy as Node Request is a burp suite extension that allows users to copy requests as Node.js code. Due to improper sanitization of cookie, it's possible to inject arbitrary Node.js code in copied text, which may lead remote code execution with a significant amount of user interaction.

Root cause

This extension has a function named escapeQuotes. While this function escapes double quotes, it doesn't escape single quotes. https://github.com/PortSwigger/copy-as-node-request/blob/b34456463310836e93365541189626909adc70bb/src/burp/BurpExtender.java#L165-L167 As the cookie field of generated codes use single quote, it's possible to escape string literal and inject arbitrary Node.js codes. https://github.com/PortSwigger/copy-as-node-request/blob/b34456463310836e93365541189626909adc70bb/src/burp/BurpExtender.java#L123-L125

Step to reproduce

  1. Install Copy as Node Request extension.
  2. Open https://example.com
  3. Open DevTools and type document.cookie = "test='/require('child_process').exec('calc.exe')//"
  4. Enable intercept and reload the browser tab.
  5. Right click on intercepted request and click Copy as Node.js Request.
  6. Execute copied text in Node.js.
  7. calc.exe will be popped up.
2021-04-18_12-36-32.mp4 From the original on HackerOne

Impact

Remote code execution via Node.js code injection with user interaction.

The original report as published on HackerOne, by ryotak. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The escapeQuotes function escaped double quotes but not single quotes, while the generated cookie code used single-quoted string literals, allowing string breakout and code injection.

Impact

An attacker could achieve remote code execution on the user's machine, but only with a significant amount of user interaction: the victim must copy the request as Node.js code and then run it.

What the attacker needed

Burp Suite with the extension installed; Victim sets a crafted cookie; Victim copies request as Node.js code; Victim runs the copied code

How it was found

  1. Install the Copy as Node Request extension in Burp Suite.
  2. Open a website in the browser.
  3. Set a crafted cookie value through the browser's developer console.
  4. Enable interception and reload the page.
  5. Right-click the intercepted request and choose Copy as Node.js Request.
  6. Run the copied code in Node.js, which executes the injected command.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This is a tool that turns a captured web request into ready-to-run Node.js code. The tool put the cookie value into the generated code without properly escaping a quote character, so a malicious cookie could break out of the text and add its own code. If the user then ran the copied code, that extra code would run on their computer.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by ryotak

View all

23 more disclosed reports, best first.

More from PortSwigger Web Security

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.