Skip to content
Access control Write-up Advanced

ConfusedFunction: A Privilege Escalation Vulnerability Impacting GCP Cloud Functions

A privilege escalation vulnerability in Google Cloud Platform's Cloud Functions allowed an attacker with permissions to create or update a function to execute code in the Cloud Build instance used for deployment, thereby stealing the default Cloud Build service account token and escalating privileges to that account's permissions.

Liv Matan Follow

Published on tenable.com

Subscribe

Liv Matan, on tenable.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.

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 automatic attachment of a default Cloud Build service account with excessive permissions to the Cloud Build instance used for Cloud Function deployment, combined with user-controlled build steps (such as npm install scripts) that run with that service account's privileges.

Impact

An attacker with permissions to create or update a Cloud Function could escalate privileges to the default Cloud Build service account, gaining access to other GCP services such as Cloud Storage and Artifact Registry; GCP partially fixed the issue for new deployments but existing instances remain vulnerable.

What the attacker needed

Permissions to create or update a Cloud Function; Ability to publish a package to npm (for one method); Victim deploys the function

The fix

GCP added an option to use a custom service account for the Cloud Build instance and changed default behaviour for new projects, but existing Cloud Build service accounts (legacy) remain unchanged; users should replace legacy service accounts with least-privilege ones.

How it was found

  1. Create a malicious npm package with a preinstall script that exfiltrates the Cloud Build service account token from the metadata server.
  2. Publish the package to the public npm registry.
  3. Create or update a Cloud Function with an identity that has function permissions.
  4. Edit the function's package.json to include the malicious package as a dependency.
  5. Deploy the Cloud Function; the preinstall script runs during the build and sends the token to the attacker's webhook.

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.

When you create a cloud function, Google automatically runs a build process behind the scenes using a service account (a special identity for programs). That service account had more permissions than the person creating the function. An attacker who could create a function could sneak malicious code into the build process and steal the service account's credentials, gaining higher access than they should have.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by Liv Matan

View all

3 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.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.