How it works
A customer managed IAM policy is not a single document. IAM stores up to five versions of it, and one of them is marked as the default. The default version is the one in effect for every user, group and role the policy is attached to. Changing a managed policy means creating a new version, and IAM lets the caller mark that version as the default in the same request.
That design gives two privilege escalation paths to a principal that holds policy version permissions on a policy attached to itself:
- New version as default.
iam:CreatePolicyVersionwith the set-as-default flag replaces the operative document with one the attacker wrote. The flag is part of theCreatePolicyVersionrequest, soiam:SetDefaultPolicyVersionis not needed. - Roll back to an older version.
iam:SetDefaultPolicyVersionmoves the default pointer to a version that is already stored. If an earlier, broader version was never deleted, the attacker reactivates it without writing anything new.
Neither path attaches a policy, creates a role or touches a trust relationship. The attachment stays as it was; only the document behind it changes. For that reason the identity often does not look privileged in an entitlement review: it holds one modest policy and a permission to edit that policy, the pattern usually called a shadow admin.
The effect is not limited to the attacker. A new default applies to every identity the policy is attached to, and to every identity that uses the policy as a permissions boundary. A widened shared policy therefore raises the privileges of other principals too, which matters for cleanup.
IAM policy changes are eventually consistent. The new default takes effect within seconds in most cases, but a request made immediately after the change can still be evaluated against the old document.
Prerequisites
- Valid credentials for an IAM user or role session in the target account.
iam:CreatePolicyVersion, oriam:SetDefaultPolicyVersion, allowed on a customer managed policy. Grants such asiam:*onResource: "*", or a policy that lets a team "manage its own policies", commonly include both.- The policy must be attached to an identity the attacker controls: its own user, a group it belongs to, or a role it can assume.
- For the rollback variant: an older stored version that grants more than the current default.
- No permissions boundary, service control policy or explicit deny that blocks the new permissions. A boundary caps what the rewritten policy can grant.
Read access (iam:ListAttachedUserPolicies, iam:ListPolicyVersions, iam:GetPolicyVersion) makes target selection easier but is not required. An attacker who already knows the policy ARN can write blind.
Attack steps
For authorized security testing and lab use only. Run these steps against systems you own or have written permission to assess.
1. Find a writable policy attached to the current identity
# Who am I, and which managed policies are attached to me?
aws iam get-user
aws iam list-attached-user-policies --user-name alice
# Which versions does the policy hold, and which one is the default?
aws iam list-policy-versions --policy-arn arn:aws:iam::111122223333:policy/dev-tools
# Read each stored version; older ones may already be broader
aws iam get-policy-version --policy-arn arn:aws:iam::111122223333:policy/dev-tools --version-id v1
For a role session, use aws iam list-attached-role-policies --role-name <role> instead. Pacu automates the search: its iam__enum_permissions module collects the permissions of the current identity and iam__privesc_scan checks them against known escalation paths, including both policy version methods.
Pacu > run iam__enum_permissions
Pacu > run iam__privesc_scan
2. Write a new default version
Save the document the attacker wants in effect:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "*",
"Resource": "*"
}
]
}
Create it as a new version and make it the default in one call:
aws iam create-policy-version \
--policy-arn arn:aws:iam::111122223333:policy/dev-tools \
--policy-document file://admin.json \
--set-as-default
If the policy already holds five versions, the call fails until one is deleted. An operator with iam:DeletePolicyVersion removes a non-default version first; one without it falls back to the rollback variant.
3. Or roll back to a broader stored version
aws iam set-default-policy-version \
--policy-arn arn:aws:iam::111122223333:policy/dev-tools \
--version-id v1
4. Use the new permissions
The same credentials now carry the new permissions. No new session or sign-in is needed, because IAM evaluates the default version on each request. Typical next steps are creating an access key for an administrator, reading secrets, or adding a second way in, such as an access key on another user.
Impact
With a new version, the attacker chooses the outcome: an Allow * on * document makes the identity an account administrator, limited only by permissions boundaries, service control policies and explicit denies elsewhere. With a rollback, the outcome is whatever the old version granted.
The change also persists. The policy keeps its name, its ARN and its attachments, and the widened document stays in effect until someone reads it and reverts it. Because every attached identity inherits the change, other users and workloads silently gain the same permissions.
OPSEC and artifacts
- Two-step change. A careful operator creates the version without the default flag, waits, and switches the pointer later with
SetDefaultPolicyVersion, so that no single event shows both the document and its activation. Both calls are still recorded, and the first one stores the document in the account where anyone with read access can see it. - Narrow documents. Instead of
Allow *, the operator adds only the actions it needs, such asiam:CreateAccessKeyorsts:AssumeRoleon one role. This defeats rules that look for administrator wildcards in the request; it does not remove the CreatePolicyVersion event. - Rollback instead of write. Reactivating an old version leaves no new document to review. It still writes a SetDefaultPolicyVersion event with the policy ARN and the chosen version id.
- Restoring the default. After adding a durable backdoor elsewhere, the operator sets the original version as default again and may delete the version it created. The interval is bounded, but the events remain, and a
DeletePolicyVersioncall shortly after a default change is itself a signal. - What always remains: IAM management events in CloudTrail with the caller identity, source address, user agent and request parameters. IAM is a global service, and its events are recorded in the US East (N. Virginia) Region in the commercial partition. The version list of the policy (
ListPolicyVersions) shows the creation date of each stored version until that version is deleted. - What does not appear: the use of the new permissions is logged under the same identity as its routine work. Nothing marks those later calls as depending on the changed policy.
Detection
The write is easy to find and hard to interpret, because the event names the change and not its effect.
- Every default change on a customer managed policy. Alert on
CreatePolicyVersionwhererequestParameters.setAsDefaultis true and on everySetDefaultPolicyVersion. The policy version detection rules implement both. - Self-benefit. The strongest signal is a caller that changes a policy attached to itself, to a group it is in, or to a role it can assume. Resolve the attachments of
requestParameters.policyArnwithListEntitiesForPolicyand compare them with the caller. - Document comparison. Read the new default with
GetPolicyVersionand compare its allowed actions with the previous default. A change made by a pipeline role inside a deployment window that narrows access is routine. A wildcard action, newiam:actions or a newsts:AssumeRolegrant is not. - Rollback to an old version. A
SetDefaultPolicyVersionthat selects a lower version id than the current default is rare in normal operations, where the pointer moves forward. - Preceding discovery.
ListPolicyVersionsandGetPolicyVersioncalls across many policies, or aGetAccountAuthorizationDetailscall, by the same identity shortly before the change. See the IAM enumeration rules.
-- Athena, CloudTrail table: policy version writes and default changes
SELECT eventtime, eventname, useridentity.arn AS caller, sourceipaddress,
json_extract_scalar(requestparameters, '$.policyArn') AS policy_arn,
json_extract_scalar(requestparameters, '$.versionId') AS version_id,
json_extract_scalar(requestparameters, '$.setAsDefault') AS set_default,
errorcode
FROM cloudtrail_logs
WHERE eventsource = 'iam.amazonaws.com'
AND eventname IN ('CreatePolicyVersion', 'SetDefaultPolicyVersion', 'DeletePolicyVersion')
AND eventtime >= '2026-11-28T00:00:00Z'
ORDER BY eventtime
Keep the rows with an errorcode: a denied attempt shows intent even when the change failed. Amazon GuardDuty can also raise PrivilegeEscalation:IAMUser/AnomalousBehavior when IAM policy changes are unusual for the calling identity, but it does not fire on every change, so the CloudTrail rule is the primary control.
Mitigation
- Do not grant policy version permissions on policies attached to the grantee. Scope
iam:CreatePolicyVersionandiam:SetDefaultPolicyVersionwith theResourceelement to the specific policy ARNs a team owns, and keep those policies off the team's own identities. Policy authorship belongs to a pipeline role, not to interactive users. - Put a permissions boundary on delegated administrators. A permissions boundary caps what a rewritten policy can grant. Deny
iam:CreatePolicyVersionandiam:SetDefaultPolicyVersionon the boundary policy itself, or the boundary can be widened the same way. - Use a service control policy for shared guardrail policies. In AWS Organizations, deny version changes on named policies for every principal except the deployment role.
- Delete old versions. After a policy is tightened, remove the broader versions so that there is nothing to roll back to. Review stored versions as part of access reviews, not only the default.
- Baseline approved defaults. Record a digest of each approved default document and alert when the live default differs.
- Apply least privilege to
iam:*. Wildcard IAM grants are the usual source of this path. Replace them with the specific actions a role needs.
Detection rules for this attack
Log events to collect
FAQ
Does --set-as-default need the iam:SetDefaultPolicyVersion permission?
No. CreatePolicyVersion takes the default flag as part of the same request, so iam:CreatePolicyVersion alone is enough to write a new version and make it the operative one. iam:SetDefaultPolicyVersion is only needed to switch to a version that is already stored.
Can an attacker do this to AWS managed policies such as AdministratorAccess?
No. Only customer managed policies in the account can receive new versions from the account's principals. The attack targets a customer managed policy that is attached to the attacker's own user, group or role, or to a role the attacker can assume.
How is the change detected?
CloudTrail records CreatePolicyVersion and SetDefaultPolicyVersion as IAM management events with the caller, the policy ARN and, for a new version, the setAsDefault flag. Alert on both, and compare the new default document with the previous one, because the event name alone does not say whether access widened.
Why do old policy versions matter?
A managed policy keeps up to five versions. A version that was replaced because it was too broad stays stored unless someone deletes it, and anyone with iam:SetDefaultPolicyVersion can bring it back with one call. No new document is written, so reviews that only read policy text miss it.
References
- Versioning IAM policies (AWS IAM User Guide)
- CreatePolicyVersion (AWS IAM API Reference)
- SetDefaultPolicyVersion (AWS IAM API Reference)
- Account Manipulation: Additional Cloud Roles, T1098.003 (MITRE ATT&CK)
- AWS IAM Privilege Escalation: Methods and Mitigation (Rhino Security Labs)
- Pacu: the AWS exploitation framework (Rhino Security Labs)
Techniques, tactics and threat groups: MITRE ATT&CK® Enterprise v20.1. © The MITRE Corporation. This work is reproduced and distributed with the permission of The MITRE Corporation. Last updated 2026-11-29.