PIVTR-D
RGoogle Cloud playbook · Compute and containers

Compromised Compute Engine instance

The attacker runs code on a Compute Engine instance, takes the attached service account's token from the metadata server, installs miners or backdoors, and moves to other instances. Google Cloud Threat Horizons H1 2026 found software vulnerabilities to be the most common initial access vector in the cloud incidents it tracked, at 44.5%, ahead of weak credentials. Memory carries evidence that a stop erases, so capture first and isolate second.

Look here

LogSearch for
Security Command Center (Virtual Machine Threat Detection)Findings from memory scans by the hypervisor, with no agent on the instance. Needs the Premium or Enterprise tier: Execution: Cryptocurrency Mining Hash Match Execution: Cryptocurrency Mining YARA Rule Execution: Cryptocurrency Mining Combined Detection Defense Evasion: Rootkit, Defense Evasion: Unexpected kernel modules Defense Evasion: Unexpected system call handler
Load balancer and Cloud Armor logs (only where backend service logging was enabled)Exploit requests to the service in front of the instance: gcloud logging read 'resource.type="http_load_balancer" AND httpRequest.requestUrl:"<path>"' --project=<project> --freshness=30d
Same log entriesWeb application firewall (WAF) rule matches on those requests: jsonPayload.enforcedSecurityPolicy.outcome, jsonPayload.enforcedSecurityPolicy.preconfiguredExprIds
Security Command Center (Vulnerability Assessment for Google Cloud)Known vulnerabilities on the instance: OS vulnerability and Software vulnerability findings from agentless scans of cloned disks. Scans run about every 12 hours on Premium and Enterprise, and weekly on Standard, where it must be enabled
Admin Activity audit log, Compute EngineChanges to the instance and project. The match ignores case: gcloud logging read 'protoPayload.serviceName="compute.googleapis.com" AND (protoPayload.methodName:"instances.setMetadata" OR protoPayload.methodName:"instances.setServiceAccount" OR protoPayload.methodName:"instances.setTags" OR protoPayload.methodName:"projects.setCommonInstanceMetadata" OR protoPayload.methodName:"instances.insert")' --project=<project> --freshness=30d
Admin Activity audit log, firewallNew rules that open SSH, RDP or other ports to 0.0.0.0/0: protoPayload.methodName:"firewalls.insert" OR protoPayload.methodName:"firewalls.patch"
OS Login and SSHWho signed in over SSH. With OS Login on, SSH access is granted to Google identities through IAM roles. Without it, SSH keys come from instance or project metadata, and the guest's own /var/log/auth.log or the Windows Security log is the record of who signed in
VPC Flow Logs (only if enabled before the incident)Connections to unusual destinations, scans of other internal addresses, and outbound traffic to mining pools. Filter compute.googleapis.com/vpc_flows by source: jsonPayload.connection.src_ip="<instance-ip>"
Data Access audit log, IAM Service Account CredentialsUse of the instance's service account from another address, where iamcredentials.googleapis.com Data Access logs were enabled. See stolen workload credentials
Instance configurationThe service account and scopes, network interfaces and external IP, metadata items (startup scripts and SSH keys), attached disks, and Shielded VM options. Record them: gcloud compute instances describe <instance> --zone=<zone> --format=json

Contain

#Item
1Record the instance configuration, then set deletion protection: gcloud compute instances update <instance> --zone=<zone> --deletion-protection
2Keep each disk if the instance is deleted: gcloud compute instances set-disk-auto-delete <instance> --zone=<zone> --no-auto-delete --disk=<disk>
3Capture volatile evidence from the running instance while access still works: process list, network connections and a memory image, using your forensic tooling. Stopping the instance clears memory
4Snapshot every attached disk. A snapshot works on a running instance: gcloud compute disks snapshot <disk> --snapshot-names=<case>-<disk> --zone=<zone> --storage-location=<location>
5Tag the instance for quarantine: gcloud compute instances add-tags <instance> --zone=<zone> --tags=quarantine
6Deny all inbound traffic to the tag at the highest priority: gcloud compute firewall-rules create quarantine-deny-in --network=<network> --direction=INGRESS --action=DENY --rules=all --priority=0 --target-tags=quarantine
7Deny all outbound traffic from the tag at the highest priority: gcloud compute firewall-rules create quarantine-deny-out --network=<network> --direction=EGRESS --action=DENY --rules=all --priority=0 --target-tags=quarantine --destination-ranges=0.0.0.0/0
8Remove the external address if the deny rules are not enough: gcloud compute instances delete-access-config <instance> --zone=<zone> --access-config-name="External NAT"
9Block the exploit path in Cloud Armor while the patch is prepared. For a service outside the load balancer, deny the port in a VPC firewall rule. The expression can also be a preconfigured rule such as evaluatePreconfiguredWaf('cve-canary'): gcloud compute security-policies rules create <priority> --security-policy=<policy> --expression="request.path.matches('<path-regex>')" --action=deny-403
10Stop the instance once the memory image is saved. Removing the service account needs a stopped instance: gcloud compute instances stop <instance> --zone=<zone>
11Take the service account away from the instance so it cannot mint new tokens: gcloud compute instances set-service-account <instance> --zone=<zone> --no-service-account --no-scopes
12Disable the service account and its keys if the attacker used them off the instance: gcloud iam service-accounts disable <sa-email>
13Remove attacker SSH keys from instance and project metadata, and remove roles/compute.osLogin and roles/compute.osAdminLogin grants that the attacker added

Eradicate and recover

#Item
1Create copies of the evidence disks, attach them read-only to a forensic instance in an isolated project, and work from the copies: gcloud compute disks create <copy> --source-snapshot=<snapshot> --zone=<zone>
2Find how the attacker got in: exposed services, weak or reused credentials, vulnerable packages, a leaked key. Search the other instances for the same indicators
3Rebuild from a known-good image or template, and redeploy the workload with a dedicated service account that has only the roles it needs
4Patch or rebuild every instance built from the same image. Take the image ID from the boot disk's sourceImageId, and update instance templates that reference the image. List the disks built from it, where users names the attached instances: gcloud compute disks list --filter="sourceImageId=<image-id>" --format="value(name,users)"
5Rotate every secret the instance stored or could read: application credentials, database passwords, keys in metadata and files, and anything reachable with its service account
6Enable OS Login and block project-wide SSH keys: gcloud compute project-info add-metadata --metadata=enable-oslogin=TRUE
7Enforce compute.requireOsLogin at the organization
8Turn on Shielded VM features, VPC Flow Logs for the subnet, and Virtual Machine Threat Detection in Security Command Center
9Remove deletion protection after the case owner releases the evidence: gcloud compute instances update <instance> --zone=<zone> --no-deletion-protection
10Delete the compromised instance and the quarantine rules destructive: gcloud compute instances delete <instance> --zone=<zone>
Watch out
  • A new firewall rule applies only to new connections. A tracked connection persists while at least one packet crosses it every 10 minutes, so an attacker with an open session keeps it after the deny rules go in. Stop the instance or remove its address once the memory image is saved.
  • Stopping an instance clears memory and releases an ephemeral external IP address. Capture memory before the stop, and record the address first.
  • Removing the service account requires a stopped instance, and the credentials the attacker already fetched from the metadata server stay valid until they expire. Disable the service account to end them early.
  • Startup scripts in metadata run again at every boot. An attacker who edits one keeps access after a rebuild from the same instance configuration, so check metadata before reusing a template.

Google Cloud documentation: Virtual Machine Threat Detection overview; Compute Engine disk snapshots; stop and start an instance; gcloud reference for compute instances set-service-account; VPC firewall rules and connection tracking; Cloud Armor request logging and preconfigured WAF rules; Security Command Center Vulnerability Assessment for Google Cloud; Compute Engine API Disk resource. Google Cloud Threat Horizons H1 2026 (Cloud CISO Perspectives). Checked September 2026.

Adapts material from Dynamic Incident Response: A Framework for Security Teams by Joshua Wright, © 2026 The Escal Institute of Advanced Technologies, Inc. d/b/a SANS Institute, licensed under CC BY 4.0. Figures reproduced under that license. Changes were made. Not published by, endorsed by, or affiliated with the SANS Institute.