← Back to SOC feed Coverage →

Spam detection by IP and its location

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-05-17T23:00:00Z · Confidence: medium

Hunt Hypothesis

Adversaries may use compromised IP addresses to send spam emails, leveraging geographic location data to bypass basic filtering mechanisms. SOC teams should proactively hunt for this behavior to identify potential spam campaigns and mitigate reputational and operational risks in their Azure Sentinel environment.

KQL Query

//This query visualises total emails with Spam detections summarizing the data by email sender IP address (SenderIPv4, SenderIPv6).
let ipv4position = EmailEvents
| where ThreatTypes has "Spam" 
| where TimeGenerated > ago(90d) // last 30 days by default, replace 30d with the desired period
| where SenderIPv4 != ""
| summarize count() by SenderIPv4
| extend GeoInfo = geo_info_from_ip_address(SenderIPv4)
| extend Latitude = tostring(GeoInfo.latitude), Longitude = tostring(GeoInfo.longitude)
| project SenderIPv4, Latitude, Longitude, count_;
let ipv6position = EmailEvents
| where ThreatTypes has "Spam" 
| where TimeGenerated > ago(90d) // last 30 days by default, replace 30d with the desired period
| where SenderIPv6 != ""
| summarize count() by SenderIPv6
| extend GeoInfo = geo_info_from_ip_address(SenderIPv6)
| extend Latitude = tostring(GeoInfo.latitude), Longitude = tostring(GeoInfo.longitude)
| project SenderIPv6, Latitude, Longitude, count_;
ipv4position
| union ipv6position
| project SenderIPv6, SenderIPv4, Latitude, Longitude, count_;

Analytic Rule Definition

id: fc2a1197-7ad5-43e3-83f1-0ecd5ada41ca
name: Spam detection by IP and its location
description: |
  This query visualises total emails with Spam detections summarizing the data by email sender IP address (SenderIPv4, SenderIPv6).
description-detailed: |
  This query returns total emails with Spam detections summarizing the data by email sender IP address (SenderIPv4, SenderIPv6) and its geoagraphical position in Microsoft Defender for Office 365.
  To build a graphical map please consider exporting to CSV and use tools like Power BI, Excel, or custom dashboards to plot the data on a map. 
  Taken from the the Microsoft Defender for Office 365 Detections and Insights - Microsoft Sentinel workbook.
  https://techcommunity.microsoft.com/blog/microsoftdefenderforoffice365blog/part-2-build-custom-email-security-reports-and-dashboards-with-workbooks-in-micr/4411303
requiredDataConnectors:
- connectorId: MicrosoftThreatProtection
  dataTypes:
  - EmailEvents
tactics:
  - InitialAccess
relevantTechniques:
  - T1566
query: |
  //This query visualises total emails with Spam detections summarizing the data by email sender IP address (SenderIPv4, SenderIPv6).
  let ipv4position = EmailEvents
  | where ThreatTypes has "Spam" 
  | where TimeGenerated > ago(90d) // last 30 days by default, replace 30d with the desired period
  | where SenderIPv4 != ""
  | summarize count() by SenderIPv4
  | extend GeoInfo = geo_info_from_ip_address(SenderIPv4)
  | extend Latitude = tostring(GeoInfo.latitude), Longitude = tostring(GeoInfo.longitude)
  | project SenderIPv4, Latitude, Longitude, count_;
  let ipv6position = EmailEvents
  | where ThreatTypes has "Spam" 
  | where TimeGenerated > ago(90d) // last 30 days by default, replace 30d with the desired period
  | where SenderIPv6 != ""
  | summarize count() by SenderIPv6
  | extend GeoInfo = geo_info_from_ip_address(SenderIPv6)
  | extend Latitude = tostring(GeoInfo.latitude), Longitude = tostring(GeoInfo.longitude)
  | project SenderIPv6, Latitude, Longitude, count_;
  ipv4position
  | union ipv6position
  | project SenderIPv6, SenderIPv4, Latitude, Longitude, count_;
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 Detection IP and Geo Position.yaml