Stealing Accesses tokens from Cloud Functions in GCP
A Cloud Function's IAM policy was misconfigured to allow all users to invoke it, and the function's code returned an access token for its attached service account. An attacker with a low-privileged service account could invoke the function and obtain a token for a more privileged service account, enabling lateral movement.
Published on infosecwriteups.com
How Attackers Leverage Serverless Functions to Escalate Privileges and Move Laterally
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 Cloud Function's IAM policy granted the invoker role to all users, and the function's code returned its service account's access token to any caller.
Impact
The attacker could obtain a valid access token for a different service account, potentially enabling lateral movement to other resources within the GCP environment.
What the attacker needed
Access to a low-privileged GCP service account; a Cloud Function with allUsers invoker permission; function code that returns an access token
The fix
IAM policies should be reconfigured to remove allUsers and allAuthenticatedUsers from function invocation permissions, and function code should not expose access tokens.
How it was found
- Authenticate to GCP using the compromised service account's JSON key file.
- Enumerate project IAM policies and identify the custom role assigned to the service account.
- Describe the custom role to see its permissions.
- List available Cloud Functions and describe each one to find its URL and attached service account.
- Check each function's IAM policy and find one that allows all users to invoke it.
- Send a POST request to the function's URL and receive an access token in the response.
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.
In cloud computing, a service account is like a robot user that programs use to talk to other services. An access token is a temporary password that proves which service account is making a request. Here, a small program (a cloud function) was set up so that anyone could run it, and when run it handed back a token for a different, more powerful robot user. That let the attacker act as that more powerful account.
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.