Detection rules › Kusto

TI map Domain entity to EmailEvents

Severity
medium
Time window
14d
Group by
IndicatorId, RecipientEmailAddress, RecipientEmailDomain, SenderFromDomain, TI_Domain
Source
github.com/Azure/Azure-Sentinel

Identifies a match in EmailEvents table from any Domain IOC from TI

MITRE ATT&CK coverage

TacticTechniques
Initial Access

Telemetry coverage

Rule body

id: 96307710-8bb9-4b45-8363-a90c72ebf86f
name: TI map Domain entity to EmailEvents
description: |
  Identifies a match in EmailEvents table from any Domain IOC from TI
severity: Medium
requiredDataConnectors:
  - connectorId: Office365
    dataTypes:
      - EmailEvents
  - connectorId: ThreatIntelligence
    dataTypes:
      - ThreatIntelligenceIndicator
  - connectorId: ThreatIntelligenceTaxii
    dataTypes:
      - ThreatIntelligenceIndicator
  - connectorId: MicrosoftDefenderThreatIntelligence
    dataTypes:
      - ThreatIntelligenceIndicator
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(ThreatIntelligenceIndicator
  | where TimeGenerated >= ago(ioc_lookBack)
  | where isnotempty(DomainName)
  | extend TI_Domain = tolower(DomainName)
  | where TI_Domain in (SenderDomains) or TI_Domain in (RecipientDomains)
  | summarize LatestIndicatorTime = arg_max(TimeGenerated, *) by IndicatorId
  | where Active == true and ExpirationDateTime > now()
  | where Description !contains_cs "State: inactive;" and Description !contains_cs "State: falsepos;");
  (union
    (TI | join kind=innerunique (EmailEvents_) on $left.TI_Domain == $right.SenderFromDomain),
    (TI | join kind=innerunique (EmailEvents_) on $left.TI_Domain == $right.RecipientEmailDomain))
  | where EmailEvents_TimeGenerated < ExpirationDateTime
  | summarize EmailEvents_TimeGenerated = arg_max(EmailEvents_TimeGenerated, *) by IndicatorId, RecipientEmailAddress
  | project EmailEvents_TimeGenerated, Description, ActivityGroupNames, IndicatorId, ThreatType, ExpirationDateTime, ConfidenceScore, DomainName, RecipientEmailAddress, SenderFromAddress, Subject, ConfidenceLevel, Url, Type, TI_Domain, 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.2
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

ThreatIntelligenceIndicator

Stage 6: where

where TimeGenerated >= ago(1209600s)

Stage 7: where

where isnotempty(DomainName)

Stage 8: extend

extend TI_Domain

Stage 9: where

where (TI_Domain =~ "RecipientDomains" or TI_Domain =~ "SenderDomains")

Stage 10: summarize

summarize LatestIndicatorTime by IndicatorId

Stage 11: where

where Active =~ true

Stage 12: where

where not (Description contains "State: falsepos;") and not (Description contains "State: inactive;")

Stage 13: join

join kind=innerunique (EmailEvents_) on TI_Domain, SenderFromDomain

Stage 14: source

ThreatIntelligenceIndicator

Stage 15: where

where TimeGenerated >= ago(1209600s)

Stage 16: where

where isnotempty(DomainName)

Stage 17: extend

extend TI_Domain

Stage 18: where

where (TI_Domain =~ "RecipientDomains" or TI_Domain =~ "SenderDomains")

Stage 19: summarize

summarize LatestIndicatorTime by IndicatorId

Stage 20: where

where Active =~ true

Stage 21: where

where not (Description contains "State: falsepos;") and not (Description contains "State: inactive;")

Stage 22: join

join kind=innerunique (EmailEvents_) on TI_Domain, RecipientEmailDomain

Stage 23: where

where EmailEvents_TimeGenerated < ExpirationDateTime

Stage 24: summarize

summarize EmailEvents_TimeGenerated by IndicatorId, RecipientEmailAddress

Stage 25: project

project ActivityGroupNames, ConfidenceLevel, ConfidenceScore, DeliveryAction, DeliveryLocation, Description, DomainName, EmailDirection, EmailEvents_TimeGenerated, ExpirationDateTime, IndicatorId, RecipientEmailAddress, SenderFromAddress, Subject, TI_Domain, ThreatType, TrafficLightProtocolLevel, Type, Url

Stage 26: extend

extend Name, UPNSuffix

Stage 27: extend

extend timestamp

Indicators

These rows show field, operator, and value matches.

Exclusions

The rule actively suppresses these predicates.

FieldKindExcluded valuesSearch
DescriptioncontainsState: falsepos;excludes:Description field:"Description" value:"State: falsepos;"
DescriptioncontainsState: inactive;excludes:Description field:"Description" value:"State: inactive;"
DeliveryActionmatchBlockedexcludes:DeliveryAction field:"DeliveryAction" value:"Blocked"

Output fields

These fields are emitted when the rule matches.

FieldSource
ActivityGroupNamesproject
ConfidenceLevelproject
ConfidenceScoreproject
DeliveryActionproject
DeliveryLocationproject
Descriptionproject
DomainNameproject
EmailDirectionproject
EmailEvents_TimeGeneratedproject
ExpirationDateTimeproject
IndicatorIdproject
RecipientEmailAddressproject
SenderFromAddressproject
Subjectproject
TI_Domainproject
ThreatTypeproject
TrafficLightProtocolLevelproject
Typeproject
Urlproject
Nameextend
UPNSuffixextend
timestampextend