GCP - Sourcerepos 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

Source Repositories

有关 Source Repositories 的更多信息,请查看:

GCP - Source Repositories Enum

source.repos.get

拥有此权限可以将仓库下载到本地:

Clone source repository ```bash gcloud source repos clone --project= ```

source.repos.update

拥有此权限的主体 将能够在通过 gcloud source repos clone <repo> 克隆的仓库中写入代码。但请注意,此权限不能附加到自定义角色,只能通过如下预定义角色授予:

  • Owner
  • Editor
  • Source Repository Administrator (roles/source.admin)
  • Source Repository Writer (roles/source.writer)

要写入代码,只需执行常规的 git push

source.repos.setIamPolicy

拥有此权限的攻击者可以将之前的权限授予自己。

Secret access

如果攻击者能够访问保存令牌的 secrets,就可以窃取它们。关于如何访问 secret 的更多信息,请查看:

GCP - Secretmanager Privesc

Add SSH keys

可以在 Web 控制台中向 Source Repository 项目添加 ssh keys。该操作会发出一个 POST 请求到 /v1/sshKeys:add,并且可以在 https://source.cloud.google.com/user/ssh_keys 配置。

一旦设置了 ssh 密钥,你就可以通过以下方式访问仓库:

使用 SSH 克隆仓库 ```bash git clone ssh://username@domain.com@source.developers.google.com:2022/p//r/ ```

然后按常规使用 git 命令。

Manual Credentials

可以创建手动凭证以访问 Source Repositories:

点击第一个链接会将你引导到 https://source.developers.google.com/auth/start?scopes=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform&state&authuser=3

它会弹出一个 Oauth authorization prompt,以授予对 Google Cloud Development 的访问。因此你需要 用户的凭证 或者 浏览器中的已登录会话

这会将你带到一个包含 bash script to execute 的页面,并在 $HOME/.gitcookies 配置一个 git cookie。

执行该脚本后,你就可以使用 git clone、push 等操作,正常工作。

source.repos.updateProjectConfig

拥有此权限可以禁用 Source Repositories 的默认保护,从而允许上传包含 Private Keys 的代码:

Disable pushblock and modify pub/sub configuration ```bash gcloud source project-configs update --disable-pushblock ``` 你也可以配置不同的 pub/sub topic,或者将其完全禁用: ```bash gcloud source project-configs update --remove-topic=REMOVE_TOPIC gcloud source project-configs update --remove-topic=UPDATE_TOPIC ```

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