Detection rules › Kusto
TI Map Domain entity to EmailEvents
Identifies a match in EmailEvents table from any Domain IOC from TI
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Initial Access |
Telemetry coverage
| Platform | Record / event type |
|---|---|
| Microsoft Defender for Endpoint | EmailEvents action any: Email processed |
Rule body
id: bc3bb047-70b8-4a4b-ac21-e3b1172881a4
name: TI Map Domain entity to EmailEvents
description: |
Identifies a match in EmailEvents table from any Domain IOC from TI
severity: Medium
requiredDataConnectors:
- connectorId: MicrosoftThreatProtection
dataTypes:
- EmailEvents
- connectorId: ThreatIntelligence
dataTypes:
- ThreatIntelIndicators
- connectorId: ThreatIntelligenceTaxii
dataTypes:
- ThreatIntelIndicators
- connectorId: MicrosoftDefenderThreatIntelligence
dataTypes:
- ThreatIntelIndicators
queryFrequency: 1h
queryPeriod: 14d
triggerOperator: gt
triggerThreshold: 0
tactics:
- InitialAccess
relevantTechniques:
- T1566
query: |
let dt_lookBack = 1h;
let ioc_lookBack = 14d;
let EmailEvents_ = materialize(EmailEvents | where isnotempty(RecipientEmailAddress) and isnotempty(SenderFromAddress) and TimeGenerated >= ago(dt_lookBack) and DeliveryAction !has "Blocked" | project-rename EmailEvents_TimeGenerated = TimeGenerated | extend SenderFromDomain = tolower(SenderFromDomain) | extend RecipientEmailDomain = tolower(tostring(split(RecipientEmailAddress, '@', 1))));
let SenderDomains = EmailEvents_ | distinct SenderFromDomain | summarize make_list(SenderFromDomain);
let RecipientDomains = EmailEvents_ | distinct RecipientEmailDomain | summarize make_list(RecipientEmailDomain);
let TI = materialize(ThreatIntelIndicators
| where TimeGenerated >= ago(ioc_lookBack)
| extend IndicatorType = replace(@"\[|\]|\""", "", tostring(split(ObservableKey, ":", 0)))
| where IndicatorType == "domain-name"
| extend DomainName = tolower(ObservableValue)
| extend TrafficLightProtocolLevel = tostring(parse_json(AdditionalFields).TLPLevel)
| extend IndicatorId = tostring(split(Id, "--")[2])
| where DomainName in (SenderDomains) or DomainName in (RecipientDomains)
| summarize LatestIndicatorTime = arg_max(TimeGenerated, *) by Id, ObservableValue
| where IsActive and (ValidUntil > now() or isempty(ValidUntil))
| extend Description = tostring(parse_json(Data).description)
| where Description !contains_cs "State: inactive;" and Description !contains_cs "State: falsepos;");
(union
(TI | join kind=innerunique (EmailEvents_) on $left.DomainName == $right.SenderFromDomain),
(TI | join kind=innerunique (EmailEvents_) on $left.DomainName == $right.RecipientEmailDomain))
| where EmailEvents_TimeGenerated < ValidUntil
| extend ActivityGroupNames = extract("ActivityGroup:([^,]+)", 1, tostring(parse_json(Data).labels))
| summarize EmailEvents_TimeGenerated = arg_max(EmailEvents_TimeGenerated, *) by Id, RecipientEmailAddress
| project EmailEvents_TimeGenerated, Description, ActivityGroupNames, Id, ValidUntil, Confidence, DomainName, RecipientEmailAddress, SenderFromAddress, Subject, ConfidenceLevel, Type, TrafficLightProtocolLevel, DeliveryAction, DeliveryLocation, EmailDirection
| extend Name = tostring(split(RecipientEmailAddress, '@', 0)[0]), UPNSuffix = tostring(split(RecipientEmailAddress, '@', 1)[0])
| extend timestamp = EmailEvents_TimeGenerated
entityMappings:
- entityType: Account
fieldMappings:
- identifier: FullName
columnName: RecipientEmailAddress
- identifier: Name
columnName: Name
- identifier: UPNSuffix
columnName: UPNSuffix
version: 1.0.5
kind: Scheduled
Stages and Predicates
Stage 0: let
let dt_lookBack = 1h;
let ioc_lookBack = 14d;
let EmailEvents_ = materialize(EmailEvents | where isnotempty(RecipientEmailAddress) and isnotempty(SenderFromAddress) and TimeGenerated >= ago(dt_lookBack) and DeliveryAction !has "Blocked" | project-rename EmailEvents_TimeGenerated = TimeGenerated | extend SenderFromDomain = tolower(SenderFromDomain) | extend RecipientEmailDomain = tolower(tostring(split(RecipientEmailAddress, '@', 1))));
let SenderDomains = EmailEvents_ | distinct SenderFromDomain | summarize make_list(SenderFromDomain);
let RecipientDomains = EmailEvents_ | distinct RecipientEmailDomain | summarize make_list(RecipientEmailDomain);
let TI = materialize(<inlined as stages below>);
Stage 1: source
let EmailEvents_
Stage 2: source
let SenderDomains
Stage 3: source
let RecipientDomains
Stage 4: union
union of 2 branches
Stage 5: source
ThreatIntelIndicators
Stage 6: where
where TimeGenerated >= ago(1209600s)
Stage 7: extend
extend IndicatorType
Stage 8: where
where IndicatorType =~ "domain-name"
Stage 9: extend (3 consecutive steps)
extend DomainName, IndicatorId, TrafficLightProtocolLevel
Stage 10: where
where (DomainName =~ "RecipientDomains" or DomainName =~ "SenderDomains")
Stage 11: summarize
summarize LatestIndicatorTime by Id, ObservableValue
Stage 12: where
where (isempty(ValidUntil) or ValidUntil > now())
Stage 13: extend
extend Description
Stage 14: where
where not (Description contains "State: falsepos;") and not (Description contains "State: inactive;")
Stage 15: join
join kind=innerunique (EmailEvents_) on DomainName, SenderFromDomain
Stage 16: source
ThreatIntelIndicators
Stage 17: where
where TimeGenerated >= ago(1209600s)
Stage 18: extend
extend IndicatorType
Stage 19: where
where IndicatorType =~ "domain-name"
Stage 20: extend (3 consecutive steps)
extend DomainName, IndicatorId, TrafficLightProtocolLevel
Stage 21: where
where (DomainName =~ "RecipientDomains" or DomainName =~ "SenderDomains")
Stage 22: summarize
summarize LatestIndicatorTime by Id, ObservableValue
Stage 23: where
where (isempty(ValidUntil) or ValidUntil > now())
Stage 24: extend
extend Description
Stage 25: where
where not (Description contains "State: falsepos;") and not (Description contains "State: inactive;")
Stage 26: join
join kind=innerunique (EmailEvents_) on DomainName, RecipientEmailDomain
Stage 27: where
where EmailEvents_TimeGenerated < ValidUntil
Stage 28: extend
extend ActivityGroupNames
Stage 29: summarize
summarize EmailEvents_TimeGenerated by Id, RecipientEmailAddress
Stage 30: project
project ActivityGroupNames, Confidence, ConfidenceLevel, DeliveryAction, DeliveryLocation, Description, DomainName, EmailDirection, EmailEvents_TimeGenerated, Id, RecipientEmailAddress, SenderFromAddress, Subject, TrafficLightProtocolLevel, Type, ValidUntil
Stage 31: extend
extend Name, UPNSuffix
Stage 32: extend
extend timestamp
Indicators
These rows show field, operator, and value matches.
| Field | Kind | Values | Search |
|---|---|---|---|
DomainName | in |
| field:"DomainName" kind:in |
EmailEvents_TimeGenerated | cross_field_compare |
| field:"EmailEvents_TimeGenerated" kind:cross_field_compare value:"ValidUntil" |
IndicatorType | eq |
| field:"IndicatorType" kind:eq value:"domain-name" |
RecipientEmailAddress | is_not_null | field:"RecipientEmailAddress" kind:is_not_null | |
SenderFromAddress | is_not_null | field:"SenderFromAddress" kind:is_not_null | |
ValidUntil | is_null | field:"ValidUntil" kind:is_null |
Exclusions
The rule actively suppresses these predicates.
| Field | Kind | Excluded values | Search |
|---|---|---|---|
Description | contains | State: falsepos; | excludes:Description field:"Description" value:"State: falsepos;" |
Description | contains | State: inactive; | excludes:Description field:"Description" value:"State: inactive;" |
DeliveryAction | match | Blocked | excludes:DeliveryAction field:"DeliveryAction" value:"Blocked" |
Output fields
These fields are emitted when the rule matches.
| Field | Source |
|---|---|
ActivityGroupNames | project |
Confidence | project |
ConfidenceLevel | project |
DeliveryAction | project |
DeliveryLocation | project |
Description | project |
DomainName | project |
EmailDirection | project |
EmailEvents_TimeGenerated | project |
Id | project |
RecipientEmailAddress | project |
SenderFromAddress | project |
Subject | project |
TrafficLightProtocolLevel | project |
Type | project |
ValidUntil | project |
Name | extend |
UPNSuffix | extend |
timestamp | extend |