Agent Foskett Academy • Microsoft Sentinel • Module 3 • Lesson 35

Lesson 35 — Building a Complete Sentinel Detection

Anyone can write a query.

The job is not finished until that query becomes a detection an analyst can trust.

Module 3 finale — build the complete detection, not just the KQL.
Agent Foskett building a complete Microsoft Sentinel detection
What you will build

A complete scheduled analytics rule from evidence to investigation.

✓ Detection hypothesis and KQL
✓ Schedule and thresholds
✓ Entities and enrichment
✓ Testing, incidents and tuning

Learning objectives

  • Bring the full scheduled analytics rule workflow together.
  • Build detection logic from a clear security hypothesis.
  • Configure scheduling, thresholds, entities and alert enrichment.
  • Map the detection to MITRE ATT&CK based on evidence.
  • Test the rule as an analyst would experience it.
  • Define what happens after the rule enters production.

The investigation

The SOC wants to detect one source IP repeatedly failing authentication against many user accounts — behaviour consistent with password spraying.

We are going to build the detection from the evidence upward rather than opening the rule wizard and guessing.

The complete detection lifecycle

Security hypothesis │ ▼ Required telemetry │ ▼ KQL detection logic │ ▼ Historical validation │ ▼ Schedule + lookback + threshold │ ▼ Entities + custom details + alert details │ ▼ MITRE ATT&CK + incident behaviour │ ▼ Results simulation + analyst validation │ ▼ Enable → Monitor → Tune → Improve

Step 1 — write the hypothesis

Hypothesis: one source IP failing authentication against many distinct user accounts within a short period can indicate password spraying.

This sentence defines the behaviour. It tells us which evidence matters and prevents the rule from becoming a vague “suspicious sign-in” detector.

Step 2 — identify the telemetry

For this example we use SigninLogs. We need the event time, source IP, user account and sign-in result.

Before writing detection logic, confirm the required table is populated and the fields contain the values you expect.

Step 3 — build the KQL

Password-spray detection candidate
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
SigninLogs
| where ResultType != "0"
| summarize FailedAttempts = count(),
            TargetUsers = dcount(UserPrincipalName),
            Users = make_set(UserPrincipalName, 20),
            FirstSeen = min(TimeGenerated),
            LastSeen = max(TimeGenerated)
    by IPAddress
| where FailedAttempts >= 20 and TargetUsers >= 5

The query describes the behaviour rather than merely returning failed sign-ins. Each result represents a source IP that crossed both the failed-attempt and distinct-user thresholds.

Do not add a fixed time filter blindly

Scheduled rules evaluate data using their configured lookback period and TimeGenerated. Design the rule query and scheduling together so the detection window is clear.

A manual hunting query may use a convenient ago() filter; production scheduling needs deliberate timing.

Step 4 — validate against history

Run the candidate logic against historical data. Inspect every result you can reasonably validate.

Separate known benign scanners, testing systems and expected applications from activity that really deserves analyst attention.

Step 5 — choose frequency and lookback

SettingExample designReason
Run query every15 minutesProvides regular detection without treating this example as a real-time rule.
Lookup data from the last30 minutesProvides a wider detection window and some tolerance for timing.
KQL behavioural threshold20 failures / 5 usersDefines the password-spray hypothesis.
Rule-result thresholdGenerate when query results exceed the configured minimumControls whether returned result rows create an alert.

These are teaching values, not universal production thresholds. Tune them from your own environment and threat model.

Overlapping windows are deliberate

A 15-minute interval with a 30-minute lookback means query windows overlap. That can improve coverage but can also expose the same activity to multiple executions.

Plan alert and incident grouping with that behaviour in mind.

Remember ingestion latency

Microsoft Sentinel scheduled analytics rules run with a built-in five-minute delay to help account for ingestion latency.

If your source commonly arrives later than that, measure the delay and design the lookup strategy accordingly rather than assuming the event was available.

Step 6 — map the entity

Query field: IPAddress │ ▼ Entity type: IP │ ▼ Identifier: Address │ ▼ Alert entity │ ▼ Investigation pivots and correlation

Entity mapping is not decoration. It turns a query value into an entity Sentinel can expose to investigation and correlation experiences.

What about the user accounts?

Our query aggregates many users into the Users dynamic array. That is useful investigation context, but it is not one clean account identifier.

Do not force an account entity mapping merely because accounts appear somewhere in the result. Map fields that correctly represent the entity schema.

Step 7 — add custom details

Surface FailedAttempts, TargetUsers, FirstSeen and LastSeen as useful alert context.

The analyst should immediately understand the scale and timing of the activity without rerunning the query first.

Step 8 — make the alert readable

Sentinel can customize alert details using values returned by the query. Use that capability carefully to make the detection understandable.

Example alert intent

Possible password spray from a source IP — multiple failed sign-ins across distinct user accounts.

Avoid dramatic names such as “PASSWORD SPRAY ATTACK CONFIRMED.” The rule identifies evidence consistent with the hypothesis; the investigation determines what actually happened.

Step 9 — map MITRE ATT&CK

The behaviour in this example supports mapping to the Credential Access tactic and the Brute Force technique, specifically Password Spraying where the rule logic genuinely represents that behaviour.

Do not add Initial Access, Persistence or Privilege Escalation simply because they could happen later.

Step 10 — choose event grouping

Decide whether each returned result should become its own alert or whether all returned events should be grouped into a single alert.

For a result set where each row represents a distinct suspicious source IP, per-result alerts can preserve that separation — but always consider expected volume.

Step 11 — design the incident

Decide how alerts should become incidents. Sentinel supports grouping related alerts using mapped entities and selected details.

ChoiceInvestigation effect
Separate incidentsEach alert begins its own investigation context.
Group when entities matchRepeated alerts involving the same mapped entities can be investigated together.
Group by selected entities/detailsProvides more deliberate control over which alerts belong together.

In the Defender portal, Defender XDR's correlation engine is responsible for incident correlation, so actual incident grouping can differ from the initial Sentinel rule grouping instructions.

Step 12 — simulate before enabling

Use Results simulation → Test with current data. Microsoft Sentinel simulates the scheduled rule 50 times using the configured schedule and current data.

Look for alert storms, long quiet periods, threshold boundaries and known benign spikes.

Simulation is not the whole test

Simulation shows expected result volume. You still need to validate known true positives, known false positives, entity mappings, custom details and the final analyst experience.

The rule must make sense after it fires, not just before.

The pre-production test matrix

TestExpected outcome
Known password-spray sampleDetection matches.
19 failures against 5 usersBelow the example failed-attempt threshold.
20 failures against 4 usersBelow the example distinct-user threshold.
Known approved scannerHandled according to documented tuning policy.
Multiple suspicious source IPsAlert/event grouping behaves as designed.
Generated alertIP entity and custom details appear correctly.

Step 13 — tune with evidence

If a known benign source repeatedly matches, prove why it is benign before excluding it.

Prefer narrow, maintainable exceptions. A watchlist can be appropriate where a centrally managed list of approved sources is required.

Do not tune away the hypothesis

If the rule becomes quiet only because every noisy account, subnet and application has been excluded, revisit the detection design.

Tuning should improve signal quality without destroying the behaviour you intended to detect.

Step 14 — enable and verify

Enable rule │ ▼ Confirm scheduled execution │ ▼ Generate / observe expected evidence │ ▼ Confirm alert │ ▼ Confirm entities + details │ ▼ Confirm incident behaviour │ ▼ Record baseline alert volume

Production enablement is not the end of testing. Verify that the complete path works in the live environment.

Step 15 — monitor the detection

Track alert volume, false positives, missed expected behaviour and execution health. A detection is operational content, not a page of KQL you forget after deployment.

Changes to identity systems, data sources, schemas and business processes can all change its behaviour.

Document why the rule exists

Record the hypothesis, data dependencies, thresholds, expected entities, exceptions, ATT&CK mapping, owner and tuning rationale.

The next analyst should not have to reverse-engineer your intentions from the query.

Complete detection specification

ComponentOur example
HypothesisOne IP failing against many accounts may indicate password spraying.
TelemetrySigninLogs
Primary entityIP address
Behaviour20+ failed attempts against 5+ distinct users
Example frequency15 minutes
Example lookback30 minutes
Custom detailsFailure count, target count, first seen, last seen
ATT&CKCredential Access / Brute Force / Password Spraying where supported by the logic
TestingHistorical validation + simulation + true/false-positive matrix
LifecycleEnable → verify → monitor → tune → retest

What makes this a detection?

Not the KQL alone.

The detection is the combination of hypothesis, telemetry, query, timing, thresholds, context, entities, alert behaviour, incident behaviour, testing and ongoing ownership.

What makes it trustworthy?

The analyst can explain why it fired, inspect the evidence, identify the entities, reproduce the logic and understand its limitations.

Trust comes from evidence and repeatability — not from a severity label.

Agent Foskett final exercise — build your own

Scenario:

You have a hunting query that finds suspicious PowerShell activity on endpoints. Build the production detection specification before touching the analytics-rule wizard.

  1. Write the detection hypothesis in one sentence.
  2. Name the required table and fields.
  3. Define what one query result represents.
  4. Choose frequency and lookback and explain why.
  5. Define KQL and rule-level thresholds.
  6. Choose entity mappings.
  7. Choose custom details and alert details.
  8. Map only evidence-supported ATT&CK techniques.
  9. Define alert and incident grouping.
  10. Create true-positive, false-positive and boundary tests.
  11. Run simulation before enablement.
  12. Define how the rule will be monitored and tuned after deployment.

Module 3 checklist

  • Scheduled analytics rules
  • Frequency and lookup periods
  • Alert thresholds
  • Entity mapping
  • Custom details and enrichment
  • Alert and incident grouping
  • NRT and Microsoft security rules
  • MITRE ATT&CK mapping
  • Tuning and false positives
  • Testing before enablement
  • Hunting-to-detection workflow
  • Troubleshooting failed detections

Agent Foskett takeaway

A query can find evidence.

A complete detection makes that evidence repeatable, explainable and actionable for the SOC.

Follow the evidence. Build the detection. Test the assumptions. Then trust the alert.

Module 3 complete
You have moved from writing scheduled analytics rules to designing, testing, tuning and troubleshooting complete Microsoft Sentinel detections. Next, the focus moves from creating alerts to investigating the incidents they produce.
Sentinel Academy Home

Continue learning

Module 3 is complete. Continue into Module 4 — Incidents and Investigation.

Build a Complete Microsoft Sentinel Detection

A production Microsoft Sentinel detection is more than a KQL query. Scheduled analytics rules combine a security hypothesis, telemetry, query logic, scheduling, thresholds, entity mapping, alert enrichment, MITRE ATT&CK mapping, event and incident behaviour, testing, tuning and ongoing monitoring.

Microsoft Sentinel Lesson 35

This Agent Foskett Microsoft Sentinel Academy lesson brings Module 3 together in one end-to-end detection engineering exercise, from initial hypothesis through production validation and lifecycle management.