Skip to content
RCE Write-up Advanced

Elevating privileges

The Cloud SQL export feature allowed SQL injection with FILE privileges and parameter injection into mysqldump, enabling an attacker to write a malicious plugin and execute it to gain a reverse shell inside a container. The container used host networking, allowing the attacker to spoof metadata server responses and add an SSH key to the host, escaping to the underlying VM.

Ezequiel Pereira Follow

Published on offensi.com

Google Cloud SQL is a fully managed relational database service. Customers can deploy a SQL, PostgreSQL or MySQL server which is secured, monitored and updated by Google.

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.

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

How it worked

Root cause

Likely the export feature failed to sanitise user-supplied SQL queries and mysqldump parameters, allowing injection and arbitrary plugin loading.

Impact

An attacker could execute arbitrary code in the Cloud SQL container and, due to host networking, potentially escape to the underlying VM and compromise other instances.

What the attacker needed

Access to Cloud SQL export feature; ability to import a database; ability to intercept API requests

The fix

The vulnerabilities were patched by Google.

How it was found

  1. Use the CSV export feature with a custom query to perform SQL injection and write a file to /mysql/tmp.
  2. Create a malicious database containing a shared object that spawns a reverse shell.
  3. Import the malicious database into Cloud SQL.
  4. Use the CSV export to write the shared object to /mysql/tmp.
  5. Trigger a regular export and modify the API request to pass --plugin-dir and --default-auth parameters to mysqldump.
  6. The plugin executes, giving a reverse shell inside a container.

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 write-up has not been written yet. The Original tab links to the source.

Cloud SQL is a managed database service. The export feature let users run custom SQL queries, but it did not properly sanitise them, so an attacker could run their own commands. Also, the tool used for exporting (mysqldump) accepted extra options from user input, letting the attacker load a malicious plugin and run code on the server.

What is RCE?

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

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.