Google Cloud SDK (gcloud) Cheat Sheet
GCP command-line tool for project enumeration, IAM review, compute instances, and storage access testing.
Overview
gcloud is the primary CLI for Google Cloud Platform. Use for listing projects, service accounts, GCS buckets, GCE metadata tokens, and IAM policies during cloud assessments.
Authorized testing only. Use only on systems, networks, and accounts you own or have explicit written permission to test. Unauthorized access is illegal.
Install
Debian
sudo apt install -y apt-transport-https ca-certificates gnupgecho "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee /etc/apt/sources.list.d/google-cloud-sdk.listcurl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/cloud.google.gpgsudo apt update && sudo apt install -y google-cloud-cligcloud initgcloud auth loginEssential commands
Active identity
gcloud auth listgcloud config listProjects
gcloud projects listSet project
gcloud config set project PROJECT_IDCommon workflows
From compromised VM
curl -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/tokencurl -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/project/project-idexport CLOUDSDK_CORE_PROJECT=$(curl -s -H "Metadata-Flavor: Google"http://metadata.google.internal/computeMetadata/v1/project/project-id)GCS enumeration —
gsutil lsgsutil ls gs://bucket-name/gsutil cp gs://bucket-name/secret.txt .gsutil iam get gs://bucket-nameIAM / service accounts —
gcloud iam service-accounts listgcloud projects get-iam-policy PROJECT_IDgcloud iam roles describe roles/ownergcloud iam service-accounts keys list --iam-account SA@PROJECT.iam.gserviceaccount.comCompute instances —
gcloud compute instances listgcloud compute ssh INSTANCE --zone us-central1-agcloud compute instances describe INSTANCE --zone us-central1-aOrg-wide (if permitted) —
gcloud organizations listgcloud resource-manager folders list --organization ORG_IDgcloud asset search-all-resources --scope=projects/PROJECT_IDFlags reference
--project PROJECT_ID | Override project |
|---|---|
--format json | Machine-readable output |
--filter EXPRESSION | List filtering |
gcloud auth activate-service-account | Use JSON key file |
bq / gsutil | BigQuery / Storage CLIs bundled |
gcloud components install | Extra tools (kubectl, etc.) |
Tips
- Default SA on GCE often has broad scopes — check token scopes in metadata.
- Public GCS: gsutil ls gs://bucket without auth sometimes works.
- Use ScoutSuite / custom scripts for report-style misconfig after manual triage.
- Service account key JSON: gcloud auth activate-service-account --key-file=key.json.