Using Advanced Hunting in Defender XDR

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 11 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

Mastering Advanced Hunting in Microsoft Defender XDR

Introduction: Why Advanced Hunting Matters

In the modern landscape of cybersecurity, relying solely on automated alerts and pre-built dashboards is no longer sufficient. While Microsoft Defender XDR provides an excellent baseline of automated detection and response, sophisticated threats often hide in the "noise" of everyday network activity. Advanced Hunting is a powerful threat-hunting tool that allows security analysts to perform proactive, query-based investigations across their environment. By using Kusto Query Language (KQL), analysts can search through a vast repository of raw telemetry data to uncover hidden patterns, validate suspicious activities, or scope the extent of a potential compromise.

Understanding Advanced Hunting is essential because it shifts the security posture from reactive to proactive. Instead of waiting for a high-severity alert to trigger, security teams can hypothesize about potential attack vectors—such as lateral movement, data exfiltration, or persistence mechanisms—and then use Advanced Hunting to confirm or deny those theories. This capability is critical for incident response, threat intelligence gathering, and ensuring that your environment remains secure against adversaries who deliberately attempt to evade traditional signature-based detection mechanisms.

Not read yet

Understanding the Foundation: Kusto Query Language (KQL)

At the heart of Advanced Hunting lies the Kusto Query Language (KQL). KQL is a high-performance, read-only language designed to query large-scale data sets. Unlike SQL, which is optimized for relational database management, KQL is optimized for time-series and log-based data, making it the perfect fit for the massive telemetry streams generated by endpoints, identities, and cloud applications within Microsoft Defender XDR.

The Basic Structure of a KQL Query

Every KQL query starts with a table name followed by one or more operators separated by pipe symbols (|). The pipe indicates that the output of the previous command is passed as the input to the next. This logical flow allows you to build complex data transformations step-by-step.

For example, consider a simple query to look for processes being executed:

DeviceProcessEvents
| where Timestamp > ago(24h)
| where FileName == "powershell.exe"
| project Timestamp, DeviceName, AccountName, CommandLine
| sort by Timestamp desc

In this example, we start by referencing the DeviceProcessEvents table. We then filter for events that occurred in the last 24 hours. Next, we narrow the scope to only include instances of powershell.exe. Finally, we select only the columns we care about and sort the results by time. This iterative process is the standard way to build queries in Defender XDR.

Callout: KQL vs. SQL While KQL may look somewhat familiar if you have experience with SQL, it is important to remember that KQL is not SQL. In SQL, you typically write a SELECT statement that defines the entire operation at once. In KQL, you "pipe" data through a series of operators. This makes KQL much more readable and easier to debug, as you can see exactly how the data is transformed at every stage of the pipeline.

Not read yet

Navigating the Microsoft Defender XDR Schema

To effectively use Advanced Hunting, you must understand the data available to you. Microsoft organizes telemetry into various tables, each representing a specific type of activity. These tables are grouped logically to help you find the data you need quickly.

Key Tables in the Schema

  • DeviceProcessEvents: Records process creation, command-line arguments, and process file hashes across all monitored devices.
  • DeviceFileEvents: Tracks file creation, modification, deletion, and renaming events.
  • DeviceNetworkEvents: Logs network connections, including destination IP addresses, ports, and protocols.
  • DeviceLogonEvents: Captures user login and logout activities, including logon types (interactive, network, remote interactive).
  • CloudAppEvents: Contains telemetry from cloud services like Office 365, focusing on user activities and file access.
  • IdentityLogonEvents: Tracks authentication attempts across your identity provider, which is crucial for detecting credential-based attacks.

Note: Always check the schema documentation within the Advanced Hunting portal. Microsoft frequently adds new tables and updates existing ones to incorporate new telemetry from emerging threat vectors.

Not read yet

Practical Scenarios: When to Use Advanced Hunting

Advanced Hunting is not just for hunting; it is also for scoping and validation. Below are several real-world scenarios where you would employ these queries.

Scenario 1: Investigating Suspicious PowerShell Execution

Attackers often use PowerShell to execute malicious scripts in memory. You need to identify instances where PowerShell was launched with encoded commands, which is a common obfuscation tactic.

DeviceProcessEvents
| where Timestamp > ago(7d)
| where FileName =~ "powershell.exe"
| where CommandLine has_any ("-enc", "-EncodedCommand", "-e")
| project Timestamp, DeviceName, AccountName, CommandLine, InitiatingProcessFileName
| order by Timestamp desc

In this query, the =~ operator is used for a case-insensitive match on the filename. The has_any operator is a highly efficient way to search for multiple strings within the command line argument. This query provides a clear view of which accounts are running suspicious commands and which processes initiated them.

Scenario 2: Detecting Lateral Movement via SMB

Lateral movement often involves an attacker copying tools or scripts to a remote machine using SMB (Server Message Block). We can look for file creation events that coincide with network connections.

let FileCreation = DeviceFileEvents
| where Timestamp > ago(24h)
| where ActionType == "FileCreated"
| project DeviceName, FileName, FolderPath, Timestamp;
let NetworkConnection = DeviceNetworkEvents
| where Timestamp > ago(24h)
| where RemotePort == 445
| project DeviceName, RemoteIP, Timestamp;
FileCreation
| join kind=inner (NetworkConnection) on DeviceName
| where Timestamp between ((NetworkConnection.Timestamp - 1m) .. (NetworkConnection.Timestamp + 1m))

This query uses the let statement to define two separate data sets and then joins them based on the DeviceName. By narrowing the time window to within one minute of the network connection, we are looking for evidence of a file being created immediately following an SMB connection, which is a classic indicator of lateral movement.

Not read yet

Best Practices for Writing Efficient Queries

As your environment grows, the volume of telemetry data increases exponentially. Writing inefficient queries can lead to timeouts or incomplete results. Follow these best practices to ensure your investigations are fast and effective.

1. Always Filter by Time

The most important rule in KQL is to limit the time range. By default, many queries might look back 30 days. If you only need to investigate the last 24 hours, explicitly define that in your query. This drastically reduces the amount of data the system needs to process.

2. Move Filters to the Top

The order of operations matters. If you apply a project or summarize operator before filtering your data, you are forcing the system to process more data than necessary. Always filter as early as possible to reduce the data set size.

3. Use has and in Instead of contains

The contains operator is very powerful but computationally expensive because it performs a full-text search across all data. If you know exactly what you are looking for, use has, which searches for whole tokens (words). If you have a list of values, use the in operator, which is highly optimized.

4. Project Only What You Need

Avoid using the * wildcard when projecting columns. Only include the columns that are necessary for your analysis. This reduces memory usage and improves the speed at which your query results are displayed in the browser.

Warning: Be cautious when running queries that aggregate large amounts of data, such as using summarize count() by Bin(Timestamp, 1h). While these are great for identifying trends, they can consume significant resources if run over long periods without sufficient filtering.

Not read yet

Advanced Techniques: Joining and Summarizing

Advanced Hunting becomes truly powerful when you combine data from different sources. The join and summarize operators allow you to correlate events that seem unrelated on the surface.

Correlating Identity and Endpoint Data

An attacker might compromise a user's credentials and then use those credentials to log into a sensitive server. You can correlate IdentityLogonEvents with DeviceLogonEvents to spot this pattern.

let CompromisedAccount = "[email protected]";
IdentityLogonEvents
| where AccountUpn == CompromisedAccount
| where ResultType == 0 // Successful login
| join kind=inner (DeviceLogonEvents) on AccountUpn
| project Timestamp, DeviceName, ActionType, Logontype, AccountUpn

This query correlates successful identity logins with physical device logins. If a user logs in from an unusual device or at an unusual time, this query will highlight the activity, allowing you to investigate further.

Summarizing Activity for Anomaly Detection

Sometimes, you aren't looking for a single malicious event, but rather a pattern of unusual behavior. For example, you might want to see which devices are generating an unusually high number of network connections to external IP addresses.

DeviceNetworkEvents
| where Timestamp > ago(24h)
| where RemoteIPType == "Public"
| summarize ConnectionCount = count() by DeviceName, RemoteIP
| where ConnectionCount > 100
| sort by ConnectionCount desc

This query aggregates the data by device and IP address. By using summarize, you can quickly spot devices that are beaconing to a specific external IP address, which could indicate a C2 (Command and Control) server connection.

Not read yet

Avoiding Common Pitfalls

Even experienced analysts fall into traps when using Advanced Hunting. Awareness of these common mistakes will save you significant time during incident response.

Ignoring Data Latency

Telemetry data does not always arrive in real-time. Depending on the device's connectivity and the load on the Microsoft Defender service, there can be a delay of several minutes between an event occurring and it appearing in the Advanced Hunting tables. If you are investigating a live incident, keep this delay in mind.

Misinterpreting InitiatingProcess

The InitiatingProcess columns are incredibly useful, but they can be misleading if you don't understand the parent-child relationship. A process might be launched by a service, which in turn was launched by a user. Always trace the process tree back to the root if you are unsure of the origin of a malicious activity.

Overlooking the "ActionType"

Different tables use different ActionType values to describe events. For example, in DeviceFileEvents, the ActionType might be FileCreated or FileDeleted. Always verify the ActionType values available for the table you are querying to ensure you aren't filtering for events that don't exist in that specific table.

Callout: The Power of Custom Detections Once you have written a query that successfully identifies a threat, you don't have to run it manually every time. You can save your query as a "Custom Detection." Microsoft Defender XDR will then automatically run this query at regular intervals. If it finds a match, it will trigger an alert, essentially turning your manual hunting query into a proactive detection rule.

Not read yet

Step-by-Step: Creating a Custom Detection Rule

If you want to automate your findings, follow these steps to turn your query into a detection:

  1. Develop and Test: Write your query in the Advanced Hunting portal. Ensure it returns the expected results and that there are no errors.
  2. Save as Detection: Once you are satisfied with the results, click the "Create detection rule" button at the top of the query editor.
  3. Define Alert Details: Provide a name, description, and severity for the alert. This is what the security operations team will see when the alert fires.
  4. Set Frequency: Choose how often the rule should run (e.g., every hour, every 24 hours).
  5. Configure Actions: Define what happens when the rule triggers. You can have the system automatically isolate the device, disable the user account, or simply generate a notification.
  6. Review and Enable: Review your settings to ensure they meet your security policy requirements, then save the rule.

Not read yet

Comparison: Advanced Hunting vs. Other Defender XDR Features

To understand where Advanced Hunting fits, it helps to compare it with other features in the Defender XDR ecosystem.

Feature Primary Goal Best Used For
Alerts/Incidents Reactive Responding to known, high-confidence threats identified by the system.
Advanced Hunting Proactive Searching for unknown threats, scoping incidents, and threat hunting.
Threat Analytics Informative Staying informed about current threat actors, techniques, and global trends.
Custom Detections Automated Automating the detection of specific, recurring attack patterns discovered via hunting.

Industry Standards and Best Practices

When integrating Advanced Hunting into your daily security operations, it is helpful to align with industry frameworks such as MITRE ATT&CK.

  • Map to MITRE ATT&CK: Every time you write a hunting query, ask yourself which part of the MITRE ATT&CK framework you are trying to detect. For example, are you hunting for Credential Dumping (T1003) or Lateral Movement (T1021)? This helps document your security coverage.
  • Version Control: Just like software code, your KQL queries should be stored in a version control system (like Git). This allows you to track changes, collaborate with other analysts, and roll back if a query is updated incorrectly.
  • Peer Review: Always have a colleague review your complex queries. A fresh pair of eyes can often spot inefficiencies or logical errors that you might have missed.
  • Baseline Your Environment: You cannot hunt effectively if you don't know what "normal" looks like. Use Advanced Hunting to establish baselines for your environment—such as which accounts usually log into which servers—so that you can quickly spot deviations.

Not read yet

Addressing Common Questions (FAQ)

Q: Does Advanced Hunting cover all of my data?

A: Advanced Hunting covers data generated by Microsoft Defender for Endpoint, Defender for Office 365, Defender for Identity, and Defender for Cloud Apps. If you have external data sources (like custom logs), you should look into integrating those into a Sentinel workspace, which offers even more robust hunting capabilities.

Q: Can I use Advanced Hunting to modify data?

A: No. Advanced Hunting is a read-only interface. You cannot use it to delete files, kill processes, or modify registry keys directly. You must use the response capabilities within the incident dashboard or automated response actions to take remediation steps.

Q: Is there a limit to how many queries I can run?

A: While there is no hard limit on the number of queries, there are limits on resource consumption. If a query is too complex or spans too much data, the system will prevent it from running to ensure performance for all users. Always optimize your queries to stay within these limits.

Not read yet

Final Key Takeaways

Mastering Advanced Hunting is a journey that requires both technical skill in KQL and a deep understanding of how attackers operate. By consistently applying these principles, you will significantly improve your team's ability to defend your organization.

  1. Proactivity is Key: Move beyond the alerts. Use Advanced Hunting to validate hypotheses and discover threats that automated systems might have missed.
  2. Master KQL: The performance of your hunting relies entirely on your ability to write efficient KQL. Focus on filtering early and using the right operators.
  3. Correlate Data: Use the power of the XDR schema to join data across endpoints, identities, and email. This holistic view is what makes Advanced Hunting truly unique.
  4. Automate Your Success: Whenever you find a reliable way to detect a specific threat, turn that query into a custom detection rule to ensure permanent protection.
  5. Document and Share: Keep a library of your queries. Share them with your team to build a collective knowledge base of how to defend your specific environment.
  6. Align with Frameworks: Use industry standards like MITRE ATT&CK to guide your hunting efforts and ensure you are covering the full spectrum of potential attack vectors.
  7. Iterate and Refine: Your environment changes constantly. Regularly review your hunting queries to ensure they are still relevant and optimized for your current infrastructure.

By following these practices, you transform from a reactive analyst into a proactive threat hunter, capable of identifying and mitigating risks before they escalate into full-blown security incidents. The tools are available; the success of your security program now depends on how effectively you use them.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.