Let’s Get Certified
Module 11 / 13 · Perform threat hunting

Write and interpret a bounded Defender hunt

Select an event table, filter the population and distinguish event frequency from device reach.

Write and interpret a bounded Defender hunt

Work through the decision

A policy team supplies a synthetic file digest from a controlled maintenance release. A query returns eighteen matching file-event rows. The coordinator reports eighteen devices. Which query change tests that conclusion?

Check your reasoning

Filter the appropriate Defender hunting table by time, action and digest. Count events per stable DeviceId and inspect the first and last observations. Eighteen writes may come from one device. Use the source timestamps and coverage before claiming fleet-wide prevalence.

Watch the source lesson at 1:32:15

Compare the choices

Table selection
Choose a hunting table whose events actually represent the observation. Inspect its schema and reporting prerequisites.
Bounded filtering
Restrict the interval, event type and indicator to define the population. Make time-zone and boundary behavior explicit.
Grouped aggregation
Summarize records at an explicit grain, such as one row per device. Keep occurrence count distinct from number of reporting devices.
Projection
Select fields required for a hypothesis, entity pivot or handoff. Keep the stable identifiers that a downstream workflow requires.

Test the decision

For an endpoint file question, DeviceFileEvents supplies relevant fields such as Timestamp, DeviceId, ActionType and SHA1. Project just the fields required for handoff. Include stable event keys when results may later form the basis of a custom detection.

Check the source schema before counting devices

DeviceFileEvents is populated by Defender for Endpoint. Inspect Timestamp, ActionType, DeviceId and the available hash fields in the source schema. In the example, each grouping key represents a device. Compare the number of groups with the sum of their event counts.

Microsoft Learn · DeviceFileEvents schema

Read the equivalent Defender KQL query

let start_time = datetime(2026-10-22 08:00:00);
let end_time = datetime(2026-10-22 09:00:00);
DeviceFileEvents
| where Timestamp >= start_time and Timestamp < end_time
| where ActionType == "FileCreated" and SHA1 == "1111111111111111111111111111111111111111"
| summarize Events=count(), LastSeen=max(Timestamp) by DeviceId
| project DeviceId, Events, LastSeen
| order by DeviceId asc
Check the result

The output has one row per matching device. The exercise below supplies the synthetic records to evaluate locally. A real tenant would only return rows if its devices actually recorded the selected digest within the time window.

Practice the guide skills

  1. Which table best addresses a question about files created on reporting endpoints? Watch 1:32:15
    Check your answer

    Start with DeviceFileEvents and inspect its schema. Use the event source that records the activity of interest and verify device coverage.

  2. An indicator appears many times on one device. Count distinct devices affected. Watch 1:33:03
    Check your answer

    Filter by time and indicator first. Group by stable device identifier before counting unique devices, and distinguish occurrence count from breadth.

  3. Return the minimum fields needed for an endpoint handoff. Watch 1:33:03 · Continue at 1:33:18
    Check your answer

    Project the timestamp, stable device identifier and relevant entity fields after filtering. Preserve the keys needed for a later pivot or custom detection.

Official objectives for this lesson

Lab · Count matching devices in a bounded hunt

Use Python 3 with the fictional DeviceFileEvents-like records below. A maintenance release uses a known test digest. Count its FileCreated observations from 08:00 inclusive until 09:00 exclusive in UTC. Predict the event count, unique devices and behavior at the end boundary. This local exercise reproduces the filtering and grouping used in the KQL example.

from collections import Counter
from datetime import datetime

digest = "1" * 40
# UTC timestamp, stable device ID, file event type, synthetic SHA-1
rows = [
    ("2026-10-22T07:59:59+00:00", "D1", "FileCreated", digest),
    ("2026-10-22T08:02:00+00:00", "D1", "FileCreated", digest),
    ("2026-10-22T08:13:00+00:00", "D1", "FileCreated", digest),
    ("2026-10-22T08:17:00+00:00", "D2", "FileCreated", digest),
    ("2026-10-22T08:21:00+00:00", "D2", "FileModified", digest),
    ("2026-10-22T08:41:00+00:00", "D3", "FileCreated", "2" * 40),
    ("2026-10-22T09:00:00+00:00", "D3", "FileCreated", digest),
]
start = datetime.fromisoformat("2026-10-22T08:00:00+00:00")
end = datetime.fromisoformat("2026-10-22T09:00:00+00:00")
counts = Counter()
for time_text, device, action, sha1 in rows:
    time = datetime.fromisoformat(time_text)
    if start <= time < end and action == "FileCreated" and sha1 == digest:
        counts[device] += 1
for device, count in sorted(counts.items()):
    print(device, count)
print("events:", sum(counts.values()))
print("devices:", len(counts))
Check the result
D1 2
D2 1
events: 3
devices: 2

D1 contributed two events. D2 has one matching creation and one excluded modification. D3 has a different digest inside the window and a qualifying event at the next window’s start. Move the end one second later and predict the result. The sample demonstrates presence on reporting devices; it says nothing about devices with missing telemetry.

Related lesson · Move from collected events to a reviewed response

Knowledge check

Write and interpret a bounded Defender hunt quiz

Answer 3 questions. Check each answer for an explanation.

Worked example · Write and interpret a bounded Defender hunt