1. Resources
  2. Detection rules
  3. Device Code Phishing Against IAM Identity Center

Device Code Phishing Against IAM Identity Center detection rules

An attacker starts the IAM Identity Center device authorization flow and gets a user to approve it on the genuine AWS page. The attacker's client receives the user's token and, with it, role credentials in every assigned account.

Platform
AWS
Severity
High
Log source
AWS CloudTrail
Last updated
Rule formats
Sigmaand queries for: SplunkMicrosoft SentinelIBM QRadar
What an attacker needs
The URL of the organization's AWS access portal and a user who approves a device sign-in request that the attacker started.
Impact
An Identity Center token for the user and, through it, temporary role credentials for every account and permission set assigned to that user.
Response
End the user's active AWS access portal sessions and deny the user by its Identity Store user ID until the role sessions that were already opened have expired.
Mitigation
Teach users to refuse device approvals they did not start, and keep the AWS CLI current so that sign-in uses PKCE and device code grants become rare.
CloudTrail event
CreateToken

How the attack works

IAM Identity Center lets command-line tools sign in with the OAuth 2.0 device authorization grant. The client asks the Identity Center OIDC service to start a device authorization for the organization's AWS access portal and receives a device code, a user code and a verification address. The user opens the address in a browser, signs in and approves the request, and the client exchanges its device code for an access token with CreateToken. In device code phishing the attacker starts the flow and sends the verification link to a user with a pretext. The user signs in on the genuine AWS page, MFA included, and the token is issued to the client that started the flow, which is the attacker's.

AWS documents that such a token grants access to all AWS account entitlements assigned to the user. With it the attacker calls the AWS access portal API as that user: ListAccounts and ListAccountRoles show the accounts and permission sets, and GetRoleCredentials returns temporary credentials for each of them. CloudTrail records the token exchange as CreateToken with event source sso.amazonaws.com, the user in userIdentity.onBehalfOf.userId and the grant type in requestParameters.grantType, which is urn:ietf:params:oauth:grant-type:device_code for this flow. The start of the flow is not among the OIDC events AWS lists for CloudTrail.

What an attacker needs

  • The URL of the organization's AWS access portal, which a client sends when it starts a device authorization.
  • A way to reach a user, such as email or chat, while the verification code is valid.
  • A user who approves a sign-in request that they did not start.

Impact

An Identity Center access token for the user and, through it, temporary role credentials for every account and permission set assigned to that user. If the user is an administrator in several accounts, one approval gives the attacker administrator access across them. The access lasts for as long as the session and the role credentials obtained from it stay valid.

Detection rules

IAM Identity Center Token Issued Through the Device Code Grant

Detects successful CreateToken events of the IAM Identity Center OIDC service whose requestParameters.grantType is urn:ietf:params:oauth:grant-type:device_code. This is the token exchange at the end of a device authorization flow: a user has approved a sign-in request in a browser, and the client that started the flow receives an access token for that user. AWS publishes an example record of this event with exactly this grant type. The grant is legitimate for command-line tools on hosts without a browser and for AWS CLI versions before 2.22.0, and it is the event a device code phishing attack produces. The rule also requires responseElements.tokenType to be Bearer, as in that example record, so that only an exchange in which a token was issued raises an alert. Identify the user from userIdentity.onBehalfOf.userId and compare sourceIPAddress and userAgent with what that user normally works from.

LevelMediumStatusExperimentalLog sourceAWS CloudTrail
title: IAM Identity Center Token Issued Through the Device Code Grant
id: 7136bd88-743e-4346-9f9e-1d96355373c7
status: experimental
description: >-
  Detects successful CreateToken events of the IAM Identity Center OIDC
  service whose requestParameters.grantType is
  urn:ietf:params:oauth:grant-type:device_code. This is the token exchange at
  the end of a device authorization flow: a user has approved a sign-in
  request in a browser, and the client that started the flow receives an
  access token for that user. AWS publishes an example record of this event
  with exactly this grant type. The grant is legitimate for command-line
  tools on hosts without a browser and for AWS CLI versions before 2.22.0,
  and it is the event a device code phishing attack produces. The rule
  also requires responseElements.tokenType to be Bearer, as in that example
  record, so that only an exchange in which a token was issued raises an
  alert. Identify the user from
  userIdentity.onBehalfOf.userId and compare sourceIPAddress and userAgent
  with what that user normally works from.
references:
  - https://docs.aws.amazon.com/singlesignon/latest/userguide/understanding-sso-entries.html
  - https://docs.aws.amazon.com/singlesignon/latest/userguide/sso-info-in-cloudtrail.html
  - https://docs.aws.amazon.com/singlesignon/latest/OIDCAPIReference/API_CreateToken.html
  - https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html
  - https://attack.mitre.org/techniques/T1528/
author: Forestall
date: 2026-11-18
tags:
  - attack.credential-access
  - attack.t1528
logsource:
  product: aws
  service: cloudtrail
detection:
  selection:
    eventSource: sso.amazonaws.com
    eventName: CreateToken
    requestParameters.grantType: 'urn:ietf:params:oauth:grant-type:device_code'
    responseElements.tokenType: Bearer
  condition: selection
falsepositives:
  - Users who sign in with the AWS CLI or an IDE toolkit through device authorization, on hosts without a browser, with CLI versions before 2.22.0 or with the --use-device-code option. Move those users to a current CLI, and add the source addresses of build hosts that need the flow to a filter_* selection on sourceIPAddress.
level: medium

False positives

  • Users who sign in with the AWS CLI or an IDE toolkit through device authorization, on hosts without a browser, with CLI versions before 2.22.0 or with the --use-device-code option. Move those users to a current CLI, and add the source addresses of build hosts that need the flow to a filter_* selection on sourceIPAddress.

Detection logic

Patterns that need more than one event, a baseline or knowledge of your own environment. Each is a hypothesis to build and tune in your SIEM, not a ready rule.

Role credentials for many accounts fetched right after a device code grant

Detection hypothesisSequence of eventsNeeds a baseline

A person who signs in from a command-line tool works in one or two accounts. An attacker who has just received a token wants everything it reaches, lists the accounts and fetches role credentials for many of them within minutes.

  1. A CreateToken event from sso.amazonaws.com whose requestParameters.grantType is urn:ietf:params:oauth:grant-type:device_code. Note the user in userIdentity.onBehalfOf.userId and the sourceIPAddress.
  2. Within 60 minutes, ListAccounts, ListAccountRoles and GetRoleCredentials events from sso.amazonaws.com with the same userIdentity.onBehalfOf.userId.
  3. Count the GetRoleCredentials events and alert when there are more than the user normally produces, for example five or more within the hour.

EventsCreateTokenListAccountsListAccountRolesGetRoleCredentials

LimitsAWS publishes no example record of GetRoleCredentials, so the fields that name the account and the role have to be read from your own events. Scripts that loop over all accounts of an administrator look the same. The count and the 60 minutes are starting points.

First device code grant of a user, or a grant from a new address

Detection hypothesisNeeds a baseline

Most people either never use device authorization or use it from the same host every time. The first device code grant of a user, or one whose token exchange comes from a network the user has not worked from, is the phished flow more often than a new habit.

  1. Collect the CreateToken events from sso.amazonaws.com that carry the device code grant in requestParameters.grantType, over a few weeks.
  2. Keep, for each userIdentity.onBehalfOf.userId, the sourceIPAddress and userAgent values that were seen.
  3. Alert on the first device code grant of a user, and on a grant whose source address or user agent is new for that user.

EventsCreateToken

LimitsPeople who work from changing networks produce new addresses all the time, and a new laptop or CLI version changes the user agent. The baseline needs a few weeks of data before it is useful. An attacker who exchanges the token from an address range the user also works from does not stand out.

Triage

  • Identify the user from userIdentity.onBehalfOf.userId with the Identity Store (DescribeUser), and ask whether they started a sign-in from a command-line tool at that time.
  • Compare sourceIPAddress and userAgent of the CreateToken event with the addresses and tools the user normally works from. In a phished flow the token exchange comes from the attacker's client, not from the user's workstation.
  • Look for ListAccounts, ListAccountRoles and GetRoleCredentials events from sso.amazonaws.com for the same user after the token was issued, and note which accounts and roles were reached.
  • Check whether your organization still uses device authorization at all, for example on hosts without a browser or with older CLI versions. If it does not, every such grant is suspect.

Response

Once the attack is confirmed:

  1. End the user's active AWS access portal sessions in the IAM Identity Center console, so that the token can no longer be used to fetch role credentials.
  2. Block the role sessions that already exist. Role credentials obtained through the portal keep working until they expire, so deny the user by its Identity Store user ID in a service control policy until then.
  3. Review what the roles did in every account the attacker reached, starting from the GetRoleCredentials events, and remove what was created there, such as users, access keys, roles and trust policy changes.
  4. Reset the user's credentials at the identity source if there is any sign that more than the approval was given away.
  5. Search for other CreateToken events with the device code grant from the same source address, to find other users who approved the same lure.

Mitigation

  • Teach users that an approval page or code they did not request themselves is an attack and must be denied. The AWS CLI opens the approval page itself, so a verification link that arrives by mail or chat is not part of a normal sign-in.
  • Keep the AWS CLI at version 2.22.0 or later, where sign-in uses the authorization code flow with PKCE by default and device authorization needs the --use-device-code option. Device code grants then become rare, and each one can be reviewed.
  • Assign permission sets with least privilege and keep administrator access out of the permission sets people use every day, so that one approved request exposes less.
  • Keep the session duration of the AWS access portal and of permission sets short, to limit how long a stolen session can be used.

Frequently asked questions

Does MFA stop device code phishing against IAM Identity Center?

No. The user signs in on the genuine AWS page and completes MFA themselves, and the token is then issued to the client that started the flow, which is the attacker's client. What helps is a user who refuses an approval they did not start, together with the detection of device code grants.

Why does this rule become more useful with a current AWS CLI?

Starting with version 2.22.0 the AWS CLI signs in with the authorization code flow with PKCE by default. Device authorization is used by older versions, or when the `--use-device-code` option is given. Once your users are on a current version, a `CreateToken` event with the device code grant is uncommon and can be checked one by one.

Does CloudTrail show the moment the attacker starts the flow?

Not according to what AWS documents. The list of OIDC events that IAM Identity Center publishes for CloudTrail names `CreateToken` and `CreateTokenWithIAM`. The token exchange is therefore the first event to build on, and it is written when the user has already approved the request.

How do I find out which user a CreateToken event belongs to?

These events carry no user name. They identify the user with `userId` and `identityStoreArn` in the `onBehalfOf` element of `userIdentity`. Look the user ID up in the Identity Store, for example with `DescribeUser`, to get the user name, and accept both `IdentityCenterUser` and `Unknown` as the identity type, as AWS advises.

References

We respect your privacy

We use cookies to keep this site secure and working properly. With your permission, we also use optional cookies to understand usage and improve the experience. Cookie Policy

You can change your choice at any time.