GCP - local privilege escalation ssh pivoting
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を提出してハッキングトリックを共有してください。
in this scenario we are going to suppose that you have compromised a non privilege account inside a VM in a Compute Engine project.
驚くべきことに、あなたが侵害した Compute Engine の GPC 権限は、マシン内でローカルに権限を escalate privileges locally inside a machine するのに役立つことがあります。クラウド環境では常に有用とは限りませんが、可能であることを知っておくのは有益です。
Read the scripts
Compute Instances はおそらくその service accounts を使って何らかのスクリプトを execute some scripts するために存在しています。
IAM は細かく制御できるため、あるアカウントがリソースに対して read/write 権限を持っていても no list privileges の場合があります。
良い仮想例として、instance82736-long-term-xyz-archive-0332893 という storage bucket にバックアップを read/write する権限を持つ Compute Instance がある場合が挙げられます。
コマンドラインから gsutil ls を実行しても何も返ってこないことがあります。これは service account に storage.buckets.list IAM permission がないためです。しかし、gsutil ls gs://instance82736-long-term-xyz-archive-0332893 を実行すると、完全なファイルシステムのバックアップが見つかり、あなたのローカル Linux アカウントが持っていない平文データにアクセスできる可能性があります。
このバケット名はスクリプト(bash、Python、Ruby など)の中に見つかることがあります。
Custom Metadata
管理者はインスタンスレベルとプロジェクトレベルで custom metadata を追加できます。これはインスタンスに任意の key/value ペアを渡す単純な方法で、環境変数や startup/shutdown スクリプトに一般的に使われます。
さらに、userdata を追加することが可能で、これはマシンが起動または再起動されるたびに executed everytime されるスクリプトで、metadata endpoint からも accessed できます。
For more info check:
Abusing IAM permissions
以下に挙げる多くの権限は default Compute SA に付与されていることが多く、唯一の問題は default access scope が SA にそれらを使わせない点です。しかし、cloud-platform scope が有効化されているか、あるいは compute scope のみが有効であれば、それらを abuse することが可能です。
Check the following permissions:
- compute.instances.osLogin
- compute.instances.osAdminLogin
- compute.projects.setCommonInstanceMetadata
- compute.instances.setMetadata
- compute.instances.setIamPolicy
Search for Keys in the filesystem
ボックス内で他のユーザーが gcloud にログインして filesystem に認証情報を残していないか確認してください:
Search for gcloud credentials in filesystem
``` sudo find / -name "gcloud" ```最も興味深いファイルは次のとおりです:
~/.config/gcloud/credentials.db~/.config/gcloud/legacy_credentials/[ACCOUNT]/adc.json~/.config/gcloud/legacy_credentials/[ACCOUNT]/.boto~/.credentials.json
追加の API Keys 正規表現
Grep パターン (GCP credentials と keys)
```bash TARGET_DIR="/path/to/whatever"Service account keys
grep -Pzr “(?s){[^{}]?service_account[^{}]?private_key.*?}”
“$TARGET_DIR”
Legacy GCP creds
grep -Pzr “(?s){[^{}]?client_id[^{}]?client_secret.*?}”
“$TARGET_DIR”
Google API keys
grep -Pr “AIza[a-zA-Z0-9\-_]{35}”
“$TARGET_DIR”
Google OAuth tokens
grep -Pr “ya29.[a-zA-Z0-9_-]{100,200}”
“$TARGET_DIR”
Generic SSH keys
grep -Pzr “(?s)—–BEGIN[ A-Z]?PRIVATE KEY[a-zA-Z0-9/+=\n-]?END[ A-Z]*?PRIVATE KEY—–”
“$TARGET_DIR”
Signed storage URLs
grep -Pir “storage.googleapis.com.*?Goog-Signature=[a-f0-9]+”
“$TARGET_DIR”
Signed policy documents in HTML
grep -Pzr ‘(?s)<form action.?googleapis.com.?name=“signature” value=“.*?”>’
“$TARGET_DIR”
</details>
## 参考資料
- [https://about.gitlab.com/blog/2020/02/12/plundering-gcp-escalating-privileges-in-google-cloud-platform/](https://about.gitlab.com/blog/2020/02/12/plundering-gcp-escalating-privileges-in-google-cloud-platform/)
> [!TIP]
> AWSハッキングを学び、実践する:<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">\
> GCPハッキングを学び、実践する:<img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)<img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
> Azureハッキングを学び、実践する:<img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training Azure Red Team Expert (AzRTE)**](https://training.hacktricks.xyz/courses/azrte)<img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
>
> <details>
>
> <summary>HackTricksをサポートする</summary>
>
> - [**サブスクリプションプラン**](https://github.com/sponsors/carlospolop)を確認してください!
> - **💬 [**Discordグループ**](https://discord.gg/hRep4RUj7f)または[**テレグラムグループ**](https://t.me/peass)に参加するか、**Twitter** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**をフォローしてください。**
> - **[**HackTricks**](https://github.com/carlospolop/hacktricks)および[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud)のGitHubリポジトリにPRを提出してハッキングトリックを共有してください。**
>
> </details>
HackTricks Cloud

