GCP - Compute Post Exploitation
Last updated
Last updated
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
For more information about Compute and VPC (Networking) check:
GCP - Compute EnumThis would allow an attacker to access the data contained inside already existing images or create new images of running VMs and access their data without having access to the running VM.
It's possible to export a VM image to a bucket and then download it and mount it locally with the command:
Fore performing this action the attacker might need privileges over the storage bucket and for sure privileges over cloudbuild as it's the service which is going to be asked to perform the export
Moreover, for this to work the codebuild SA and the compute SA needs privileged permissions.
The cloudbuild SA <project-id>@cloudbuild.gserviceaccount.com
needs:
roles/iam.serviceAccountTokenCreator
roles/compute.admin
roles/iam.serviceAccountUser
And the SA <project-id>-compute@developer.gserviceaccount.com
needs:
oles/compute.storageAdmin
roles/storage.objectAdmin
It's not possible to directly export snapshots and disks, but it's possible to transform a snapshot in a disk, a disk in an image and following the previous section, export that image to inspect it locally
With the goal of accessing the data stored in an image or inside a running VM from where an attacker has created an image, it possible to grant an external account access over the image:
and then create a new VM from it:
If you could not give your external account access over image, you could launch a VM using that image in the victims project and make the metadata execute a reverse shell to access the image adding the param:
With the goal of accessing the data stored in a disk or a snapshot, you could transform the snapshot into a disk, a disk into an image and follow th preivous steps.
Or you could grant an external account access over the disk (if the starting point is a snapshot give access over the snapshot or create a disk from it):
Attach the disk to an instance:
Mount the disk inside the VM:
SSH into the VM:
Identify the Disk: Once inside the VM, identify the new disk by listing the disk devices. Typically, you can find it as /dev/sdb
, /dev/sdc
, etc.
Format and Mount the Disk (if it's a new or raw disk):
Create a mount point:
Mount the disk:
If you cannot give access to a external project to the snapshot or disk, you might need to perform these actions inside an instance in the same project as the snapshot/disk.
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)