Skip to content
RCE Disclosed report Intermediate

Synthetics Recorder: Code injection when recording website with malicious content

The Synthetics Recorder's code generator escapes single quotes but places a user-controlled URL inside a multi-line comment, so a crafted URL can break out of the comment and inject JavaScript. When the recorded session is exported and run with the Synthetics runner, the injected code executes arbitrary commands on the machine.

dee-see Follow

Originally disclosed on HackerOne

High 8.2 View original
  • Triaged in 4 days
  • Fixed in 7 days
  • Paid in 11 days
  • Disclosed after 9 months

Summary

Hello team! Synthetics recorder has a quote function to escape user-controlled input, but in one particular scenario the escaping isn't enough and a malicious website can inject arbitrary code in the recorder session.

Description

The waitForNavigation event calls quote within the context of a multi-line comment (/* ... */) so we can break out of that without using the escaped characters (reference)

In a normal situation the code generated looks like this for a navigation event to https://example.com

JavaScript
    page.waitForNavigation(/*{ url: 'https://example.com' }*/),

but it's possible to escape out of the comment without using single quotes (which would be escaped) with a specially crafted URL like https://example.com?q=*/require(child_process).exec(touch$IFS/tmp/haxx)/*

JavaScript
    page.waitForNavigation(/*{ url: 'https://example.com?q=*/require(`child_process`).exec(`touch$IFS/tmp/dee-see`)/*' }*/),

The syntax highlighting here on HackerOne helps visualizing how that works. $IFS is used because spaces get encoded to %20.

It's possible to have code execution when the victim uses the test feature inside of the synthetic recorder but the code we're allowed to use is fairly limited because the require function isn't available. The maximum impact is when the user saves the recorded session as a project and executes it using the synthetic runner.

Steps To Reproduce

Preparation

Install the synthetics recorder (See https://github.com/elastic/synthetics-recorder/, I'm following the instructions to run it in development mode (nvm install; nvm use; npm install; npm run dev) but you could also download the binary on the releases page)

Reproduction

  1. Start Synthetics Recorder and enter http://deesee.xyz:4567 in the text box where it says "Enter a Starting URL"

  2. Click "Start Recording"

  3. A browser has opened, this website is a modified clone of my blog. Click the GitLab icon in the top right

    gl.png
    gl.png From the original on HackerOne
  4. Close the browser window

    In a normal Synthetics Recorder session there would be much more steps to record but here we only did what's necessary to trigger the issue.

  5. Click the "Export" button and you'll see this code

    JavaScript
    step('Go to http://deesee.xyz:4567/', async () => {
      await page.goto('http://deesee.xyz:4567/');
      await Promise.all([
        page.waitForNavigation(/*{ url: 'https://gitlab.com/dee-see?query=*/require(`child_process`).exec(`touch$IFS/tmp/dee-see`)/*' }*/),
        page.click('[aria-label="GitLab"] svg')
      ]);
    });
    

    We can see the payload is in place. It's fairly obvious because we only recorded one step, but in a long recording session it would be buried deeper.

  6. Click the "Export" button and save the file in a directory

  7. In that directory run npm init -y; npm install @elastic/synthetics; npx @elastic/synthetics .

  8. When the tests finished running observe that the touch /tmp/dee-see command ran

Those last steps seem contrived, but that's how a synthetics test suite is setup and how a developer would make sure the session they just recorded would be integrated into their builds and whatnot.

Supporting Material/References:

2022-07-14_00-09-26.mp4 From the original on HackerOne

CVSS

Confidentiality and Integrity impact are High because of the arbitrary command execution. I also included Availability impact because those commands can shut down the system. I will concede though that Attack Complexity could be "very high" if that existed on the Attack Complexity scale. :)

Impact

Someone with control over the website's content can run arbitrary code where ever the synthetics recorded session will be re-executed.

Developer computers and CI systems come to mind. The most realistic attack scenario would be privilege escalation from within a company.

The original report as published on HackerOne, by dee-see. 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 escaping function only handles single quotes, but the URL is embedded inside a multi-line comment, so comment-closing characters can break out of the comment and inject code.

Impact

An attacker who controls a website's content can run arbitrary commands on developer machines or CI systems wherever the recorded session is re-executed; the `test` feature inside the recorder is limited because `require` is unavailable there.

What the attacker needed

Victim records a session on attacker-controlled site; victim exports and runs the recorded session

The fix

The escaping should handle comment delimiters so URLs cannot break out of comments.

How it was found

  1. Start Synthetics Recorder and enter the malicious starting URL.
  2. Click Start Recording; a browser opens to the modified site.
  3. Click the GitLab icon on the page to trigger a navigation event.
  4. Close the browser window.
  5. Click Export to see the generated code containing the injected payload.
  6. Save the exported file, install the Synthetics runner, and run it to observe the command execution.

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.

The Synthetics Recorder is a tool that watches you browse a website and writes a script that repeats your actions. It puts the website address into that script inside a comment, which is text the computer is supposed to ignore. A malicious website can choose an address that ends the comment early and adds its own instructions, so the script runs the attacker's code when someone later plays it back.

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 dee-see

View all

9 more disclosed reports, best first.

More from Elastic

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.