GCP - Cloud Functions 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。
Cloud Functions
Google Cloud Functions 旨在托管您的代码,该代码在响应事件时执行,无需管理主机操作系统。此外,这些函数支持存储环境变量,代码可以利用这些变量。
Storage
Cloud Functions 代码存储在 GCP Storage 中。因此,任何对 GCP 中的存储桶具有读取权限的人都能够读取 Cloud Functions 代码。
代码存储在一个存储桶中,格式如下:
gcf-sources-<number>-<region>/<function-name>-<uuid>/version-<n>/function-source.zipgcf-v2-sources-<number>-<region>/<function-name>function-source.zip
例如:gcf-sources-645468741258-us-central1/function-1-003dcbdf-32e1-430f-a5ff-785a6e238c76/version-4/function-source.zip
Warning
任何对存储 Cloud Function 的存储桶具有读取权限的用户都可以读取执行的代码。
Artifact Registry
如果云函数配置为将执行的 Docker 容器存储在项目内的 Artifact Registry 仓库中,任何对该仓库具有读取权限的人都能够下载镜像并检查源代码。有关更多信息,请查看:
SA
如果未指定,默认情况下将附加具有项目编辑权限的App Engine 默认服务帐户到 Cloud Function。
Triggers, URL & Authentication
创建 Cloud Function 时,需要指定触发器。一个常见的触发器是HTTPS,这将创建一个可以通过网页浏览触发函数的 URL。
其他触发器包括 pub/sub、Storage、Filestore…
URL 格式为**https://<region>-<project-gcp-name>.cloudfunctions.net/<func_name>**
当使用 HTTPS 触发器时,还会指明调用者是否需要 IAM 授权才能调用该函数,或者每个人是否都可以调用它:
.png)
Inside the Cloud Function
代码下载到文件夹**/workspace中,文件名与 Cloud Function 中的文件名相同,并以用户 www-data 执行。
磁盘未以只读方式挂载**。
Enumeration
# List functions
gcloud functions list
gcloud functions describe <func_name> # Check triggers to see how is this function invoked
gcloud functions get-iam-policy <func_name>
# Get logs of previous runs. By default, limits to 10 lines
gcloud functions logs read <func_name> --limit [NUMBER]
# Call a function
curl https://<region>-<project>.cloudfunctions.net/<func_name>
gcloud functions call <func_name> --data='{"message": "Hello World!"}'
# If you know the name of projects you could try to BF cloud functions names
# Get events that could be used to trigger a cloud function
gcloud functions event-types list
# Access function with authentication
curl -X POST https://<region>-<project>.cloudfunctions.net/<func_name> \
-H "Authorization: bearer $(gcloud auth print-identity-token)" \
-H "Content-Type: application/json" \
-d '{}'
权限提升
在以下页面中,您可以查看如何滥用云函数权限以提升权限:
未经身份验证的访问
GCP - Cloud Functions Unauthenticated Enum
利用后
GCP - Cloud Functions Post Exploitation
持久性
GCP - Cloud Functions Persistence
参考
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

