PIVTR-D
RAWS playbook · Identity and access

Leaked IAM user access keys used to change permissions

The attacker calls AWS with an IAM user's long-term access key found in code, a continuous integration (CI) log or a laptop. A typical run checks the key with GetCallerIdentity, then creates new users, keys or console passwords and grants itself more policy. Deactivate the key and block the temporary credentials made from it first, and export CloudTrail before the 90-day event history runs out.

Look here

LogSearch for
CloudTrail event historyManagement calls made with the key in the last 90 days. Event history has no data events, so use the trail logs or CloudTrail Lake for S3 object access and older activity. IAM events are in us-east-1. Repeat for each Region: aws cloudtrail lookup-events --region <region> --lookup-attributes AttributeKey=AccessKeyId,AttributeValue=<access-key-id> --start-time <utc-start> --end-time <utc-end>
CloudTrail, IAM and STS eventsKey checks, new principals and policy changes: GetCallerIdentity, CreateUser, CreateAccessKey, CreateLoginProfile, UpdateLoginProfile, AttachUserPolicy, PutUserPolicy, AddUserToGroup, AttachRolePolicy, PutRolePolicy, UpdateAssumeRolePolicy, CreatePolicyVersion, SetDefaultPolicyVersion, GetSessionToken, GetFederationToken, AssumeRole
CloudTrail LakeEvery call made with the key, in time order: SELECT eventTime, eventSource, eventName, awsRegion, sourceIPAddress, userAgent, errorCode FROM <event-data-store-id> WHERE userIdentity.accessKeyId = '<access-key-id>' ORDER BY eventTime
GuardDutyFindings for leaked or misused credentials: CredentialAccess:IAMUser/CompromisedCredentials, PrivilegeEscalation:IAMUser/AnomalousBehavior, Persistence:IAMUser/AnomalousBehavior, Discovery:IAMUser/AnomalousBehavior, AttackSequence:IAM/CompromisedCredentials
IAMAn AWS quarantine policy on the user, AWSCompromisedKeyQuarantineV2 or AWSCompromisedKeyQuarantineV3: aws iam list-attached-user-policies --user-name <user>

Contain

#Item
1Deactivate the key and keep it for the investigation: aws iam update-access-key --user-name <user> --access-key-id <access-key-id> --status Inactive
2Leave any AWSCompromisedKeyQuarantine policy attached, and follow the instructions in the AWS Support case
3Block temporary credentials issued from the key. The inline policy denies * when aws:TokenIssueTime is before now: aws iam put-user-policy --user-name <user> --policy-name ir-deny-old-tokens --policy-document file://deny-old-tokens.json
4List the keys of each user named in the CreateAccessKey events, then deactivate the attacker's keys with the item 1 command: aws iam list-access-keys --user-name <user>
5Revoke sessions on every role the key assumed, with the same aws:TokenIssueTime deny: aws iam put-role-policy --role-name <role> --policy-name AWSRevokeOlderSessions --policy-document file://revoke.json
6Remove console passwords the attacker created destructive: aws iam delete-login-profile --user-name <user>

Eradicate and recover

#Item
1List the versions of each changed managed policy and find the known-good one: aws iam list-policy-versions --policy-arn <arn>
2Set the known-good version as the default: aws iam set-default-policy-version --policy-arn <arn> --version-id <known-good>
3Restore each changed trust policy: aws iam update-assume-role-policy --role-name <role> --policy-document file://known-good-trust.json
4Remove users, keys, inline policies and group memberships created in the window, after the evidence is exported
5Rotate every secret and key the user's policies could read, working from the scope in Scope
6Delete the exposed key once no workload depends on it destructive: aws iam delete-access-key --user-name <user> --access-key-id <access-key-id>
7Move the workload that used the key to an IAM role, and remove the key from the repository or log where it leaked
Watch out
  • Deactivating or rotating the key leaves temporary credentials from GetSessionToken and GetFederationToken valid for up to 36 hours. The aws:TokenIssueTime deny closes that gap for IAM users. It cannot restrict temporary credentials the root user created. For a root key, delete the key and open an AWS Support case.
  • Those temporary credentials carry their own ASIA key IDs. Search for each one in CloudTrail as well.
Adapts material from Dynamic Incident Response: A Framework for Security Teams by Joshua Wright, © 2026 The Escal Institute of Advanced Technologies, Inc. d/b/a SANS Institute, licensed under CC BY 4.0. Figures reproduced under that license. Changes were made. Not published by, endorsed by, or affiliated with the SANS Institute.