GCP - local privilege escalation ssh pivoting

Tip

Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Impara e pratica il hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Supporta HackTricks

in this scenario we are going to suppose that you have compromised a non privilege account inside a VM in a Compute Engine project.

Sorprendentemente, i permessi GPC del compute engine che hai compromesso possono aiutarti a escalate privileges locally inside a machine. Anche se questo non sarà sempre molto utile in un ambiente cloud, è bene sapere che è possibile.

Leggi gli script

Compute Instances sono probabilmente lĂŹ per eseguire alcuni script per effettuare azioni con i loro service accounts.

PoichÊ IAM è molto granulare, un account può avere privilegi read/write su una risorsa ma nessun privilegio di list.

Un ottimo esempio ipotetico è una Compute Instance che ha il permesso di leggere/scrivere backup in un bucket di storage chiamato instance82736-long-term-xyz-archive-0332893.

Eseguire gsutil ls dalla riga di comando non restituisce nulla, poichĂŠ il service account non ha il permesso IAM storage.buckets.list. Tuttavia, se esegui gsutil ls gs://instance82736-long-term-xyz-archive-0332893 potresti trovare un backup completo del filesystem, ottenendo accesso in chiaro a dati che il tuo account Linux locale non possiede.

Potresti essere in grado di trovare il nome di questo bucket all’interno di uno script (in bash, Python, Ruby…).

Custom Metadata

Gli amministratori possono aggiungere custom metadata a livello di instance e project. Questo è semplicemente un modo per passare coppie chiave/valore arbitrarie in un’instance, ed è comunemente usato per variabili d’ambiente e startup/shutdown scripts.

Inoltre, è possibile aggiungere userdata, che è uno script che verrà eseguito ogni volta che la macchina viene avviata o riavviata e che può essere accessibile anche dall’endpoint dei metadata.

For more info check:

Cloud SSRF - HackTricks

Abusing IAM permissions

La maggior parte dei permessi proposti qui sotto sono assegnati al default Compute SA, l’unico problema è che lo scope di accesso predefinito impedisce alla SA di usarli. Tuttavia, se lo scope cloud-platform è abilitato o anche solo lo scope compute è abilitato, sarai in grado di abusarne.

Check the following permissions:

Cerca chiavi nel filesystem

Controlla se altri utenti hanno effettuato il login con gcloud all’interno della macchina e lasciato le loro credenziali nel filesystem:

Cerca credenziali gcloud nel filesystem ``` sudo find / -name "gcloud" ```

Questi sono i file piĂš interessanti:

  • ~/.config/gcloud/credentials.db
  • ~/.config/gcloud/legacy_credentials/[ACCOUNT]/adc.json
  • ~/.config/gcloud/legacy_credentials/[ACCOUNT]/.boto
  • ~/.credentials.json

Altre regex per API Keys

Pattern grep per credenziali e chiavi GCP ```bash TARGET_DIR="/path/to/whatever"

Service account keys

grep -Pzr “(?s){[^{}]?service_account[^{}]?private_key.*?}”
“$TARGET_DIR”

Legacy GCP creds

grep -Pzr “(?s){[^{}]?client_id[^{}]?client_secret.*?}”
“$TARGET_DIR”

Google API keys

grep -Pr “AIza[a-zA-Z0-9\-_]{35}”
“$TARGET_DIR”

Google OAuth tokens

grep -Pr “ya29.[a-zA-Z0-9_-]{100,200}”
“$TARGET_DIR”

Generic SSH keys

grep -Pzr “(?s)—–BEGIN[ A-Z]?PRIVATE KEY[a-zA-Z0-9/+=\n-]?END[ A-Z]*?PRIVATE KEY—–”
“$TARGET_DIR”

Signed storage URLs

grep -Pir “storage.googleapis.com.*?Goog-Signature=[a-f0-9]+”
“$TARGET_DIR”

Signed policy documents in HTML

grep -Pzr ‘(?s)<form action.?googleapis.com.?name=“signature” value=“.*?”>’
“$TARGET_DIR”

</details>

## Riferimenti

- [https://about.gitlab.com/blog/2020/02/12/plundering-gcp-escalating-privileges-in-google-cloud-platform/](https://about.gitlab.com/blog/2020/02/12/plundering-gcp-escalating-privileges-in-google-cloud-platform/)

> [!TIP]
> Impara e pratica il hacking AWS:<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">\
> Impara e pratica il hacking GCP: <img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)<img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
> Impara e pratica il hacking Azure: <img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training Azure Red Team Expert (AzRTE)**](https://training.hacktricks.xyz/courses/azrte)<img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
>
> <details>
>
> <summary>Supporta HackTricks</summary>
>
> - Controlla i [**piani di abbonamento**](https://github.com/sponsors/carlospolop)!
> - **Unisciti al** 💬 [**gruppo Discord**](https://discord.gg/hRep4RUj7f) o al [**gruppo telegram**](https://t.me/peass) o **seguici** su **Twitter** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
> - **Condividi trucchi di hacking inviando PR ai** [**HackTricks**](https://github.com/carlospolop/hacktricks) e [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repos su github.
>
> </details>