Skip to content
Pwnversity
CLOUD-GCPintermediate · 5 min · upd. 2026-10

GCP Pentesting

Google Cloud Platform organizes everything around projects and uses service accounts (SA) as the identities of applications. Escalation in GCP almost always revolves around impersonating service accounts: with the right permissions you can obtain tokens of more privileged SAs and chain up to Owner of the project or organization. Understanding SAs, roles, and the hierarchy (organization → folder → project → resource) is the key.

The attacker gets in with a Google user, a leaked service account JSON (direct access), or a token stolen from a VM’s metadata. From there, the goal is impersonation: use permissions like iam.serviceAccounts.getAccessToken or actAs to obtain tokens of more privileged SAs and escalate to Owner. Permissions are inherited downward through the hierarchy, so a broad role at the organization or folder level propagates to every project beneath it.

flowchart TD
    A[User / SA JSON / VM token] --> B[Enumerate IAM policies]
    B --> C{Impersonation permissions?}
    C -->|getAccessToken / actAs| D[Privileged SA token]
    C -->|setIamPolicy| E[Grant yourself Owner]
    D --> F[Create resource running as admin SA]
    F --> G[Project Owner]
    E --> G
    G --> H[Organization Owner]
  • Hierarchy: Organization → Folders → Projects → Resources. Permissions are inherited downward.
  • Identities: Google users, groups, and service accounts (SA: identity of apps and VMs).
  • Roles: primitive (Owner/Editor/Viewer, very broad), predefined (scoped per service), and custom.
Ventana de terminal
# ways in
gcloud auth login # user
gcloud auth activate-service-account --key-file=sa.json # SA (leaked JSON = access)
# a leaked service account JSON (see recon-code) is direct access
# SA token from a VM (see cloud-metadata)
Ventana de terminal
gcloud auth list ; gcloud config list
gcloud projects list
gcloud projects get-iam-policy <project-id>
gcloud iam service-accounts list --project <project-id>
# tools
# gcp_scanner, GCPBucketBrute, Hayat, ScoutSuite (supports GCP)
Ventana de terminal
# if you hold iam.serviceAccounts.getAccessToken over an SA -> you get its token
gcloud auth print-access-token \
--impersonate-service-account=<SA>@<project>.iam.gserviceaccount.com
# iam.serviceAccountKeys.create -> create a key for an SA (persistence/access)
gcloud iam service-accounts keys create k.json \
--iam-account=<SA>@<project>.iam.gserviceaccount.com

If the target SA is more privileged (Editor/Owner), you impersonate it and escalate. With iam.serviceAccounts.actAs + creating a resource (function/VM/job) that runs as that SA, you execute code with its permissions.

  • resourcemanager.projects.setIamPolicy → grant yourself project Owner.
  • iam.serviceAccounts.getAccessToken / actAs → impersonate a privileged SA.
  • iam.serviceAccountKeys.create → SA key (persistent access).
  • cloudfunctions.functions.create + actAs → function running as an admin SA (see Serverless Security).
Ventana de terminal
# Cloud Storage (see cloud-s3)
gsutil ls ; gsutil ls gs://<bucket> # public/readable buckets
# Compute Engine: project metadata (SSH keys, startup scripts)
gcloud compute instances list
gcloud compute project-info describe # sometimes credentials in metadata
# Secret Manager
gcloud secrets list
gcloud secrets versions access latest --secret=<name>
  • Least privilege: avoid broad primitive roles (Owner/Editor); use scoped predefined roles.
  • Control impersonation: restrict iam.serviceAccounts.getAccessToken/actAs; disable SA key creation with the Organization Policy iam.disableServiceAccountKeyCreation.
  • SAs without static keys: use Workload Identity; never expose a service account JSON.
  • Organization Policies to constrain (domain-restricted sharing, no SA keys, no public IPs).
  • Cloud Audit Logs (Admin Activity + Data Access) + Security Command Center; alerts on setIamPolicy and serviceAccountKeys.create.
  • Access (user / SA JSON / VM token) and enumeration (gcloud)
  • IAM policy of projects and SAs (inherited roles)
  • Impersonate SAs (getAccessToken/actAs) toward more privilege
  • serviceAccountKeys.create (access/persistence)
  • setIamPolicy → project Owner
  • Public GCS buckets (Buckets and Public Storage), Compute metadata (keys)
  • Secret Manager and functions with a privileged SA (Serverless Security)
  • Map up to project/organization Owner