Detection rules › Kusto
Dataverse - Terminated employee exfiltration over email
This query identifies Dataverse exfiltration via email by terminated employees.
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Exfiltration | |
| Exfiltration |
Telemetry coverage
| Platform | Record / event type |
|---|---|
| Microsoft Defender for Endpoint | EmailEvents action any: Email processed |
Rule body
id: de039242-47e0-43fa-84d7-b6be24305349
kind: Scheduled
name: Dataverse - Terminated employee exfiltration over email
description: This query identifies Dataverse exfiltration via email by terminated
employees.
severity: High
status: Available
requiredDataConnectors:
- connectorId: MicrosoftThreatProtection
dataTypes:
- EmailEvents
- connectorId: AzureActiveDirectoryIdentityProtection
dataTypes:
- SecurityAlert
- connectorId: IdentityInfo
dataTypes:
- IdentityInfo
queryFrequency: 1h
queryPeriod: 14d
triggerOperator: gt
triggerThreshold: 0
tactics:
- Exfiltration
relevantTechniques:
- T1639
- T1567
query: |
// Note this detection relies upon the user's UPN matching their email address.
// UEBA can provide more accurate data if enabled.
let query_frequency = 1h;
let allowed_destination_smtp_domains = dynamic([
// Specify a list of recipient domains to exclude from alerting.
// Example:
// "microsoft.com", "contoso.com"
]);
let exfiltration_alert_users = SecurityAlert
| where Tactics has 'Exfiltration' and Entities has_all ('account', '32780')
| mv-expand DataverseEntities = todynamic(Entities)
| where DataverseEntities.AppId == 32780
| extend InstanceUrl = tostring(DataverseEntities.InstanceName)
| mv-expand AccountEntities = todynamic(Entities)
| where AccountEntities.Type == 'account'
| extend
AccountName = tostring(AccountEntities.Name),
UPNSuffix = tostring(AccountEntities.UPNSuffix)
| summarize InstanceUrls = make_set(InstanceUrl, 100) by AccountName, UPNSuffix
| extend UserId = tolower(strcat(AccountName, "@", UPNSuffix));
exfiltration_alert_users
| join kind=inner (
MSBizAppsTerminatedEmployees
| project UserId = tolower(UserPrincipalName), NotificationDate
| where startofday(NotificationDate) <= startofday(now()))
// Uncomment the below KQL if UEBA is available to gain more accurate
// email address data:
// | join kind=leftouter (_ASIM_IdentityInfo) on $left.UserId == $right.Username
// | extend UserId = iif(UserId == UserMailAddress or isempty(UserMailAddress), UserId, UserMailAddress))
on UserId
| join kind=inner (
EmailEvents
| where TimeGenerated >= ago (query_frequency)
| where EmailDirection == "Outbound" and AttachmentCount > 0
| extend RecipientDomain = tolower(split(RecipientEmailAddress, '@')[1])
| where RecipientDomain !in (allowed_destination_smtp_domains)
| summarize
RecipientAddresses = make_set(RecipientEmailAddress, 1000),
Subject = make_set(Subject, 1000)
by SenderAddress = tolower(SenderMailFromAddress), SenderIPv4)
on $left.UserId == $right.SenderAddress
| mv-expand InstanceUrl = InstanceUrls to typeof(string)
| extend
CloudAppId = int(32780),
AccountName = tostring(split(UserId, "@")[0]),
UPNSuffix = tostring(split(UserId, "@")[1])
| project
UserId,
InstanceUrl,
SenderIPv4,
RecipientAddresses,
Subject,
AccountName,
UPNSuffix,
CloudAppId
eventGroupingSettings:
aggregationKind: AlertPerResult
entityMappings:
- entityType: Account
fieldMappings:
- identifier: Name
columnName: AccountName
- identifier: UPNSuffix
columnName: UPNSuffix
- entityType: IP
fieldMappings:
- identifier: Address
columnName: SenderIPv4
- entityType: CloudApplication
fieldMappings:
- identifier: AppId
columnName: CloudAppId
- identifier: InstanceName
columnName: InstanceUrl
alertDetailsOverride:
alertDisplayNameFormat: Email attachment sent externally by terminated user following
Dataverse exfiltration alerts
alertDescriptionFormat: 'Departing or terminated user {{UserId}} was found to send
email to external domains not on the allowed list: {{RecipientAddresses}}'
version: 3.2.0
Stages and Predicates
Parameters
let query_frequency = 1h;
let exfiltration_alert_users is inlined into the numbered stages below.
Let binding: allowed_destination_smtp_domains
let allowed_destination_smtp_domains = dynamic([
]);
Stages 1 to 10 define let exfiltration_alert_users (the rule's main pipeline source); stages 11 to 15 run on it.
Stage 1: source
SecurityAlert
Stage 2: where
| where Tactics has 'Exfiltration' and Entities has_all ('account', '32780')
Stage 3: mv-expand
| mv-expand DataverseEntities = todynamic(Entities)
Stage 4: where
| where DataverseEntities.AppId == 32780
Stage 5: extend
| extend InstanceUrl = tostring(DataverseEntities.InstanceName)
Stage 6: mv-expand
| mv-expand AccountEntities = todynamic(Entities)
Stage 7: where
| where AccountEntities.Type == 'account'
Stage 8: extend
| extend
AccountName = tostring(AccountEntities.Name),
UPNSuffix = tostring(AccountEntities.UPNSuffix)
Stage 9: summarize
| summarize InstanceUrls = make_set(InstanceUrl, 100) by AccountName, UPNSuffix
Stage 10: extend
| extend UserId = tolower(strcat(AccountName, "@", UPNSuffix))
Stage 11: join
exfiltration_alert_users
| join kind=inner (
MSBizAppsTerminatedEmployees
| project UserId = tolower(UserPrincipalName), NotificationDate
| where startofday(NotificationDate) <= startofday(now()))
on UserId
Stage 12: join
| join kind=inner (
EmailEvents
| where TimeGenerated >= ago (query_frequency)
| where EmailDirection == "Outbound" and AttachmentCount > 0
| extend RecipientDomain = tolower(split(RecipientEmailAddress, '@')[1])
| where RecipientDomain !in (allowed_destination_smtp_domains)
| summarize
RecipientAddresses = make_set(RecipientEmailAddress, 1000),
Subject = make_set(Subject, 1000)
by SenderAddress = tolower(SenderMailFromAddress), SenderIPv4)
on $left.UserId == $right.SenderAddress
Stage 13: mv-expand
| mv-expand InstanceUrl = InstanceUrls to typeof(string)
Stage 14: extend
| extend
CloudAppId = int(32780),
AccountName = tostring(split(UserId, "@")[0]),
UPNSuffix = tostring(split(UserId, "@")[1])
Stage 15: project
| project
UserId,
InstanceUrl,
SenderIPv4,
RecipientAddresses,
Subject,
AccountName,
UPNSuffix,
CloudAppId
Exclusions
The rule actively suppresses these predicates.
| Field | Kind | Excluded values | Search |
|---|---|---|---|
RecipientDomain | eq | [] | excludes:RecipientDomain field:"RecipientDomain" value:"[]" |
Indicators
These rows show field, operator, and value matches.
| Field | Kind | Values | Search |
|---|---|---|---|
AppId | eq |
| field:"AppId" kind:eq value:"32780" |
AttachmentCount | gt |
| field:"AttachmentCount" kind:gt value:"0" |
EmailDirection | eq |
| field:"EmailDirection" kind:eq value:"Outbound" |
Entities | match |
| field:"Entities" kind:match |
Tactics | match |
| field:"Tactics" kind:match value:"Exfiltration" |
Type | eq |
| field:"Type" kind:eq value:"account" |
Output fields
These fields are emitted when the rule matches.
| Field | Source |
|---|---|
AccountName | project |
CloudAppId | project |
InstanceUrl | project |
RecipientAddresses | project |
SenderIPv4 | project |
Subject | project |
UPNSuffix | project |
UserId | project |