Microsoft Defender β’ KQL β’ Threat Hunting β’ Complete Guide
Microsoft Defender KQL Threat Hunting Complete Guide
This is the practical hub for Microsoft Defender KQL threat hunting across email, identity, endpoint and cloud activity.
Use these Defender XDR queries to investigate EmailEvents, DMARC failures, URL clicks, suspicious sign-ins, endpoint behaviour and post-delivery activity.
The goal is simple: move beyond alert chasing and use KQL to prove what happened, who was affected, and what to check next.
A central Microsoft Defender KQL threat hunting guide for analysts, administrators and business owners who want to understand what the security data is really showing.
EmailEvents, AuthenticationDetails and UrlClickEvents
Identity, endpoint and cloud activity pivots
Real investigation flow, not just isolated queries
π¨ What this means for your environment
Even if there are no high severity alerts:
β’ Suspicious email may already have been delivered
β’ Users may have clicked links without a major incident being raised
β’ Identity and endpoint behaviour may contain the missing evidence
π This is why threat hunting matters β the logs often know before the alerts do
Microsoft Defender KQL threat hunting uses Defender XDR telemetry across EmailEvents,
UrlClickEvents, IdentityLogonEvents, DeviceProcessEvents and CloudAppEvents to investigate
suspicious activity, validate alerts and uncover evidence that traditional dashboards may miss.
What you'll learn on this page
Use this complete guide as a Defender XDR hunting path. Start with email evidence, then pivot into clicks, identity, endpoint behaviour, cloud activity and response decisions.
KQL threat hunting is the process of asking security questions directly of your Microsoft Defender data. Instead of waiting for an alert, you query behaviour across email, identity, endpoint and cloud activity to find patterns that should not exist.
Start with behaviourSomething looks unusual: a sender mismatch, a DMARC failure, a click, a strange sign-in, or an endpoint command line.
Ask a better questionDid this user normally do this? Was the email really trusted? Did the click lead to identity or device activity?
Follow the evidenceKQL lets you move from one signal to the next: message β recipient β click β sign-in β endpoint β response.
How to read these KQL queries
The real value is not just copying a query. The real value is knowing what the result means, what is normal, what is suspicious, and where to pivot next.
What the query findsEach query is designed to surface a behaviour: sender mismatch, authentication failure, click activity, sign-in activity or suspicious process execution.
What to look forLook for delivered messages, repeated subjects, unfamiliar domains, unusual IP addresses, unexpected applications or activity outside normal hours.
When to investigateIf the behaviour does not match the user, the sender, the device, the time or the business process, dig deeper.
Email threat hunting: sender mismatch and spoofing
Email spoofing often starts with a trust problem: the address the user sees does not match the underlying sending path. This query surfaces visible sender and envelope sender mismatches in EmailEvents.
email-sender-alignment-threat-hunt.kql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
EmailEvents
| where Timestamp > ago(30d)
| where SenderFromDomain != SenderMailFromDomain
| project
Timestamp,
SenderFromAddress,
SenderFromDomain,
SenderMailFromAddress,
SenderMailFromDomain,
RecipientEmailAddress,
Subject,
AuthenticationDetails,
DeliveryAction,
NetworkMessageId
| order by Timestamp desc
What this findsMessages where the visible sender domain does not match the Mail From domain.
Why it mattersMismatch is not always malicious, but it becomes important when combined with failed authentication, trusted branding or delivery.
Best next stepCheck AuthenticationDetails, DeliveryAction, recipient spread and URL click activity.
DMARC failures deserve context. A failed DMARC result may be normal third-party sending, broken forwarding, poor alignment, or a spoofing attempt. The key is to understand delivery, recipients and user interaction.
dmarc-failures-threat-hunt.kql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
EmailEvents
| where Timestamp > ago(30d)
| where AuthenticationDetails has "dmarc=fail"
| project
Timestamp,
SenderFromAddress,
SenderFromDomain,
SenderMailFromDomain,
RecipientEmailAddress,
Subject,
AuthenticationDetails,
DeliveryAction,
NetworkMessageId
| order by Timestamp desc
What this findsMessages where AuthenticationDetails contains dmarc=fail.
What to checkDeliveryAction, SenderFromDomain, SenderMailFromDomain, subject, recipient and NetworkMessageId.
Best pivotMove to URL clicks if the message was delivered or looked trusted.
A suspicious email is one thing. A suspicious email with a user click changes the risk. This query joins suspicious message telemetry to UrlClickEvents using NetworkMessageId.
email-to-url-click-threat-hunt.kql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
let SuspiciousMessages =
EmailEvents
| where Timestamp > ago(30d)
| where AuthenticationDetails has_any ("dmarc=fail", "spf=fail", "dkim=fail", "spoof")
| project NetworkMessageId, EmailTime = Timestamp, SenderFromAddress, RecipientEmailAddress, Subject, DeliveryAction;
SuspiciousMessages
| join kind=inner (
UrlClickEvents
| where Timestamp > ago(30d)
| project NetworkMessageId, ClickTime = Timestamp, AccountUpn, Url, ActionType
) on NetworkMessageId
| order by ClickTime desc
What this findsUsers who interacted with suspicious or failed-authentication messages.
What to reviewClickAllowed, blocked clicks, suspicious domains, repeated clicks and timing after delivery.
Next stepUse the AccountUpn and ClickTime to review sign-ins and device activity.
Identity threat hunting after a click
After a user clicks, the next question is whether their identity behaviour changed. This query connects click activity to sign-in activity around the same time window.
click-to-identity-threat-hunt.kql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
let ClickedUsers =
UrlClickEvents
| where Timestamp > ago(7d)
| where ActionType has_any ("ClickAllowed", "UrlScanInProgress")
| project AccountUpn, ClickTime = Timestamp, Url;
ClickedUsers
| join kind=inner (
IdentityLogonEvents
| where Timestamp > ago(7d)
| project AccountUpn, SignInTime = Timestamp, IPAddress, Location, Application, LogonType
) on AccountUpn
| where SignInTime between ((ClickTime - 2h) .. (ClickTime + 6h))
| order by ClickTime desc
What this findsSign-ins around the same time as a suspicious click.
What to look forNew locations, unfamiliar IPs, unexpected applications or timing that does not match the user.
Best next stepReview Conditional Access, MFA behaviour, session activity and device signals.
Not every incident starts with malware. Sometimes the first useful signal is file activity that does not match the userβs normal working pattern.
after-hours-file-activity-threat-hunt.kql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
CloudAppEvents
| where Timestamp > ago(14d)
| where ActionType has_any ("FileDownloaded", "FileAccessed")
| extend HourOfDay = datetime_part("hour", Timestamp)
| where HourOfDay < 6 or HourOfDay > 20
| project
Timestamp,
AccountDisplayName,
AccountId,
IPAddress,
Application,
ActionType,
ObjectName
| order by Timestamp desc
What this findsFile downloads or access events outside expected business hours.
Why it mattersData access behaviour can reveal compromise or insider risk even when malware is not present.
Best pivotCompare IP address, location, device, file sensitivity and user history.
Defender XDR Tables Used In This Guide
These are the primary Microsoft Defender XDR tables referenced throughout this investigation workflow.
Table
Purpose
EmailEvents
Email delivery and authentication analysis
UrlClickEvents
User interaction with email links
IdentityLogonEvents
Authentication and sign-in investigations
DeviceProcessEvents
Process execution and endpoint behaviour
CloudAppEvents
Cloud activity and file access
PostDeliveryEvents
Post-delivery remediation and message actions
The real investigation flow
The strongest investigations do not stop at one query. They follow the evidence across Microsoft Defender and Microsoft 365 until the activity makes sense.
1. EmailStart with delivery, sender alignment, DMARC, SPF, DKIM and message metadata.
2. ClickCheck whether the message led to user interaction through UrlClickEvents.
3. IdentityReview sign-ins, sessions, IP address, location and application use after interaction.
4. EndpointLook for unusual process execution, suspicious scripts and device-level behaviour.
6. ResponseDecide whether this is benign, misconfiguration, suspicious activity or confirmed compromise.
What dashboards miss
Most organisations already have the tools. But they struggle to interpret the data. Modern Microsoft security investigations often fail because teams focus only on high severity alerts while ignoring the quieter telemetry surrounding delivery, authentication, clicks and identity behaviour.
Low severity does not mean low riskA delivered phishing email, informational alert or unusual sign-in may still become a major compromise when correlated together.
Delivered messages matterMany investigations stop once spoofing or DMARC failures are identified. The more important question is whether the message reached the user and triggered interaction.
Correlation changes the storyEmailEvents, UrlClickEvents, IdentityLogonEvents and endpoint telemetry together reveal far more than any single alert ever could.
Understanding AuthenticationDetails
AuthenticationDetails is one of the most important fields in Microsoft Defender XDR email investigations. It explains how the message authenticated, whether alignment failed, and whether the sender identity should be trusted.
SPF, DKIM and DMARCAuthenticationDetails often contains the real evidence behind email trust failures including spf=fail, dkim=fail and dmarc=fail.
DMARC fail does not always mean blockedMessages can still be delivered due to forwarding behaviour, policy configuration, allow rules or partial alignment.
Context mattersThe investigation should combine authentication results with delivery outcome, URL clicks, identity behaviour and user impact.
When the inbox changes after delivery
Not every dangerous message is blocked immediately. Microsoft Defender may later quarantine or remediate messages after additional intelligence becomes available. Post-delivery visibility is critical.
post-delivery-remediation-hunt.kql
1
2
3
4
5
6
7
8
9
10
11
12
PostDeliveryEvents
| where Timestamp > ago(30d)
| project
Timestamp,
RecipientEmailAddress,
Subject,
Action,
ActionTrigger,
NetworkMessageId
| order by Timestamp desc
What this findsMessages that were later quarantined, removed or remediated after initial delivery.
Why it mattersThe inbox can change after delivery. A message that looked legitimate earlier may later be confirmed malicious.
Best next pivotCorrelate the message with UrlClickEvents, sign-ins and user activity before remediation occurred.
Complete Defender XDR investigation path
A complete KQL threat hunt follows the evidence across tables instead of stopping at the first result.
1. Start with the signalEmail delivery, DMARC failure, click activity, sign-in anomaly, process execution or cloud access.
2. Confirm the evidenceProject the fields that prove time, user, device, sender, recipient, process or object activity.
3. Pivot with intentMove from EmailEvents to UrlClickEvents, then into identity, endpoint and cloud activity where needed.
4. Look for repetitionUse summarize to identify repeated senders, users, devices, IPs, subjects or processes.
5. Decide impactAsk whether the message was delivered, clicked, signed into, executed or used to access data.
6. Improve controlsUse findings to improve Defender tuning, Conditional Access, DMARC, endpoint hardening and investigation playbooks.
Related Agent Foskett investigation clusters
These pages connect this complete guide to the strongest Microsoft Defender and KQL topic clusters on the site.
It is the process of using KQL in Microsoft Defender XDR advanced hunting to query email, identity, endpoint and cloud telemetry for suspicious behaviour before or beyond alerts.
Which Defender tables are useful for threat hunting?
Common starting tables include EmailEvents, UrlClickEvents, IdentityLogonEvents, DeviceProcessEvents, DeviceNetworkEvents, CloudAppEvents and PostDeliveryEvents.
How do I pivot from email to identity evidence?
Start with EmailEvents, use NetworkMessageId to join to UrlClickEvents, then use the clicked account and timestamp to review IdentityLogonEvents around the same time.
Why does threat hunting matter if Defender already creates alerts?
Alerts are important, but many investigations require context. KQL helps correlate quiet telemetry such as delivery, clicks, sign-ins, process execution and cloud access into one story.
Continue your investigation
This guide connects the core pages across the GEMXIT Microsoft Defender,
Entra ID and KQL threat hunting investigation ecosystem.
Need help with Microsoft Defender KQL threat hunting? Running queries is one thing. Knowing what matters is another. GEMXIT helps organisations review Microsoft Defender signals, Sentinel visibility, Microsoft 365 email security, identity behaviour and practical threat hunting workflows.
Microsoft Defender KQL Threat Hunting Complete Guide
A complete Microsoft Defender KQL threat hunting guide covering EmailEvents, AuthenticationDetails, UrlClickEvents, identity pivots, endpoint process activity and cloud activity investigation workflows.
Microsoft Defender XDR KQL Examples
This page targets technical searches around Microsoft Defender KQL, threat hunting, EmailEvents, dmarc=fail, sender alignment, URL click investigation, suspicious PowerShell and identity investigation.
GEMXIT Microsoft Security Operations
GEMXIT uses Microsoft Defender, Sentinel, Entra ID and Microsoft 365 security data to support practical security operations, threat hunting, email security reviews and response planning.