← Back to SOC feed Coverage →

Device code authentication from unseen autonomous system

kql MEDIUM Azure-Sentinel
T1528T1078.004
SigninLogs
huntingmicrosoftofficialphishing
This rule was pulled from an open-source repository and enriched with AI. Validate in a test environment before deploying to production.
View original rule at Azure-Sentinel →
Retrieved: 2026-05-28T11:00:00Z · Confidence: medium

Hunt Hypothesis

Adversaries may be using device code authentication from an unfamiliar autonomous system to bypass multi-factor authentication and gain unauthorized access. SOC teams should proactively hunt for this behavior in Azure Sentinel to detect potential device code phishing attempts and mitigate lateral movement risks.

KQL Query

let timeframe = 1d;
let lookback = 30d;
let KnownASNPerUser =
    SigninLogs
    | where TimeGenerated >= ago(timeframe + lookback) and TimeGenerated < ago(timeframe)
    | where ResultType == 0
    | where isnotempty(AutonomousSystemNumber)
    | summarize KnownASNs = make_set(AutonomousSystemNumber, 100) by UserPrincipalName;
SigninLogs
| where TimeGenerated >= ago(timeframe)
| where ResultType == 0
| where isnotempty(AutonomousSystemNumber)
| where AuthenticationDetails has "deviceCode"
| join kind=leftouter KnownASNPerUser on UserPrincipalName
| where isnull(KnownASNs) or not(set_has_element(KnownASNs, AutonomousSystemNumber))
| extend AccountName      = tostring(split(UserPrincipalName, "@")[0])
| extend AccountUPNSuffix = tostring(split(UserPrincipalName, "@")[1])
| project
    TimeGenerated,
    UserPrincipalName,
    AccountName,
    AccountUPNSuffix,
    IPAddress,
    AutonomousSystemNumber,
    Location,
    AppDisplayName,
    AuthenticationDetails,
    DeviceDetail,
    CorrelationId
| sort by TimeGenerated desc

Analytic Rule Definition

id: 562647c0-5edb-4a47-afa2-fa662efa89bf
name: Device code authentication from unseen autonomous system
description: |
  Identifies successful device code flow sign-ins from autonomous system numbers not
  seen for the user in the previous 30 days. Consistent with device code phishing:
  attacker initiates the flow, tricks the target into completing it.
requiredDataConnectors:
  - connectorId: AzureActiveDirectory
    dataTypes:
      - SigninLogs
tactics:
  - InitialAccess
  - CredentialAccess
relevantTechniques:
  - T1528
  - T1078.004
query: |
  let timeframe = 1d;
  let lookback = 30d;
  let KnownASNPerUser =
      SigninLogs
      | where TimeGenerated >= ago(timeframe + lookback) and TimeGenerated < ago(timeframe)
      | where ResultType == 0
      | where isnotempty(AutonomousSystemNumber)
      | summarize KnownASNs = make_set(AutonomousSystemNumber, 100) by UserPrincipalName;
  SigninLogs
  | where TimeGenerated >= ago(timeframe)
  | where ResultType == 0
  | where isnotempty(AutonomousSystemNumber)
  | where AuthenticationDetails has "deviceCode"
  | join kind=leftouter KnownASNPerUser on UserPrincipalName
  | where isnull(KnownASNs) or not(set_has_element(KnownASNs, AutonomousSystemNumber))
  | extend AccountName      = tostring(split(UserPrincipalName, "@")[0])
  | extend AccountUPNSuffix = tostring(split(UserPrincipalName, "@")[1])
  | project
      TimeGenerated,
      UserPrincipalName,
      AccountName,
      AccountUPNSuffix,
      IPAddress,
      AutonomousSystemNumber,
      Location,
      AppDisplayName,
      AuthenticationDetails,
      DeviceDetail,
      CorrelationId
  | sort by TimeGenerated desc
entityMappings:
  - entityType: Account
    fieldMappings:
      - identifier: FullName
        columnName: UserPrincipalName
      - identifier: Name
        columnName: AccountName
      - identifier: UPNSuffix
        columnName: AccountUPNSuffix
  - entityType: IP
    fieldMappings:
      - identifier: Address
        columnName: IPAddress
version: 1.0.0
metadata:
    source:
        kind: Community
    author:
        name: descambiado
    support:
        tier: Community
    categories:
        domains: [ "Security - Threat Protection", "Identity" ]

Required Data Sources

Sentinel TableNotes
SigninLogsEnsure this data connector is enabled

MITRE ATT&CK Context

References

False Positive Guidance

Original source: https://github.com/Azure/Azure-Sentinel/blob/main/Hunting Queries/MultipleDataSources/DeviceCodeSignInFromUnseenASN.yaml