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.
Query · kql
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