Detection rules › Kusto
User Sign in from different countries
'This query searches for successful user logins from different countries within 30 mins.'
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Initial Access | T1078 Valid Accounts |
Rule body kusto
id: 3094e036-e5ae-4d6e-8626-b0f86ebc71f2
name: User Sign in from different countries
description: |
'This query searches for successful user logins from different countries within 30 mins.'
severity: Medium
status: Available
requiredDataConnectors:
- connectorId: SalesforceServiceCloudCCPDefinition
dataTypes:
- SalesforceServiceCloud
queryFrequency: 1h
queryPeriod: 1h
triggerOperator: gt
triggerThreshold: 0
tactics:
- InitialAccess
relevantTechniques:
- T1078
query: |
let threshold = 2;
let Countrydb = externaldata(Network:string, geoname_id:string, continent_code:string, continent_name:string, country_iso_code:string, country_name:string)
[@"https://raw.githubusercontent.com/datasets/geoip2-ipv4/master/data/geoip2-ipv4.csv"];
let UsersLocation = SalesforceServiceCloud
| where EventType =~ 'Login' and LoginStatus=~'LOGIN_NO_ERROR'
| project TimeGenerated, TimestampDerived, ClientIp, UserId, User, UserType ;
UsersLocation
| extend Dummy=1
| extend TimestampDerived = todatetime(TimestampDerived)
| summarize count() by Hour=bin(TimestampDerived,30m), ClientIp,User, Dummy
| partition by Hour(
lookup (Countrydb|extend Dummy=1) on Dummy
| where ipv4_is_match(ClientIp, Network)
)
| summarize NumOfCountries = dcount(country_name) by User, Hour
| where NumOfCountries >= threshold
entityMappings:
- entityType: Account
fieldMappings:
- identifier: AadUserId
columnName: User
version: 1.0.4
kind: Scheduled
Stages and Predicates
Parameters
let threshold = 2;
Let binding: Countrydb
let Countrydb = externaldata(Network:string, geoname_id:string, continent_code:string, continent_name:string, country_iso_code:string, country_name:string)
[@"https://raw.githubusercontent.com/datasets/geoip2-ipv4/master/data/geoip2-ipv4.csv"];
The stages below define let UsersLocation (the rule's main pipeline source).
Stage 1: source
SalesforceServiceCloud
Stage 2: where
| where EventType =~ 'Login' and LoginStatus=~'LOGIN_NO_ERROR'
Stage 3: project
| project TimeGenerated, TimestampDerived, ClientIp, UserId, User, UserType
The stages below run on UsersLocation (the outer pipeline).
Stage 4: extend
UsersLocation
| extend Dummy=1
Stage 5: extend
| extend TimestampDerived = todatetime(TimestampDerived)
Stage 6: summarize
| summarize count() by Hour=bin(TimestampDerived,30m), ClientIp,User, Dummy
Stage 7: partition
| partition by Hour(
lookup (Countrydb|extend Dummy=1) on Dummy
| where ipv4_is_match(ClientIp, Network)
)
Stage 8: summarize
| summarize NumOfCountries = dcount(country_name) by User, Hour
Stage 9: where
| where NumOfCountries >= threshold
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.
| Field | Kind | Values |
|---|---|---|
EventType | eq |
|
LoginStatus | eq |
|
NumOfCountries | ge |
|
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.
| Field | Source |
|---|---|
Hour | summarize |
NumOfCountries | summarize |
User | summarize |