GCP - Cloud Functions Enum

支持 HackTricks

Cloud Functions

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

Storage

Cloud Functions 代码存储在 GCP Storage 中。因此,任何拥有 bucket 读取权限 的人都可以读取 Cloud Functions 代码。 代码存储在如下所示的 bucket 中:

  • 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

任何拥有 bucket 读取权限 的用户都可以读取执行的代码

Artifact Registry

如果 cloud function 配置为在项目内的 Artifact Registry 仓库中存储执行的 Docker 容器,任何拥有仓库读取权限的人都可以下载镜像并检查源代码。更多信息请查看:

GCP - Artifact Registry Enum

SA

如果未指定,默认情况下,具有项目 Editor 权限App Engine Default Service Account 将附加到 Cloud Function。

Triggers, URL & Authentication

创建 Cloud Function 时需要指定 trigger。一个常见的是 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 '{}'

提权

在以下页面中,您可以查看如何滥用 cloud function 权限来提升权限

GCP - Cloudfunctions Privesc

未经身份验证的访问

GCP - Cloud Functions Unauthenticated Enum

利用后操作

GCP - Cloud Functions Post Exploitation

持久性

GCP - Cloud Functions Persistence

参考资料

支持 HackTricks

Last updated