GCP - local privilege escalation ssh pivoting
Tip
Leer en oefen AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Leer en oefen GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Leer en oefen Azure Hacking:
HackTricks Training Azure Red Team Expert (AzRTE)
Ondersteun HackTricks
- Kyk na die subskripsie planne!
- Sluit aan by die 💬 Discord groep of die telegram groep of volg ons op Twitter 🐦 @hacktricks_live.
- Deel hacking truuks deur PRs in te dien na die HackTricks en HackTricks Cloud github repos.
in this scenario we are going to suppose that you have compromised a non privilege account inside a VM in a Compute Engine project.
Verbluffend genoeg kan die GPC-permissies van die Compute Engine wat jy gekompromitteer het jou help om escalate privileges locally inside a machine. Selfs al sal dit nie altyd baie nuttig wees in ’n cloud-omgewing nie, is dit goed om te weet dit is moontlik.
Read the scripts
Compute Instances is waarskynlik daar om sommige skripte uit te voer wat aksies uitvoer met hul service accounts.
Aangesien IAM baie fynkorrelig is, kan ’n rekening read/write bevoegdhede oor ’n hulpbron hê maar geen list bevoegdhede hê nie.
’n Goeie hipotetiese voorbeeld hiervan is ’n Compute Instance wat toestemming het om backups te lees/skryf na ’n storage bucket genaamd instance82736-long-term-xyz-archive-0332893.
Die uitvoering van gsutil ls vanaf die opdraglyn lewer niks op nie, omdat die service account nie die storage.buckets.list IAM-permissie het nie. As jy egter gsutil ls gs://instance82736-long-term-xyz-archive-0332893 uitgevoer het, kan jy ’n volledige filesystem backup kry, wat jou clear-text toegang gee tot data wat jou plaaslike Linux-rekening nie het nie.
Jy mag hierdie bucket-naam binne ’n skrip (in bash, Python, Ruby…) kan vind.
Custom Metadata
Administrateurs kan custom metadata by die instance en project level voeg. Dit is bloot ’n manier om arbitrêre sleutel/waarde pare in ’n instance in te gee, en dit word algemeen gebruik vir omgewingsveranderlikes en startup/shutdown skripte.
Daarbenewens is dit moontlik om userdata by te voeg, wat ’n skrip is wat elke keer uitgevoer sal word wanneer die masjien begin of herbegin, en wat ook vanaf die metadata endpoint toeganklik is.
For more info check:
Abusing IAM permissions
Die meeste van die volgende voorgestelde permissies word aan die default Compute SA gegee, die enigste probleem is dat die default access scope die SA verhinder om dit te gebruik. As die cloud-platform scope egter aangeskakel is of net die compute scope aangeskakel is, sal jy dit kan misbruik.
Check the following permissions:
- compute.instances.osLogin
- compute.instances.osAdminLogin
- compute.projects.setCommonInstanceMetadata
- compute.instances.setMetadata
- compute.instances.setIamPolicy
Search for Keys in the filesystem
Kyk of ander gebruikers by die box aangemeld het in gcloud en hul credentials in die lêerstelsel gelos het:
Search for gcloud credentials in filesystem
``` sudo find / -name "gcloud" ```Dit is die mees interessante lêers:
~/.config/gcloud/credentials.db~/.config/gcloud/legacy_credentials/[ACCOUNT]/adc.json~/.config/gcloud/legacy_credentials/[ACCOUNT]/.boto~/.credentials.json
Meer API Keys regexes
Grep-patrone vir GCP credentials and keys
```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>
## Verwysings
- [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]
> Leer en oefen AWS Hacking:<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;">\
> Leer en oefen GCP Hacking: <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;">
> Leer en oefen Azure Hacking: <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>Ondersteun HackTricks</summary>
>
> - Kyk na die [**subskripsie planne**](https://github.com/sponsors/carlospolop)!
> - **Sluit aan by die** 💬 [**Discord groep**](https://discord.gg/hRep4RUj7f) of die [**telegram groep**](https://t.me/peass) of **volg** ons op **Twitter** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
> - **Deel hacking truuks deur PRs in te dien na die** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
>
> </details>
HackTricks Cloud

