the devstorage.read_only default scope allows read access to all storage buckets within the specified project
access scopes should not be relied on as a boundary for a service account’s permissions
when cloud-platform is specified for an instance, the service account can attempt to authenticate to all API endpoints
this authentication will be successful if the permissions of the storage account allow it
even though a service account may have permissions to access a certain API endpoint, if this endpoint is not allowed by the access scope, successful authentication cannot occur
IAM
Primitive roles
Owner, Editor, and Viewer
!!!! default service account in every project is given the Editor role (insecure!!)
Predefined roles
roles managed by Google (e.g. compute.instanceAdmin)
Custom roles
provides admins the ability to create their own set of permissions for a role
To see roles assigned to each member of a project:
gcloud projects get-iam-policy <PROJECT_ID>
Enumeration
Command
Description
gcloud organizations list
Get organization ID
gcloud organizations get-iam-policy
View user permissions within organization
note that the permissions within an organization are applied to all projects within the organization, which are therefore applied to all resources within that project, etc.
alternative to pulling a token from the metadata service
this method is used when implementing one of Google’s official GCP client libraries
The following are the steps taken to search for credentials when using the GCP client libraries:
Code will check source code
The service account key file is checked
The GOOGLE_APPLICATION_CREDENTIALS environment variable is checked
This environment variable can be set to the location of a service account key file
The default token in the metadata service is used.
the default token in the metadata service is used only if 1 or 2 is not found because the metadata service token is confined within access scopes and is temporary
Privilege Escalation
⭐ Always make sure to check if the principle of least-privilege is being applied throughout the environment
SSRF
The privesc techniques described below are written from the perspective of internal access to a compromised instance. However, they can also be performed if you find SSRF in some cases.
Insecure Metadata Endpoint
If /v1beta1 is enabled, you can get the access token without the special header:
note the authorization token expires within 1 hour by default
Compute Instances
General
just because an access scope blocks a certain command, does not mean that any variations of that command cannot be run
e.g. if gsutil ls returns no storage buckets, you may still be able to query a storage bucket by specifying the name of the bucket for example gsutil ls gs://storage_bucket_example-1234567
Enumerate scripts within the following areas:
Instance metadata
Local filesystem
Service unit files
etc.
scripts help tell what the instance is meant for and what it has access to
Modifying Instance Metadata
Default Service Account
The following access scopes are offered for default service accounts:
Allow default access (default)
Allow full access to all Cloud APIs
Set access for each API
if 3 (with compute API access) or 2 is enabled, privesc is potentially possible
Custom Service Account
Google discourages using access scopes for custom service accounts
One of the following privileges necessary for privesc:
Linux GCP systems typically run Python Linux Guest Environment within Compute Engine scripts
account daemon queries metadata for changes to authorized SSH keys, and will add a new key to an existing user or a user with sudo rights
if custom project metadata can be modified, persistence is established on all systems within the GCP project running the accounts daemonBlock project-wide SSH keys option enabled
the same process can be used (1-3), however a new username should be specified
this gives the new user sudo permissions
Sudo to Existing Session
Use the following command to generate a new SSH key, add your current username to google-sudoers group, and initiate an SSH session:
gcloud compute ssh <INSTANCE_NAME>
note this may cause more changes to the target instance’s metadata than the manual step-by-step process described above
this uses your current username
OS Login
links Google user or service account to Linux identity
IAM permissions dictate the authorization of this request
enabled at project or instance level with the metadata key of enable-oslogin = TRUE
2FA OS login enabled with enable-oslogin-2fa = TRUE
roles/compute.osLogin and roles/compute.osAdminLogin control SSH access to instances with enabled OS Login
note the former is without sudo access while the latter is with sudo access
by adding one’s SSH key to the project metadata, access to all instances can be achieved as long as the instance does not have the Block pojrect-wide SSH keys option enabled:
Check for Service Accounts with Exported Key Files
for i in $(gcloud iam service-accounts list --format="table[no-heading](email)"); do
echo Looking for keys for $i:
gcloud iam service-accounts keys list --iam-account $i
done
default name for service account key file is <PROJECT_ID>-<PORTION_OF_KEY_ID>.json
if access scopes are too restrictive, check if there is another instance that is more permissive
gcloud compute instances list --quiet
check if an instance has the default service account (PROJECT_NUMBER-compute@developer.gserviceaccount.com)
can potentially impersonate another account with the iam.serviceAccountTokenCreator permission
if you have Owner access, you can try logging into the web interface
service accounts can’t access web interface, but you can provide Editoraccess to any arbitrary @gmail.com account and then login (can’t provide Owner access)
1. Attempt to trigger a job as an unauthenticated user
2. Trigger a job as authenticated user
AI Platform
look for models and jobs
Command
Description
gcloud ai-platforms models list --format=json
Lists models
gcloud ai-platform jobs list --format=json
Lists jobs
Cloud Pub/Sub
service allowing applications to send messages between each other
Pub/Sub is made up of the following:
Topic - logical group of messages
Subscriptions - Allows applications to receive a stream of messages related to a topic, which can be enabled via push notifications (for some Google services), or pull requests (for custom services)
The second video in the GCP series in which the threat actor must leverage an SSRF vulnerability to exploit a misconfigured application. The application supports the gopher protocol which can be abused to query the metadata service.
The first video in the GCP series features a scenario where participants are provided with a URL leading to a misconfigured storage bucket serving image files, prompting them to fuzz potential files, discover a backup zip file due to the entity being set to "Public" with "allUsers" granted Reader access, and completing the challenge by decrypting the zip file.