How to contact Google SRE: Dropping a shell in Cloud SQL
A SQL injection in Cloud SQL's CSV export feature allowed writing a malicious MySQL plugin to a temporary directory, and parameter injection in mysqldump then loaded that plugin, giving a reverse shell inside a container. Because the container used host networking, the attacker could spoof metadata server responses to the Google Guest Agent and add an SSH key, escaping to the host VM.
Published on ezequiel.tech
Note: The vulnerabilities that are discussed in this post were patched quickly and properly by Google. We support responsible disclosure.
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 features failed to properly sanitise user-supplied SQL and command-line arguments, allowing SQL injection with FILE privileges and parameter injection into mysqldump.
Impact
An attacker with a Cloud SQL instance could execute code in the container and escape to the host VM, and if Private IP access was enabled, other Cloud SQL instances in the [redacted]/8 range could be targeted.
What the attacker needed
A Google Cloud account; ability to create a Cloud SQL instance; ability to import/export databases
The fix
The vulnerabilities were patched by Google.
How it was found
- Use the CSV export feature with a crafted query to write a malicious shared object to /mysql/tmp.
- Import a database containing the malicious plugin as a longblob.
- Trigger a regular export and modify the API request to pass --plugin-dir and --default-auth parameters to mysqldump.
- Catch the reverse shell from the loaded plugin.
- Use tcpdump to watch metadata requests from the Google Guest Agent.
- Spoof the metadata response with rshijack to inject an SSH key and log in to the host.
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 where users normally cannot run system commands. The researchers found that a database export feature let them sneak extra SQL commands into a query, and another export feature passed user input directly to a command-line tool. By combining these, they made the database server run their own code and eventually take over the underlying virtual machine.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.