Detection rules › Kusto
TI Map Email entity to Cloud App Events
Identifies compromises and attacks and detect malicious activities in one's email entity from TI
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Initial Access |
Telemetry coverage
| Platform | Record / event type |
|---|---|
| Microsoft Defender for Endpoint | CloudAppEvents action any: Cloud app activity |
Rule body
id: 0385e99c-ae45-45f4-aecf-00104485cd6b
name: TI Map Email entity to Cloud App Events
description: |
'Identifies compromises and attacks and detect malicious activities in one's email entity from TI'
severity: Medium
requiredDataConnectors:
- connectorId: MicrosoftThreatProtection
dataTypes:
- CloudAppEvents
- 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 emailregex = @'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$';
ThreatIntelIndicators
| where TimeGenerated >= ago(ioc_lookBack)
| summarize LatestIndicatorTime = arg_max(TimeGenerated, *) by Id, ObservableValue
| where IsActive and (ValidUntil > now() or isempty(ValidUntil))
//extract key part of kv pair
| extend IndicatorType = replace(@"\[|\]|\""", "", tostring(split(ObservableKey, ":", 0)))
| where IndicatorType == "email-addr"
| extend EmailSenderAddress = ObservableValue
| extend EmailSourceDomain = substring(EmailSenderAddress, indexof(EmailSenderAddress, "@") + 1, strlen(EmailSenderAddress) - indexof(EmailSenderAddress, "@") - 1)
| project-reorder *, EmailSenderAddress, EmailSourceDomain, Type
| extend IndicatorId = tostring(split(Id, "--")[2])
| join kind=innerunique (CloudAppEvents
| extend User_Id = tostring(RawEventData.UserId)
| where isnotempty(User_Id)
| where TimeGenerated >= ago(dt_lookBack) and isnotempty(Application)
| extend CloudAppEvents_TimeGenerated = TimeGenerated
| where User_Id matches regex emailregex) on $left.EmailSenderAddress == $right.User_Id
| where CloudAppEvents_TimeGenerated < ValidUntil
| summarize CloudAppEvents_TimeGenerated = argmax(CloudAppEvents_TimeGenerated, *) by IndicatorId, User_Id
| extend Name = tostring(split(User_Id, '@', 0)[0]), UPNSuffix = tostring(split(User_Id, '@', 1)[0])
| extend timestamp = CloudAppEvents_TimeGenerated
entityMappings:
- entityType: Account
fieldMappings:
- identifier: DisplayName
columnName: Name
- identifier: FullName
columnName: User_Id
- identifier: UPNSuffix
columnName: UPNSuffix
version: 1.0.8
kind: Scheduled
Stages and Predicates
Parameters
let dt_lookBack = 1h;
let ioc_lookBack = 14d;
let emailregex = @'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$';
Stage 1: source
ThreatIntelIndicators
Stage 2: where
| where TimeGenerated >= ago(ioc_lookBack)
Stage 3: summarize
| summarize LatestIndicatorTime = arg_max(TimeGenerated, *) by Id, ObservableValue
Stage 4: where
| where IsActive and (ValidUntil > now() or isempty(ValidUntil))
Stage 5: extend
| extend IndicatorType = replace(@"\[|\]|\""", "", tostring(split(ObservableKey, ":", 0)))
Stage 6: where
| where IndicatorType == "email-addr"
Stage 7: extend
| extend EmailSenderAddress = ObservableValue
Stage 8: extend
| extend EmailSourceDomain = substring(EmailSenderAddress, indexof(EmailSenderAddress, "@") + 1, strlen(EmailSenderAddress) - indexof(EmailSenderAddress, "@") - 1)
Stage 9: project-reorder
| project-reorder *, EmailSenderAddress, EmailSourceDomain, Type
Stage 10: extend
| extend IndicatorId = tostring(split(Id, "--")[2])
Stage 11: join
| join kind=innerunique (CloudAppEvents
| extend User_Id = tostring(RawEventData.UserId)
| where isnotempty(User_Id)
| where TimeGenerated >= ago(dt_lookBack) and isnotempty(Application)
| extend CloudAppEvents_TimeGenerated = TimeGenerated
| where User_Id matches regex emailregex) on $left.EmailSenderAddress == $right.User_Id
Stage 12: where
| where CloudAppEvents_TimeGenerated < ValidUntil
Stage 13: summarize
| summarize CloudAppEvents_TimeGenerated = argmax(CloudAppEvents_TimeGenerated, *) by IndicatorId, User_Id
Stage 14: extend
| extend Name = tostring(split(User_Id, '@', 0)[0]), UPNSuffix = tostring(split(User_Id, '@', 1)[0])
Stage 15: extend
| extend timestamp = CloudAppEvents_TimeGenerated
Indicators
These rows show field, operator, and value matches.
| Field | Kind | Values | Search |
|---|---|---|---|
Application | is_not_null | field:"Image" kind:is_not_null | |
CloudAppEvents_TimeGenerated | cross_field_compare |
| field:"CloudAppEvents_TimeGenerated" kind:cross_field_compare value:"ValidUntil" |
IndicatorType | eq |
| field:"IndicatorType" kind:eq value:"email-addr" |
User_Id | is_not_null | field:"User_Id" kind:is_not_null | |
User_Id | regex_match |
| field:"User_Id" kind:regex_match value:"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$" |
ValidUntil | is_null | field:"ValidUntil" kind:is_null |
Output fields
These fields are emitted when the rule matches.
| Field | Source |
|---|---|
CloudAppEvents_TimeGenerated | summarize |
IndicatorId | summarize |
User_Id | summarize |
Name | extend |
UPNSuffix | extend |
timestamp | extend |