Detection rules › Kusto

User login from different countries within 3 hours (Uses Authentication Normalization)

Severity
high
Time window
3h
Group by
TargetUserId, TargetUserType, TargetUsername
Author
Ofer Shezaf
Source
github.com/Azure/Azure-Sentinel

This query searches for successful user logins from different countries within 3 hours. To use this analytics rule, make sure you have deployed the ASIM normalization parsers

MITRE ATT&CK coverage

TacticTechniques
Initial AccessT1078 Valid Accounts

Event coverage

Rule body kusto

id: 09ec8fa2-b25f-4696-bfae-05a7b85d7b9e
name: User login from different countries within 3 hours (Uses Authentication Normalization)
description: |
  'This query searches for successful user logins from different countries within 3 hours.
   To use this analytics rule, make sure you have deployed the [ASIM normalization parsers](https://aka.ms/ASimAuthentication)'
severity: High
requiredDataConnectors: []
queryFrequency: 3h
queryPeriod: 3h
triggerOperator: gt
triggerThreshold: 0
tactics:
  - InitialAccess 
relevantTechniques:
  - T1078
tags:
  - Id: 2954d424-f786-4677-9ffc-c24c44c6e7d5
    version: 1.0.0
  - Schema: ASIMAuthentication
    SchemaVersion: 0.1.0
query: |
  let timeframe = ago(3h);
  let threshold = 2;
  imAuthentication
  | where TimeGenerated > timeframe
  | where EventType == 'Logon'
      and EventResult == 'Success'
  | where isnotempty(SrcGeoCountry)
  | summarize
      StartTime        = min(TimeGenerated)
      , EndTime        = max(TimeGenerated)
      , Vendors        = make_set(EventVendor, 128)
      , Products       = make_set(EventProduct, 128)
      , NumOfCountries = dcount(SrcGeoCountry)
      , Countries      = make_set(SrcGeoCountry, 128)
      by TargetUserId, TargetUsername, TargetUserType
  | where NumOfCountries >= threshold
  | where TargetUserType !in ("Application", "Service", "System", "Other", "Machine", "ServicePrincipal")
  | extend
    Name = iif(
        TargetUsername contains "@"
            , tostring(split(TargetUsername, '@', 0)[0])
            , TargetUsername
        ),
    UPNSuffix = iif(
        TargetUsername contains "@"
        , tostring(split(TargetUsername, '@', 1)[0])
        , ""
    )
entityMappings:
  - entityType: Account
    fieldMappings:
      - identifier: FullName
        columnName: TargetUserName
      - identifier: Name
        columnName: Name
      - identifier: UPNSuffix
        columnName: UPNSuffix
version: 1.2.5
kind: Scheduled
metadata:
    source:
        kind: Community
    author:
        name: Ofer Shezaf
    support:
        tier: Community
    categories:
        domains: [ "Security - Network" ]

Stages and Predicates

Parameters

let timeframe = ago(3h);
let threshold = 2;

Stage 1: source

imAuthentication

Stage 2: where

| where TimeGenerated > timeframe

Stage 3: where

| where EventType == 'Logon'
    and EventResult == 'Success'

Stage 4: where

| where isnotempty(SrcGeoCountry)

Stage 5: summarize

| summarize
    StartTime        = min(TimeGenerated)
    , EndTime        = max(TimeGenerated)
    , Vendors        = make_set(EventVendor, 128)
    , Products       = make_set(EventProduct, 128)
    , NumOfCountries = dcount(SrcGeoCountry)
    , Countries      = make_set(SrcGeoCountry, 128)
    by TargetUserId, TargetUsername, TargetUserType
Threshold
ge 2

Stage 6: where

| where NumOfCountries >= threshold

Stage 7: where

| where TargetUserType !in ("Application", "Service", "System", "Other", "Machine", "ServicePrincipal")

Stage 8: extend

| extend
  Name = iif(
      TargetUsername contains "@"
          , tostring(split(TargetUsername, '@', 0)[0])
          , TargetUsername
      ),
  UPNSuffix = iif(
      TargetUsername contains "@"
      , tostring(split(TargetUsername, '@', 1)[0])
      , ""
  )

Exclusions

Top-level NOT(...) conjuncts: predicates this rule actively suppresses.

FieldKindExcluded values
TargetUserTypeinApplication, Machine, Other, Service, ServicePrincipal, System

Indicators

Each row is a field, operator, and value that the rule matches. The corpus column counts how many other rules in the catalog look for the same combination: high numbers point to widely-used, community-vetted indicators. Blank or 1 shows that the indicator is specific to this rule.

FieldKindValues
EventResulteq
  • Success transforms: cased corpus 2 (kusto 2)
EventTypeeq
  • Logon transforms: cased corpus 2 (kusto 2)
NumOfCountriesge
  • 2 transforms: cased corpus 3 (kusto 3)
SrcGeoCountryis_not_null
  • (no value, null check)
TimeGeneratedgt
  • timeframe transforms: cased

Output fields

Fields the rule emits when it matches. Chronicle authors list these in the outcome block; they appear on the detection and $risk_score drives alerting. Sentinel / Defender XDR rules build them up through project / summarize / extend stages. Sentinel maps these into alert fields via entityMappings and customDetails; Defender XDR custom detections surface them as alert fields directly.

FieldSource
Countriessummarize
EndTimesummarize
NumOfCountriessummarize
Productssummarize
StartTimesummarize
TargetUserIdsummarize
TargetUserTypesummarize
TargetUsernamesummarize
Vendorssummarize
Nameextend
UPNSuffixextend