GCP - Cloud Functions Enum

Support HackTricks

Cloud Functions

Google Cloud Functions 旨在托管您的代码,该代码在响应事件时执行,而无需管理主机操作系统。此外,这些函数支持存储环境变量,代码可以利用这些变量。

Storage

Cloud Functions 代码存储在 GCP Storage 中。因此,任何对 GCP 中的存储桶具有读取权限的人都能够读取 Cloud Functions 代码。 代码存储在类似以下的存储桶中:

  • gcf-sources-<number>-<region>/<function-name>-<uuid>/version-<n>/function-source.zip

  • gcf-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

任何对存储 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 授权才能调用该函数,或者每个人是否都可以调用它:

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 '{}'

权限提升

在以下页面中,您可以查看如何滥用云函数权限以提升权限

未经身份验证的访问

利用后

持久性

参考文献

支持 HackTricks

Last updated