← Back to SOC feed Coverage →

Spam Detections by Sender Country

kql MEDIUM Azure-Sentinel
T1566
EmailEvents
huntingmicrosoftofficial
This rule was pulled from an open-source repository and enriched with AI. Validate in a test environment before deploying to production.
View original rule at Azure-Sentinel →
Retrieved: 2026-09-03T11:00:00Z · Confidence: medium

Hunt Hypothesis

This hypothesis targets adversaries leveraging phishing campaigns (T1566) that originate from specific geographic regions to bypass initial email filters or exploit trust in certain sender locations. Proactively hunting for these patterns in Azure Sentinel allows the SOC to identify emerging spam trends or targeted phishing waves that may indicate broader compromise attempts before they result in user interaction.

KQL Query

// Inbound spam detections by sender-IP country. Country is from IP geolocation and is approximate.
EmailEvents
| where Timestamp > ago(30d)
| where OrgLevelPolicy != "Phishing simulation" and OrgLevelPolicy != "SecOps Mailbox"
| where ThreatTypes has "Spam" and isnotempty(SenderIPv4)
| extend Key = strcat(NetworkMessageId, '-', RecipientEmailAddress)
| summarize arg_max(Timestamp, *) by Key
| extend Country = tostring(geo_info_from_ip_address(SenderIPv4).country)
| where isnotempty(Country)
| summarize SpamEmails = count(), SenderIPs = dcount(SenderIPv4) by Country
| top 20 by SpamEmails
| project Country, SpamEmails, SenderIPs

Analytic Rule Definition

id: bdd60985-c235-4c74-af19-a3d77360f527
name: Spam Detections by Sender Country
description: |
  This query summarizes inbound spam detections by the geographic country of the sending IP address, using the EmailEvents table.
description-detailed: |
  Mapping spam detections to the country of the sending IP address helps identify the regions and sending infrastructure behind bulk and spam campaigns. This query resolves the sender IPv4 address to a country and counts inbound spam detections per country, with the number of distinct sending IPs. Country is derived from IP geolocation and is approximate.
  This query is part of the Microsoft Defender for Office 365 Detections and Insights workbook in Microsoft Sentinel: https://techcommunity.microsoft.com/blog/microsoftdefenderforoffice365blog/part-3-build-custom-email-security-reports-with-power-bi-and-workbooks-in-micros/4490127
requiredDataConnectors:
- connectorId: MicrosoftThreatProtection
  dataTypes:
  - EmailEvents
tactics:
  - InitialAccess
relevantTechniques:
  - T1566
query: |
  // Inbound spam detections by sender-IP country. Country is from IP geolocation and is approximate.
  EmailEvents
  | where Timestamp > ago(30d)
  | where OrgLevelPolicy != "Phishing simulation" and OrgLevelPolicy != "SecOps Mailbox"
  | where ThreatTypes has "Spam" and isnotempty(SenderIPv4)
  | extend Key = strcat(NetworkMessageId, '-', RecipientEmailAddress)
  | summarize arg_max(Timestamp, *) by Key
  | extend Country = tostring(geo_info_from_ip_address(SenderIPv4).country)
  | where isnotempty(Country)
  | summarize SpamEmails = count(), SenderIPs = dcount(SenderIPv4) by Country
  | top 20 by SpamEmails
  | project Country, SpamEmails, SenderIPs
version: 1.0.0

Required Data Sources

Sentinel TableNotes
EmailEventsEnsure this data connector is enabled

MITRE ATT&CK Context

References

False Positive Guidance

Original source: https://github.com/Azure/Azure-Sentinel/blob/main/Hunting Queries/Microsoft 365 Defender/Email and Collaboration Queries/Spam/Spam Detections by Sender Country.yaml