Skip to content

Commit 90bd042

Browse files
authored
Merge pull request #219 from JaimePolop/master
IAM and KMS Post Exploitation extended
2 parents 27fd007 + 1077cf6 commit 90bd042

File tree

2 files changed

+166
-7
lines changed

2 files changed

+166
-7
lines changed

src/pentesting-cloud/aws-security/aws-post-exploitation/aws-iam-post-exploitation.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,91 @@ If an S3 bucket is given as a principal, because S3 buckets do not have an Accou
9696

9797
A common way to avoid Confused Deputy problems is the use of a condition with `AWS:SourceArn` to check the origin ARN. However, **some services might not support that** (like CloudTrail according to some sources).
9898

99+
### Credential Deletion
100+
With any of the following permissions — `iam:DeleteAccessKey`, `iam:DeleteLoginProfile`, `iam:DeleteSSHPublicKey`, `iam:DeleteServiceSpecificCredential`, `iam:DeleteInstanceProfile`, `iam:DeleteServerCertificate`, `iam:DeleteCloudFrontPublicKey`, `iam:RemoveRoleFromInstanceProfile` — an actor can remove access keys, login profiles, SSH keys, service-specific credentials, instance profiles, certificates or CloudFront public keys, or disassociate roles from instance profiles. Such actions can immediately block legitimate users and applications and cause denial-of-service or loss of access for systems that depend on those credentials, so these IAM permissions must be tightly restricted and monitored.
101+
102+
```bash
103+
# Remove Access Key of a user
104+
aws iam delete-access-key \
105+
--user-name <Username> \
106+
--access-key-id AKIAIOSFODNN7EXAMPLE
107+
108+
## Remove ssh key of a user
109+
aws iam delete-ssh-public-key \
110+
--user-name <Username> \
111+
--ssh-public-key-id APKAEIBAERJR2EXAMPLE
112+
```
113+
114+
### Identity Deletion
115+
With permissions like `iam:DeleteUser`, `iam:DeleteGroup`, `iam:DeleteRole`, or `iam:RemoveUserFromGroup`, an actor can delete users, roles, or groups—or change group membership—removing identities and associated traces. This can immediately break access for people and services that depend on those identities, causing denial-of-service or loss of access, so these IAM actions must be tightly restricted and monitored.
116+
117+
```bash
118+
# Delete a user
119+
aws iam delete-user \
120+
--user-name <Username>
121+
122+
# Delete a group
123+
aws iam delete-group \
124+
--group-name <Username>
125+
126+
# Delete a role
127+
aws iam delete-role \
128+
--role-name <Role>
129+
```
130+
131+
###
132+
With any of the following permissions — `iam:DeleteGroupPolicy`, `iam:DeleteRolePolicy`, `iam:DeleteUserPolicy`, `iam:DeletePolicy`, `iam:DeletePolicyVersion`, `iam:DeleteRolePermissionsBoundary`, `iam:DeleteUserPermissionsBoundary`, `iam:DetachGroupPolicy`, `iam:DetachRolePolicy`, `iam:DetachUserPolicy` — an actor can delete or detach managed/inline policies, remove policy versions or permissions boundaries, and unlink policies from users, groups, or roles. This destroys authorizations and can alter the permissions model, causing immediate loss of access or denial-of-service for principals that depended on those policies, so these IAM actions must be tightly restricted and monitored.
133+
134+
```bash
135+
# Delete a group policy
136+
aws iam delete-group-policy \
137+
--group-name <GroupName> \
138+
--policy-name <PolicyName>
139+
140+
# Delete a role policy
141+
aws iam delete-role-policy \
142+
--role-name <RoleName> \
143+
--policy-name <PolicyName>
144+
```
145+
146+
### Federated Identity Deletion
147+
With `iam:DeleteOpenIDConnectProvider`, `iam:DeleteSAMLProvider`, and `iam:RemoveClientIDFromOpenIDConnectProvider`, an actor can delete OIDC/SAML identity providers or remove client IDs. This breaks federated authentication, preventing token validation and immediately denying access to users and services that rely on SSO until the IdP or configurations are restored.
148+
149+
```bash
150+
# Delete OIDCP provider
151+
aws iam delete-open-id-connect-provider \
152+
--open-id-connect-provider-arn arn:aws:iam::111122223333:oidc-provider/accounts.google.com
153+
154+
# Delete SAML provider
155+
aws iam delete-saml-provider \
156+
--saml-provider-arn arn:aws:iam::111122223333:saml-provider/CorporateADFS
157+
```
158+
159+
### Illegitimate MFA Activation
160+
With `iam:EnableMFADevice`, an actor can register an MFA device on a user’s identity, preventing the legitimate user from signing in. Once an unauthorized MFA is enabled the user can be locked out until the device is removed or reset (note: if multiple MFA devices are registered, sign-in requires only one, so this attack will have no effect on denying access).
161+
162+
```bash
163+
aws iam enable-mfa-device \
164+
--user-name <Username> \
165+
--serial-number arn:aws:iam::111122223333:mfa/alice \
166+
--authentication-code1 123456 \
167+
--authentication-code2 789012
168+
```
169+
170+
### Certificate/Key Metadata Tampering
171+
With `iam:UpdateSSHPublicKey`, `iam:UpdateCloudFrontPublicKey`, `iam:UpdateSigningCertificate`, `iam:UpdateServerCertificate`, an actor can change status or metadata of public keys and certificates. By marking keys/certificates inactive or altering references, they can break SSH authentication, invalidate X.509/TLS validations, and immediately disrupt services that depend on those credentials, causing loss of access or availability.
172+
173+
```bash
174+
aws iam update-ssh-public-key \
175+
--user-name <Username> \
176+
--ssh-public-key-id APKAEIBAERJR2EXAMPLE \
177+
--status Inactive
178+
179+
aws iam update-server-certificate \
180+
--server-certificate-name <Certificate_Name> \
181+
--new-path /prod/
182+
```
183+
99184
## References
100185

101186
- [https://docs.aws.amazon.com/IAM/latest/UserGuide/confused-deputy.html](https://docs.aws.amazon.com/IAM/latest/UserGuide/confused-deputy.html)

src/pentesting-cloud/aws-security/aws-post-exploitation/aws-kms-post-exploitation.md

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,27 +98,33 @@ aws kms put-key-policy --key-id mrk-c10357313a644d69b4b28b88523ef20c \
9898
```
9999

100100
> [!CAUTION]
101-
> Note that if you change that policy and only give access to an external account, and then from this external account you try to set a new policy to **give the access back to original account, you won't be able cause the Put Polocy action cannot be perfoemed from a cross account**.
101+
> Note that if you change that policy and only give access to an external account, and then from this external account you try to set a new policy to **give the access back to original account, you won't be able cause the Put Polocy action cannot be performed from a cross account**.
102102
103103
<figure><img src="../../../images/image (77).png" alt=""><figcaption></figcaption></figure>
104104

105105
### Generic KMS Ransomware
106106

107-
#### Global KMS Ransomware
108-
109107
There is another way to perform a global KMS Ransomware, which would involve the following steps:
110108

111109
- Create a new **key with a key material** imported by the attacker
112-
- **Re-encrypt older data** encrypted with the previous version with the new one.
110+
- **Re-encrypt older data** of the victim encrypted with the previous version with the new one.
113111
- **Delete the KMS key**
114112
- Now only the attacker, who has the original key material could be able to decrypt the encrypted data
115113

116-
### Destroy keys
114+
### Delete Keys via kms:DeleteImportedKeyMaterial
115+
116+
With the `kms:DeleteImportedKeyMaterial` permission, an actor can delete the imported key material from CMKs with `Origin=EXTERNAL` (CMKs that have imperted their key material), making them unable to decrypt data. This action is destructive and irreversible unless compatible material is re-imported, allowing an attacker to effectively cause ransomware-like data loss by rendering encrypted information permanently inaccessible.
117117

118118
```bash
119-
# Destoy they key material previously imported making the key useless
120-
aws kms delete-imported-key-material --key-id 1234abcd-12ab-34cd-56ef-1234567890ab
119+
aws kms delete-imported-key-material --key-id <Key_ID>
120+
```
121+
121122

123+
### Destroy keys
124+
125+
Destroying keys it's possible to perform a DoS.
126+
127+
```bash
122128
# Schedule the destoy of a key (min wait time is 7 days)
123129
aws kms schedule-key-deletion \
124130
--key-id arn:aws:kms:us-west-2:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab \
@@ -128,6 +134,74 @@ aws kms schedule-key-deletion \
128134
> [!CAUTION]
129135
> Note that AWS now **prevents the previous actions from being performed from a cross account:**
130136
137+
### Change or delete Alias
138+
This attack deletes or redirects AWS KMS aliases, breaking key resolution and causing immediate failures in any services that rely on those aliases, resulting in a denial-of-service. With permissions like `kms:DeleteAlias` or `kms:UpdateAlias` an attacker can remove or repoint aliases and disrupt cryptographic operations (e.g., encrypt, describe). Any service that references the alias instead of the key ID may fail until the alias is restored or correctly remapped.
139+
140+
```bash
141+
# Delete Alias
142+
aws kms delete-alias --alias-name alias/<key_alias>
143+
144+
# Update Alias
145+
aws kms update-alias \
146+
--alias-name alias/<key_alias> \
147+
--target-key-id <new_target_key>
148+
```
149+
150+
### Cancel Key Deletion
151+
With permissions like `kms:CancelKeyDeletion` and `kms:EnableKey`, an actor can cancel a scheduled deletion of an AWS KMS customer master key and later re-enable it. Doing so recovers the key (initially in Disabled state) and restores its ability to decrypt previously protected data, enabling exfiltration.
152+
153+
```bash
154+
# Firts cancel de deletion
155+
aws kms cancel-key-deletion \
156+
--key-id <Key_ID>
157+
158+
## Second enable the key
159+
aws kms enable-key \
160+
--key-id <Key_ID>
161+
```
162+
163+
### Disable Key
164+
With the `kms:DisableKey` permission, an actor can disable an AWS KMS customer master key, preventing it from being used for encryption or decryption. This breaks access for any services that depend on that CMK and can cause immediate disruptions or a denial-of-service until the key is re-enabled.
165+
166+
```bash
167+
aws kms disable-key \
168+
--key-id <key_id>
169+
```
170+
171+
### Derive Shared Secret
172+
With the `kms:DeriveSharedSecret` permission, an actor can use a KMS-held private key plus a user-supplied public key to compute an ECDH shared secret.
173+
174+
```bash
175+
aws kms derive-shared-secret \
176+
--key-id <key_id> \
177+
--public-key fileb:///<route_to_public_key> \
178+
--key-agreement-algorithm <algorithm>
179+
```
180+
181+
### Impersonation via kms:Sign
182+
With the `kms:Sign` permission, an actor can use a KMS-stored CMK to cryptographically sign data without exposing the private key, producing valid signatures that can enable impersonation or authorize malicious actions.
183+
184+
```bash
185+
aws kms sign \
186+
--key-id <key-id> \
187+
--message fileb://<ruta-al-archivo> \
188+
--signing-algorithm <algoritmo> \
189+
--message-type RAW
190+
```
191+
192+
### DoS with Custom Key Stores
193+
With permissions like `kms:DeleteCustomKeyStore`, `kms:DisconnectCustomKeyStore`, or `kms:UpdateCustomKeyStore`, an actor can modify, disconnect, or delete an AWS KMS Custom Key Store (CKS), making its master keys inoperable. That breaks encryption, decryption, and signing operations for any services that rely on those keys and can cause an immediate denial-of-service. Restricting and monitoring those permissions is therefore critical.
194+
195+
```bash
196+
aws kms delete-custom-key-store --custom-key-store-id <CUSTOM_KEY_STORE_ID>
197+
198+
aws kms disconnect-custom-key-store --custom-key-store-id <CUSTOM_KEY_STORE_ID>
199+
200+
aws kms update-custom-key-store --custom-key-store-id <CUSTOM_KEY_STORE_ID> --new-custom-key-store-name <NEW_NAME> --key-store-password <NEW_PASSWORD>
201+
```
202+
203+
204+
131205
<figure><img src="../../../images/image (76).png" alt=""><figcaption></figcaption></figure>
132206

133207
{{#include ../../../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)