Skip to content
Leaked secrets Write-up Beginner

Gaining Access To GCP Of Google Stadia — 500$ Bounty

A Google Cloud service account key was exposed in a public GitHub repository, allowing the researcher to authenticate and access Google Stadia's cloud resources, including many storage buckets and BigQuery datasets. The researcher could list and potentially read production data.

Sebastien Kaul Follow

Published on medium.com

Bounty$500 View original

Sebastien Kaul

Sebastien Kaul, on 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. 6 min read.

Context

This is a story about finding an exposed Google Cloud service account and using it to reach the Google Cloud Platform (GCP) environment behind Google Stadia. The work took place in July 2019, and the report was published later. The entry point was an exposed credential found through GitHub search. The researcher's approach was to hunt for such credentials through OSINT rather than to look for server-side request forgery (SSRF) in a single application.

The technique that inspired the hunt is the one described in disclosed SSRF reports: reach the internal metadata endpoint, retrieve a service account token, and then use the exfiltrated service account or token to authenticate from outside. Instead of searching for SSRF in one target, the researcher decided to search the wider internet for credentials that were already exposed.

At the time, as far as the researcher remembers, GitHub was not scanning for exposed tokens, so encountering exposed credentials was painless.

Setup

The researcher used the Google Cloud command-line interface (gcloud) together with a small enumeration script, and mentions ScoutSuite from NCC Group as an alternative. The exposed credential in this case was a service account token written inside a dot YAML file used in a DevOps automation tool. The report does not name the tool or the repository.

The workflow assumes the following preconditions:

  1. A Google service account key is publicly reachable, for example in a GitHub repository.
  2. The key can be placed into a JSON file so that gcloud can consume it.
  3. The project id can be read from that JSON file.
  4. The service account has permissions in GCP that are worth enumerating.

Finding it

The first problem was how to find service accounts at all. The researcher's method is to identify a unique string in the target that narrows down search results. For AWS, long-term IAM access key ids begin with AKIA and temporary credentials with ASIA. Google service accounts were unfamiliar, so the researcher looked up their structure to find a similar needle.

According to the Google Cloud documentation on creating and managing service account keys, all service-account-email values end with iam.gserviceaccount.com. Searching GitHub with that string greatly improved the quality of results. Because a service account is often stored as a JSON structure, it is plausible that a GitHub user exposes one in a dot JSON file, so the query can be narrowed further:

Text
iam.gserviceaccount.com extension:json

A service account can of course be stored in other file formats too. In this case the token was inside a dot YAML file used by a DevOps automation tool.

Exploitation

At this point the owner of the service account was still unclear, and the researcher needed a way to identify it. The report notes that it would be helpful if AWS or another credential issuer allowed security researchers to look up the owner of a credential, while acknowledging the privacy implications. No such lookup was available, so the approach was to list all Google cloud resources and then associate the data with a company. The researcher found no easier way than that.

Step 1: Revoke previous tokens

Start by revoking any previous access tokens from the local environment, so that older findings do not interfere:

Bash
➜ gcloud auth revoke --all

Step 2: Activate the exposed service account

Copy the exposed service account into a JSON file (assuming the origin service account is also JSON, otherwise some adjustment is needed) and tell gcloud to use it:

Bash
➜ gcloud auth activate-service-account --key-file service-account.json

Step 3: Set the project

gcloud needs to know the project id, which can be retrieved from the JSON file:

Bash
➜ gcloud config set project your-project-name

With that, the command-line interface can communicate with Google Cloud.

Step 4: Enumerate resources

Rather than querying every Google cloud resource manually, the researcher used a script, changing the project id on line 4:

Text
https://gist.github.com/carnal0wnage/[redacted]

ScoutSuite from NCC Group is mentioned as another option that might give even better results, but the script allows a quicker overview in the researcher's opinion.

The service account might have access to other projects, so it is worth listing all accessible projects with gcloud projects list and checking each project for information.

To make the dumped information easier to review in a code editor, pipe the output into a file:

Bash
➜ bash gcp_enum.sh >> out.txt
The first 48 lines of the output. From the original on medium.com

The first 48 lines of the output.

From the original on medium.com

The output was large: 109,818 lines, of which 108,466 lines were buckets. Many buckets were boring because they were suffixed buckets, perhaps versioned buckets for log files.

108,150 buckets were suffixed buckets. The other 316 buckets had interesting names, containing words such as backup, prod, automation, jenkins, stadia plus backups, logs, gpg, ssh, deployments, scripts, dumps and more.

Access was not limited to these buckets: the service account also had access to BigQuery and other cloud resources.

Stadia Analytics Dataset in BigQuery.

Root cause

The mistake was on the credential owner's side: a Google service account token was exposed inside a dot YAML file used by a DevOps automation tool. The report does not describe the repository or the file. At the time, as far as the researcher remembers, GitHub was not scanning for exposed tokens, and the credential could be found with a simple search for the iam.gserviceaccount.com string. The service account had access to buckets, BigQuery and other resources, so possession of the key was enough to enumerate them.

Impact

The researcher gained access to buckets whose names contained words such as backup, prod, automation, jenkins, stadia, backups, logs, gpg, ssh, deployments, scripts and dumps, as well as to BigQuery, including the Stadia Analytics Dataset, and other cloud resources. The report does not enumerate what was inside those buckets or datasets beyond the names. The researcher expected that access to production data would earn a large reward, but Google paid a bounty of 500 USD.

Fix

The measure implied by the finding is to remove the exposed service account key from the public repository and rotate it, and to rely on secret scanning so that committed tokens are detected.

Variants to test

  1. Search GitHub for the service account email suffix, optionally narrowed by file extension, for example iam.gserviceaccount.com extension:json. A positive result is a file containing a service account key or token.
  2. Look beyond JSON: the credential in this case was in a dot YAML file used by a DevOps automation tool, so search YAML and other configuration formats for the same suffix. A positive result is a key embedded in a pipeline or automation configuration.
  3. After activating a found key, run gcloud projects list to check whether the account reaches other projects. A positive result is more than one accessible project.
  4. Enumerate resources with the script or with ScoutSuite and review bucket names for words such as backup, prod, automation, jenkins, logs, gpg, ssh, deployments, scripts and dumps. A positive result is readable buckets with those names.
  5. Check BigQuery and other resource types, not only storage buckets. A positive result is access to datasets such as analytics data.

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. 10 min read.

What happened, in plain words

A security researcher found an exposed service account token through a GitHub search. That file let him authenticate to Google Cloud with the service account, which had access to resources including Stadia data. Once inside, he could list a very large number of buckets and reach BigQuery and other resources. He reported it to Google, and Google paid him 500 US dollars for the finding.

The work happened in July 2019. The report was published later. The important thing to understand is that the researcher did not break into a website. He found a key that someone had left lying around, and the key still worked.

Introduction

Before this, the researcher had only read other people's bug bounty write-ups. A bug bounty is a programme where a company pays people for reporting security problems. This was his first attempt at writing one up himself.

He had been reading public reports about a technique. In those reports, an attacker makes a company's own server fetch a web address that the attacker chooses. That address points at a special internal page that only the server can reach, called the metadata endpoint. That page hands out a token, a digital pass. The attacker then uses that pass from outside to log in to the company's cloud account.

This gave him an idea. Instead of hunting for that kind of flaw inside one website, he would search the open internet for cloud passes that people had already published by accident. Searching public sources for information like this is called OSINT, short for open-source intelligence: finding things out from material anyone can see.

At the time, as far as he remembers, GitHub, the popular site where people store and share code, was not automatically scanning for leaked passes. So finding them was easy.

Finding a search query

The first problem was how to find these passes at all. His method is to pick a unique piece of text that appears in the thing he is looking for, and search for that. A good needle makes the search results much more precise, the way searching for a rare surname finds the right family faster than searching for "John".

For Amazon's cloud, long-term access key ids start with AKIA and temporary ones with ASIA. Those prefixes are the needle. Google's service accounts were unfamiliar to him, so he read Google's documentation to learn what they look like.

The documentation page he used is about creating and managing service account keys. From it he learned that every service account email address ends with iam.gserviceaccount.com. That suffix became his needle.

Searching GitHub for that string made the results much better. But there was still room to improve. A service account is often stored as a JSON file, which is a plain-text format for structured data. So it is easy to imagine someone publishing their service account in a file ending in .json. The search can then be narrowed to that file type:

Text
iam.gserviceaccount.com extension:json

Line by line: iam.gserviceaccount.com is the text that must appear in the file. extension:json tells the search engine to return only files whose name ends in .json. Together they ask for JSON files that mention a Google service account address.

Of course a service account can be stored in other file formats too. In his case, the pass was written inside a file ending in .yaml, another plain-text format often used for configuration. That file was used by a DevOps automation tool, meaning software that automates the steps of building and releasing programs.

Using the Google Cloud Service Account

At this point he still did not know who owned the service account. He needed a way to find out. He notes that it would be great if Amazon or any other company that issues cloud passes let security researchers look up who a pass belongs to. He accepts there would be privacy concerns, but it would help in cases like this.

No such lookup existed, so his approach was to list every resource in the Google cloud account and then work out from the names which company it belonged to. He found no easier way.

To do this he used the Google Cloud command-line interface, usually shortened to gcloud. A command-line interface is a program where you type instructions as text instead of clicking buttons. He also used a small script, which is a file containing a list of commands to run automatically.

Step 1: Revoke previous tokens

First he cleared out any passes left over from earlier work on his own machine, so that old findings would not get mixed up with the new one:

Bash
➜ gcloud auth revoke --all

gcloud is the program being run. auth selects the group of commands about logging in and identity. revoke means cancel. --all means every stored pass, not just one. The ➜ is just the symbol his terminal shows before a command; you do not type it.

Step 2: Activate the exposed service account

Next he copied the leaked service account into a JSON file, assuming the original was also in JSON format; otherwise some fiddling is needed. Then he told gcloud to log in with it:

Bash
➜ gcloud auth activate-service-account --key-file service-account.json

activate-service-account tells gcloud to start using a service account, which is a non-human account meant for software rather than a person. --key-file service-account.json points at the file holding the key, the secret that proves the account's identity. Think of a service account as a robot employee and the key file as its ID badge.

Step 3: Set the project

gcloud needs to know which project to work in. A project is a container inside Google Cloud that groups resources together, a bit like a folder. The project id can be read from the JSON file:

Bash
➜ gcloud config set project your-project-name

config set changes a setting. project your-project-name sets the current project to the name you supply; your-project-name is a placeholder for the real id.

With that done, the command-line tool can talk to Google Cloud.

Step 4: Enumerate resources

Rather than asking for every kind of cloud resource by hand, he used a ready-made script. He had to change the project id on line 4 of it:

Text
https://gist.github.com/carnal0wnage/[redacted]

A gist is a small public snippet of code hosted on GitHub. The link is where the script lives; the only edit needed is the project id on line 4.

He also mentions ScoutSuite from NCC Group as another option. It might give even better results, but in his opinion the script gives a quicker overview.

The service account might have access to other projects as well, so it is worth listing all of them with gcloud projects list and checking each one for information.

To make the dumped information easier to read in a code editor, he sent the output into a file:

Bash
➜ bash gcp_enum.sh >> out.txt

bash is the program that runs the script. gcp_enum.sh is the script file; enum is short for enumerate, meaning list everything. >> means append the output to a file rather than print it on screen. out.txt is the file that receives it. The result is a text file you can open and scroll through.

The first 48 lines of the output. From the original on medium.com

The first 48 lines of that output.

From the original on medium.com

The output was enormous: 109,818 lines, of which 108,466 were buckets. A bucket is cloud storage space for files, like a folder in an online drive. Many buckets were uninteresting because their names had a suffix added, perhaps versioned buckets kept for log files. Versioned means old copies of files are kept each time they change.

108,150 of the buckets were these suffixed ones. The other 316 had interesting names, containing words such as backup, prod, automation, jenkins, stadia plus backups, logs, gpg, ssh, deployments, scripts, dumps and more. Prod is short for production, the live system real users see. Jenkins is a tool that automates building software. GPG and SSH are tools that use encryption keys, so buckets named after them may hold secrets.

He did not only have access to these buckets. He also had access to BigQuery, Google's service for analysing very large datasets, and to other cloud resources.

One dataset he could see was the Stadia Analytics Dataset in BigQuery.

At that point he was very happy. He thought access to production data would earn him a large reward. Google paid him 500 US dollars.

Root cause

The mistake was on the side of whoever owned the pass. A Google service account token had been exposed inside a .yaml file used by a DevOps automation tool. The report does not describe the repository or the file. At the time, as far as he remembers, GitHub was not scanning for leaked passes, and the key could be found with a simple search for the iam.gserviceaccount.com string. The service account itself had access to buckets, BigQuery and other resources, so simply holding the key was enough to list them.

Impact

He gained access to buckets whose names contained words such as backup, prod, automation, jenkins, stadia, backups, logs, gpg, ssh, deployments, scripts and dumps. He also reached BigQuery, including the Stadia Analytics Dataset, and other cloud resources. The report does not say what was inside those buckets or datasets beyond their names. He expected a large reward for access to production data; Google paid 500 US dollars.

Fix

The measure the finding implies is to remove the exposed key from the public repository and replace it with a new one, which is called rotating the key, and to use secret scanning so that committed passes are detected automatically.

Variants to test

  1. Search GitHub for the service account email suffix, optionally narrowed by file extension, for example iam.gserviceaccount.com extension:json. A positive result is a file containing a service account key or pass.
  2. Look beyond JSON: the pass in this case was in a .yaml file used by a DevOps automation tool, so search YAML and other configuration formats for the same suffix. A positive result is a key embedded in a pipeline or automation configuration.
  3. After activating a found key, run gcloud projects list to check whether the account reaches other projects. A positive result is more than one accessible project.
  4. List resources with the script or with ScoutSuite and review bucket names for words such as backup, prod, automation, jenkins, logs, gpg, ssh, deployments, scripts and dumps. A positive result is readable buckets with those names.
  5. Check BigQuery and other resource types, not only storage buckets. A positive result is access to datasets such as analytics data.

Glossary

  • Bug bounty: a programme where a company pays people for reporting security problems to it.
  • SSRF (server-side request forgery): a flaw where an attacker makes a company's server send a request to an address the attacker chooses.
  • Metadata endpoint: a special internal web address that a cloud server can reach and that hands out information and passes about that server.
  • Token: a digital pass that proves who you are, usually short-lived.
  • Service account: a non-human account used by software rather than a person.
  • Service account key: the secret file that proves a service account's identity, like an ID badge.
  • OSINT (open-source intelligence): finding information from material anyone can see, such as public websites and code.
  • GitHub: a website where people store and share code, often publicly.
  • Repository: a project's collection of files stored on a code hosting site.
  • Commit: to save a change permanently into a repository.
  • JSON: a plain-text format for structured data, using curly braces and key-value pairs.
  • YAML: a plain-text format for configuration data, using indentation and colons.
  • DevOps automation tool: software that automates the steps of building, testing and releasing programs.
  • gcloud: Google's command-line program for managing Google Cloud.
  • Command-line interface: a program you control by typing text commands instead of clicking buttons.
  • Script: a file containing a list of commands that run automatically.
  • Project: a container inside Google Cloud that groups resources together, like a folder.
  • Project id: the unique name that identifies a project.
  • Bucket: cloud storage space for files, like a folder in an online drive.
  • BigQuery: Google's service for storing and analysing very large datasets.
  • Dataset: an organised collection of data, like a set of tables.
  • Enumeration: listing everything that exists in a system.
  • Gist: a small public snippet of code hosted on GitHub.
  • ScoutSuite: a tool from NCC Group that collects and reviews cloud configuration data.
  • Prod (production): the live system that real users see.
  • Jenkins: a tool that automates building and testing software.
  • GPG: a tool for encrypting and signing data with keys.
  • SSH: a tool for logging in to other computers securely, using keys.
  • Versioned bucket: a bucket that keeps old copies of files each time they change.
  • Secret scanning: automatic checking of code repositories for leaked passes and keys.
  • Rotating a key: replacing a secret with a new one so the old one stops working.

More from Google

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Leaked secrets and credentials

The lesson behind this report.

Keys, tokens or passwords left in public code, apps, logs or responses, that grant real access.