Entra ID Primary Refresh Token Used by a Command-Line Client


Description

Identifies a Microsoft Entra ID sign-in that presents a Primary Refresh Token (PRT) from a first-party command-line or scripting client, such as Azure CLI, Azure PowerShell, Microsoft Graph PowerShell, Azure AD PowerShell, Exchange Online PowerShell, Teams PowerShell, SharePoint Online Management Shell, or Intune PowerShell. PRTs are normally redeemed by device-integrated components such as Windows sign-in, Microsoft Edge, Office, OneDrive, and the Microsoft Authentication Broker. A PRT presented through a CLI client may indicate PRT replay: an adversary with a registered device and a device-bound PRT (tools such as ROADtools enable this) can mint tokens for Microsoft Graph and other resources without interactive prompts.

Query · kuery

data_stream.dataset: "azure.signinlogs" and
azure.signinlogs.properties.incoming_token_type: "primaryRefreshToken" and
azure.signinlogs.properties.app_id: (
    "04b07795-8ddb-461a-bbee-02f9e1bf7b46" or
    "1950a258-227b-4e31-a9cf-717495945fc2" or
    "14d82eec-204b-4c2f-b7e8-296a70dab67e" or
    "1b730954-1685-4b74-9bfd-dac224a7b894" or
    "fb78d390-0c51-40cd-8e17-fdbfab77341b" or
    "12128f48-ec9e-42f0-b203-ea49fb6af367" or
    "9bc3ab49-b65d-410a-85ad-de819febfddc" or
    "d1ddf0e4-d672-4dae-b554-9d5bdfd93547"
) and event.outcome: "success"

Investigation fields

Pivot points the source recommends for triage.

  • @timestamp
  • azure.signinlogs.properties.user_principal_name
  • azure.signinlogs.properties.app_id
  • azure.signinlogs.properties.app_display_name
  • azure.signinlogs.properties.incoming_token_type
  • azure.signinlogs.properties.resource_display_name
  • azure.signinlogs.properties.session_id
  • azure.signinlogs.properties.device_detail.device_id
  • azure.signinlogs.properties.device_detail.display_name
  • azure.signinlogs.properties.device_detail.operating_system
  • azure.signinlogs.properties.device_detail.trust_type
  • azure.signinlogs.properties.device_detail.is_managed
  • azure.signinlogs.properties.device_detail.is_compliant
  • user_agent.original
  • source.ip
  • source.as.organization.name
  • source.geo.country_name

Known false positives

  • Authorized red team or penetration testing engagements that replay PRTs. Document the engagement and add exceptions on the calling user or source IP.
  • Administrators using CLI clients on Entra joined or registered devices where the Web Account Manager (WAM) broker redeems the PRT on the client's behalf. Azure CLI and Azure PowerShell with broker authentication enabled are common examples. Validate the user, device, and source before tuning.

Analyst notes

Investigating Entra ID Primary Refresh Token Used by a Command-Line Client

Entra ID issues Primary Refresh Tokens (PRTs) to registered or joined devices. They are normally redeemed by device-integrated components (Windows sign-in, Microsoft Edge, Office, OneDrive, the Microsoft Authentication Broker). This rule matches sign-ins where the incoming token is a PRT and the client is a first-party CLI or scripting application: Azure CLI (04b07795-...), Azure PowerShell (1950a258-...), Microsoft Graph PowerShell (14d82eec-...), Azure AD PowerShell (1b730954-...), Exchange Online PowerShell (fb78d390-...), Teams PowerShell (12128f48-...), SharePoint Online Management Shell (9bc3ab49-...), and Intune PowerShell (d1ddf0e4-...). This pattern can indicate PRT replay, but WAM broker authentication on a legitimate device can produce the same signal.

Possible investigation steps

  • Confirm the client and token type with azure.signinlogs.properties.app_id, app_display_name, and incoming_token_type (primaryRefreshToken).
  • Identify the user and device with azure.signinlogs.properties.user_principal_name and device_detail.device_id, device_detail.trust_type, and device_detail.is_managed. Replayed PRTs often come from Microsoft Entra registered, unmanaged devices that the user does not recognize.
  • Review azure.signinlogs.properties.resource_display_name. Microsoft Graph, Exchange Online, or SharePoint indicate the token is being used to reach data.
  • Compare source.ip, ASN, and geolocation with the user's baseline. Hosting or VPS egress raises priority, and so does a sign-in IP that differs from the device's usual network.
  • Check user_agent and device_detail.operating_system against the registered device; a mismatch suggests replay from another host.
  • Pivot to logs-azure.auditlogs-* for a recent device registration (Add device, Register device) by the same user, and to earlier sign-ins that could have seeded the registration (device code or refresh token flows).
  • Ask the user whether they ran Azure CLI, Azure PowerShell, or similar tooling at that time.

False positive analysis

  • Administrators and developers using CLI clients with WAM broker authentication on managed or registered devices. Expect a known device ID, a compliant or managed device, and a consistent source IP.
  • Authorized red team or penetration testing activity. Confirm with the engagement owner before closing.
  • If a benign pattern recurs, scope exceptions to the user and device ID rather than excluding the app.

Response and remediation

  • If the activity is not legitimate, remove the rogue device registration before revoking sessions, because device-bound PRTs survive revokeSignInSessions. List with GET /v1.0/users/{id}/registeredDevices, then remove with DELETE /v1.0/devices/{deviceObjectId}.
  • Revoke refresh tokens and sessions (POST /v1.0/users/{id}/revokeSignInSessions), reset credentials, and re-register MFA.
  • Audit other persistence created in the window: authentication methods, OAuth grants, and app credentials.
Raw source Entra ID Primary Refresh Token Used by a Command-Line Client · Elastic TOML
Esc
Published by elastic/detection-rules ↗, licensed under Elastic License 2.0 ↗. Reproduced here unmodified.
[metadata]
creation_date = "2026/11/19"
integration = ["azure"]
maturity = "production"
updated_date = "2026/11/19"

[rule]
author = ["Elastic"]
description = """
Identifies a Microsoft Entra ID sign-in that presents a Primary Refresh Token (PRT) from a first-party command-line or
scripting client, such as Azure CLI, Azure PowerShell, Microsoft Graph PowerShell, Azure AD PowerShell, Exchange Online
PowerShell, Teams PowerShell, SharePoint Online Management Shell, or Intune PowerShell. PRTs are normally redeemed by
device-integrated components such as Windows sign-in, Microsoft Edge, Office, OneDrive, and the Microsoft Authentication
Broker. A PRT presented through a CLI client may indicate PRT replay: an adversary with a registered device and a
device-bound PRT (tools such as ROADtools enable this) can mint tokens for Microsoft Graph and other resources without
interactive prompts.
"""
false_positives = [
    """
    Authorized red team or penetration testing engagements that replay PRTs. Document the engagement and add exceptions
    on the calling user or source IP.
    """,
    """
    Administrators using CLI clients on Entra joined or registered devices where the Web Account Manager (WAM) broker
    redeems the PRT on the client's behalf. Azure CLI and Azure PowerShell with broker authentication enabled are common
    examples. Validate the user, device, and source before tuning.
    """,
]
from = "now-9m"
index = ["logs-azure.signinlogs-*"]
language = "kuery"
license = "Elastic License v2"
name = "Entra ID Primary Refresh Token Used by a Command-Line Client"
note = """## Triage and analysis

### Investigating Entra ID Primary Refresh Token Used by a Command-Line Client

Entra ID issues Primary Refresh Tokens (PRTs) to registered or joined devices. They are normally redeemed by
device-integrated components (Windows sign-in, Microsoft Edge, Office, OneDrive, the Microsoft Authentication Broker).
This rule matches sign-ins where the incoming token is a PRT and the client is a first-party CLI or scripting
application: Azure CLI (`04b07795-...`), Azure PowerShell (`1950a258-...`), Microsoft Graph PowerShell (`14d82eec-...`),
Azure AD PowerShell (`1b730954-...`), Exchange Online PowerShell (`fb78d390-...`), Teams PowerShell (`12128f48-...`),
SharePoint Online Management Shell (`9bc3ab49-...`), and Intune PowerShell (`d1ddf0e4-...`). This pattern can indicate
PRT replay, but WAM broker authentication on a legitimate device can produce the same signal.

### Possible investigation steps

- Confirm the client and token type with `azure.signinlogs.properties.app_id`, `app_display_name`, and
`incoming_token_type` (`primaryRefreshToken`).
- Identify the user and device with `azure.signinlogs.properties.user_principal_name` and
`device_detail.device_id`, `device_detail.trust_type`, and `device_detail.is_managed`. Replayed PRTs often come from
Microsoft Entra registered, unmanaged devices that the user does not recognize.
- Review `azure.signinlogs.properties.resource_display_name`. Microsoft Graph, Exchange Online, or SharePoint indicate
the token is being used to reach data.
- Compare `source.ip`, ASN, and geolocation with the user's baseline. Hosting or VPS egress raises priority, and so does
a sign-in IP that differs from the device's usual network.
- Check `user_agent` and `device_detail.operating_system` against the registered device; a mismatch suggests replay
from another host.
- Pivot to `logs-azure.auditlogs-*` for a recent device registration (`Add device`, `Register device`) by the same user,
and to earlier sign-ins that could have seeded the registration (device code or refresh token flows).
- Ask the user whether they ran Azure CLI, Azure PowerShell, or similar tooling at that time.

### False positive analysis

- Administrators and developers using CLI clients with WAM broker authentication on managed or registered devices.
Expect a known device ID, a compliant or managed device, and a consistent source IP.
- Authorized red team or penetration testing activity. Confirm with the engagement owner before closing.
- If a benign pattern recurs, scope exceptions to the user and device ID rather than excluding the app.

### Response and remediation

- If the activity is not legitimate, remove the rogue device registration before revoking sessions, because device-bound
PRTs survive `revokeSignInSessions`. List with `GET /v1.0/users/{id}/registeredDevices`, then remove with
`DELETE /v1.0/devices/{deviceObjectId}`.
- Revoke refresh tokens and sessions (`POST /v1.0/users/{id}/revokeSignInSessions`), reset credentials, and re-register
MFA.
- Audit other persistence created in the window: authentication methods, OAuth grants, and app credentials.
"""
references = [
    "https://github.com/dirkjanm/ROADtools",
    "https://dirkjanm.io/abusing-azure-ad-sso-with-the-primary-refresh-token/",
    "https://dirkjanm.io/introducing-roadtools-token-exchange-roadtx/",
    "https://unit42.paloaltonetworks.com/roadtools-cloud-attacks/",
]
risk_score = 47
rule_id = "c894f171-b863-413e-adbb-7ef4844d104a"
severity = "medium"
tags = [
    "Domain: Cloud",
    "Domain: Identity",
    "Data Source: Azure",
    "Data Source: Microsoft Entra ID",
    "Data Source: Microsoft Entra ID Sign-In Logs",
    "Use Case: Identity and Access Audit",
    "Use Case: Threat Detection",
    "Tactic: Defense Evasion",
    "Tactic: Credential Access",
    "Resources: Investigation Guide",
    "Profile: Beta",
    "Rule Type: Custom Query (KQL)",
    "Platform: Entra ID",
]
timestamp_override = "event.ingested"
type = "query"

query = '''
data_stream.dataset: "azure.signinlogs" and
azure.signinlogs.properties.incoming_token_type: "primaryRefreshToken" and
azure.signinlogs.properties.app_id: (
    "04b07795-8ddb-461a-bbee-02f9e1bf7b46" or
    "1950a258-227b-4e31-a9cf-717495945fc2" or
    "14d82eec-204b-4c2f-b7e8-296a70dab67e" or
    "1b730954-1685-4b74-9bfd-dac224a7b894" or
    "fb78d390-0c51-40cd-8e17-fdbfab77341b" or
    "12128f48-ec9e-42f0-b203-ea49fb6af367" or
    "9bc3ab49-b65d-410a-85ad-de819febfddc" or
    "d1ddf0e4-d672-4dae-b554-9d5bdfd93547"
) and event.outcome: "success"
'''


[[rule.threat]]
framework = "MITRE ATT&CK"
[[rule.threat.technique]]
id = "T1528"
name = "Steal Application Access Token"
reference = "https://attack.mitre.org/techniques/T1528/"


[rule.threat.tactic]
id = "TA0006"
name = "Credential Access"
reference = "https://attack.mitre.org/tactics/TA0006/"

[[rule.threat]]
framework = "MITRE ATT&CK"
[[rule.threat.technique]]
id = "T1550"
name = "Use Alternate Authentication Material"
reference = "https://attack.mitre.org/techniques/T1550/"
[[rule.threat.technique.subtechnique]]
id = "T1550.001"
name = "Application Access Token"
reference = "https://attack.mitre.org/techniques/T1550/001/"



[rule.threat.tactic]
id = "TA0005"
name = "Defense Evasion"
reference = "https://attack.mitre.org/tactics/TA0005/"

[rule.investigation_fields]
field_names = [
    "@timestamp",
    "azure.signinlogs.properties.user_principal_name",
    "azure.signinlogs.properties.app_id",
    "azure.signinlogs.properties.app_display_name",
    "azure.signinlogs.properties.incoming_token_type",
    "azure.signinlogs.properties.resource_display_name",
    "azure.signinlogs.properties.session_id",
    "azure.signinlogs.properties.device_detail.device_id",
    "azure.signinlogs.properties.device_detail.display_name",
    "azure.signinlogs.properties.device_detail.operating_system",
    "azure.signinlogs.properties.device_detail.trust_type",
    "azure.signinlogs.properties.device_detail.is_managed",
    "azure.signinlogs.properties.device_detail.is_compliant",
    "user_agent.original",
    "source.ip",
    "source.as.organization.name",
    "source.geo.country_name",
]

Detection rules belong to the projects that publish them and remain under their own licenses. This site indexes and links to them; it claims no rights in them.