Skip to content
WETNav

Investigation · Cloud

What did this leaked AWS access key do?

Scope activity from a leaked AWS access key in CloudTrail: enumeration, persistence, defense impairment and data access, with the retention and data-event traps called out.

When you would ask thisAn AWS access key has been exposed (committed to a repo, found in a paste, flagged by GuardDuty) and you need to determine what, if anything, it did before you deactivate it.

Steps

  1. 1

    Identify the key type from its prefix

    Read the key ID prefix first, because it tells you the credential type and where to look. AKIA indicates a long-term access key belonging to an IAM user; ASIA indicates a temporary credential issued by STS (an assumed role or a federated/temporary session). The distinction matters: a long-term AKIA key is tied to one IAM user and persists until deactivated, while an ASIA key is short-lived and usually implies a role was assumed, so you also need to find the AssumeRole call that minted it and the principal behind it. Note the account ID and, for ASIA, the role.

  2. 2

    Pull every CloudTrail event for the key

    In CloudTrail, filter on userIdentity.accessKeyId equal to the leaked key to get its activity. For each event capture eventName (the API call), sourceIPAddress, userAgent, eventTime, errorCode and errorMessage. The sourceIPAddress and userAgent quickly separate the attacker's calls from legitimate automation using the same key. errorCode is especially useful: a wave of AccessDenied errors is an attacker probing the key's permissions. Use CloudTrail Lake or Athena over the trail's S3 bucket for anything beyond a quick lookup, because the console's Event history is limited (see the gotchas).

    Lookup recent events for the key (AWS CLI)
    aws cloudtrail lookup-events \
      --lookup-attributes AttributeKey=AccessKeyId,AttributeValue=AKIAEXAMPLE... \
      --max-results 50 \
      --query 'Events[].{Time:EventTime,Name:EventName,User:Username}'
  3. 3

    Read the enumeration phase

    Attackers almost always start by orienting. The first call is typically sts:GetCallerIdentity (confirming which principal and account the key belongs to), followed by a burst of List* and Describe* calls across IAM, S3, EC2, Secrets Manager and more. Many of these will carry AccessDenied in errorCode where the key lacks the permission, which draws the key's effective permission map for you. A GetCallerIdentity immediately after the key's exposure time, from an IP and user agent that are not your automation, is the clearest sign the leaked key was actually picked up and used.

  4. 4

    Hunt persistence the key established

    Check whether the attacker used the key to create durable access, which must be removed even after you deactivate the leaked key itself. The high-value eventNames are iam:CreateAccessKey (a second key, often added to the compromised user or a new one), iam:CreateUser, iam:CreateLoginProfile (enabling console sign-in for a user that had none), iam:AttachUserPolicy / iam:PutUserPolicy (granting the attacker broad permissions), and iam:UpdateAssumeRolePolicy (editing a role's trust policy so the attacker's account can assume it). Enumerate what each created so eviction removes all of it, not just the original key.

    Find IAM persistence calls in CloudTrail Lake (SQL; confirm your event data store id)
    SELECT eventTime, eventName, sourceIPAddress,
           element_at(requestParameters, 'userName') AS targetUser
    FROM <event_data_store_id>
    WHERE eventName IN ('CreateAccessKey','CreateUser','CreateLoginProfile',
                        'AttachUserPolicy','PutUserPolicy','UpdateAssumeRolePolicy')
      AND eventTime > '2026-10-01 00:00:00'
    ORDER BY eventTime
  5. 5

    Check for defense impairment

    Look for attempts to blind logging and detection, which also tell you how seriously to trust the rest of the timeline. Key eventNames: cloudtrail:StopLogging, cloudtrail:DeleteTrail, cloudtrail:UpdateTrail and cloudtrail:PutEventSelectors (which can narrow what the trail captures, e.g. switching off data events), and guardduty:DeleteDetector or UpdateDetector (disabling threat detection). If the attacker stopped or altered the trail, your CloudTrail record has a gap from that point, so note the exact time and fall back to any organization trail, S3 access logs or GuardDuty findings that sat outside the key's reach.

  6. 6

    Scope S3 and secrets data access

    Finally, scope what data the key reached. S3 object-level access (s3:GetObject, ListObjects on specific buckets) and secretsmanager:GetSecretValue / ssm:GetParameter are the reads that constitute data exposure. S3 object-level calls are data events: they appear in CloudTrail only if a trail was explicitly configured to capture S3 data events for that bucket (they are not in management events), so if data-event logging was off you can see the bucket was listed but not which objects were read, and must say so. Record bucket names, object counts where available, and any secrets retrieved for the impact assessment.

  7. 7

    Contain: deactivate the key and remove attacker artifacts

    Deactivate (do not immediately delete) the leaked key so you preserve it for correlation, using iam:UpdateAccessKey to set it Inactive, then remove the IAM persistence found in step 4: extra access keys, created users, login profiles and policy/trust-policy changes. Rotate any secrets the key could read. If a trail was stopped, re-enable it. Confirm whether the key was long-term (AKIA, one user to clean up) or temporary (ASIA, which cannot be deactivated: revoke the role's active sessions and fix the principal that issued it). Verify no new keys or users were created that you have not accounted for.

    Deactivate the leaked key and list the user's remaining keys (AWS CLI)
    aws iam update-access-key --access-key-id AKIAEXAMPLE... \
      --status Inactive --user-name compromised-user
    
    # Then confirm no extra keys were added by the attacker:
    aws iam list-access-keys --user-name compromised-user

Where it goes wrong

  • CloudTrail Event history in the console covers only the last 90 days and only management events; for older activity or for S3 object-level reads you need the trail's S3 bucket via Athena or CloudTrail Lake.
  • S3 object-level (GetObject) activity is a data event and is recorded only if a trail enabled data events for that bucket beforehand; without it you can prove the bucket was listed but not which objects were read, and must state that limit.
  • An ASIA key is a temporary STS credential: UpdateAccessKey cannot deactivate it. Revoke the role's active sessions (the IAM console's Revoke active sessions adds a deny on aws:TokenIssueTime), then find the AssumeRole or GetSessionToken call that issued it and fix the principal behind it.
  • If the attacker called StopLogging, DeleteTrail or PutEventSelectors, your CloudTrail timeline has a gap from that moment; note the exact time and pivot to an organization trail, S3 access logs or GuardDuty findings outside the key's control.
  • A flood of AccessDenied errors is enumeration, not failure to act; it maps the key's permissions and tells you what the attacker learned, so do not dismiss denied calls as harmless noise.
  • Legitimate automation may use the same key, so filter on sourceIPAddress and userAgent to separate attacker calls from normal use before attributing activity, and deactivate rather than delete so you keep the key for correlation.

Beyond event logs

GuardDuty findings

Amazon GuardDuty in the affected account/region (and the Security Hub aggregation)

Often the first alert on a leaked key (for example anomalous API calls or calls from a Tor/anonymizing IP) and can cover activity even where the attacker tampered with the trail, since it is a separate service.

IAM Access Analyzer and last-accessed data

IAM console: the user's access advisor (service last-accessed) and Access Analyzer findings

Shows which services the principal actually used recently and whether any resource was shared externally, corroborating the CloudTrail story and helping bound impact.

Source of the leak

The git repository history, paste site, CI logs or container image where the key was exposed

Establishes when the key became exposed, which sets the start of the window you must scope in CloudTrail and may reveal other secrets leaked alongside it.

References