Google Cloud Shell - Command Injection
The Google Cloud Shell terminal embedded the user-controlled 'project' parameter into a Python script without encoding, allowing an attacker to break out of a string and execute arbitrary Python code. This led to command injection and remote shell access.
Published on bugra.ninja
Hi, I’m bugra, and here is a write-up about my Google Bug Bounty report.
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
Impact
An attacker could execute arbitrary commands on the Cloud Shell instance, potentially leading to remote shell access and compromise of the environment.
What the attacker needed
Access to Google Cloud Shell
The fix
The vulnerability was fixed by properly encoding or sanitising the 'project' parameter before embedding it in the Python script.
How it was found
- Visit the Cloud Shell URL with a 'project' parameter.
- Change the 'show' parameter to 'ide' to get a different terminal view.
- Enter a value with an apostrophe in the 'project' parameter to cause a syntax error.
- Craft a value that closes the string and injects Python code, such as importing os and running a system command.
- Observe the command output in the terminal.
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 Shell is a web-based terminal for managing Google Cloud. The 'project' parameter in the URL was inserted directly into a Python script that runs in the terminal. By adding special characters, an attacker could make the script run their own commands, like reading files or opening a remote shell.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.