GCP - Cloudbuild Privesc

Support HackTricks

cloudbuild

Cloud Build에 대한 자세한 정보는 다음을 확인하세요:

cloudbuild.builds.create

이 권한으로 클라우드 빌드를 제출할 수 있습니다. cloudbuild 머신의 파일 시스템에는 기본적으로 cloudbuild 서비스 계정의 토큰이 포함되어 있습니다: <PROJECT_NUMBER>@cloudbuild.gserviceaccount.com. 그러나 클라우드 빌드 구성에서 프로젝트 내의 모든 서비스 계정을 지정할 수 있습니다. 따라서 머신이 토큰을 서버로 유출하거나 그 안에서 리버스 셸을 얻어 토큰을 가져올 수 있습니다 (토큰이 포함된 파일은 변경될 수 있습니다).

원래의 익스플로잇 스크립트는 여기 GitHub에서 찾을 수 있습니다 (하지만 토큰을 가져오는 위치는 저에게는 작동하지 않았습니다). 따라서 취약한 환경의 생성, 익스플로잇 및 정리를 자동화하는 스크립트는 여기에서 확인하고, 클라우드 빌드 머신 내에서 리버스 셸을 얻고 토큰을 훔치는 파이썬 스크립트는 여기에서 확인하세요 (코드에서 다른 서비스 계정을 지정하는 방법을 찾을 수 있습니다).

더 자세한 설명은 https://rhinosecuritylabs.com/gcp/iam-privilege-escalation-gcp-cloudbuild/을 방문하세요.

cloudbuild.builds.update

잠재적으로 이 권한으로 클라우드 빌드를 업데이트하고 서비스 계정 토큰을 훔칠 수 있습니다. 이전 권한으로 수행된 것처럼 (하지만 불행히도 이 글을 쓰는 시점에서 해당 API를 호출할 방법을 찾을 수 없었습니다).

TODO

cloudbuild.repositories.accessReadToken

이 권한으로 사용자는 리포지토리에 접근하는 데 사용되는 읽기 접근 토큰을 얻을 수 있습니다:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d '{}' \
"https://cloudbuild.googleapis.com/v2/projects/<PROJECT_ID>/locations/<LOCATION>/connections/<CONN_ID>/repositories/<repo-id>:accessReadToken"

cloudbuild.repositories.accessReadWriteToken

이 권한을 가진 사용자는 리포지토리에 접근하는 데 사용되는 읽기 및 쓰기 액세스 토큰을 얻을 수 있습니다:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d '{}' \
"https://cloudbuild.googleapis.com/v2/projects/<PROJECT_ID>/locations/<LOCATION>/connections/<CONN_ID>/repositories/<repo-id>:accessReadWriteToken"

cloudbuild.connections.fetchLinkableRepositories

이 권한을 사용하면 연결이 접근할 수 있는 리포지토리를 가져올 수 있습니다:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://cloudbuild.googleapis.com/v2/projects/<PROJECT_ID>/locations/<LOCATION>/connections/<CONN_ID>:fetchLinkableRepositories"
HackTricks 지원하기

Last updated