Agent Foskett Academy • Microsoft Sentinel • Module 8 • Lesson 71

Lesson 71 — Advanced Detection Engineering in Microsoft Sentinel

Threat hunting asks what might be happening. Detection engineering turns a defensible hypothesis into a repeatable, tested and maintainable signal that analysts can trust.

Module 8 — Advanced Detection Engineering and SOC Optimisation
Agent Foskett advanced Microsoft Sentinel detection engineering
What you will learn

Build detections as engineered security products—not just scheduled KQL queries.

✓ Define an observable threat behaviour
✓ Validate data and KQL assumptions
✓ Design useful alerts and entities
✓ Test, tune and monitor detections

Agent Foskett case file — The rule that never fired

At 02:14, a service account authenticates from an unfamiliar public IP address. A threat hunter finds the activity with KQL, but the production rule produces no alert. Agent Foskett investigates whether the detection was incorrectly designed, lacked data, missed the event window, or was intentionally suppressed during tuning.

The goal is not to generate more alerts. It is to explain exactly what the detection should identify, prove it works, and make failures visible.

Learning objectives

  • Describe the detection engineering lifecycle and its operational deliverables.
  • Convert a hypothesis into measurable behaviour and documented assumptions.
  • Validate data availability, schema, ingestion delay and coverage.
  • Write scoped, read-only KQL suitable for a candidate scheduled analytics rule.
  • Plan rule scheduling, entity mapping, incident grouping and safe testing.
  • Define validation, tuning, ownership and ongoing health monitoring.

What makes detection engineering advanced?

Earlier Academy modules introduced scheduled analytics rules, thresholds and basic tuning. Advanced detection engineering adds a repeatable process: threat model → telemetry contract → analytic logic → test cases → rule configuration → production observation → improvement. Each detection has an owner, expected inputs, known limitations, a change history and a way to verify that it still works.

Detection specification — before writing KQL

FieldExample
HypothesisA service account signs in successfully from an IP not observed for that account during the baseline window
ScopeInteractive Microsoft Entra sign-ins represented in SigninLogs; service-account inventory maintained separately
EvidenceAccount identifier, source IP, result, application, timestamp and prior observed IPs
Expected exclusionsApproved new egress IPs and documented account changes, with expiry dates
ValidationKnown positive and negative examples, including missing baseline and delayed ingestion
ResponseAnalyst review; no automatic account disablement from a single anomaly

Important: this example covers interactive sign-ins only. Non-interactive service-principal and managed-identity activity use other log types and must be engineered separately.

Prerequisites and telemetry contract

Use Microsoft Sentinel Logs with the Microsoft Entra ID connector configured to ingest SigninLogs into the workspace. Confirm the appropriate licensing, permissions and retention. You also need a maintained list of the service accounts in scope; do not infer account type from a username prefix. The queries below demonstrate the analytic pattern using an explicitly supplied account identifier.

Detection quality depends on available data. A missing log table, insufficient retention or changed source schema can invalidate an otherwise correct query.

KQL 1 — Verify source coverage

Microsoft Sentinel Logs — KQL 1 — Verify source coverage
SigninLogs
| where TimeGenerated >= ago(7d)
| summarize Events=count(), FirstSeen=min(TimeGenerated),
    LastSeen=max(TimeGenerated), Accounts=dcount(UserId)
| extend DataAgeMinutes=datetime_diff('minute', now(), LastSeen)

Interpreting source coverage

Check whether the connector is expected to receive events during the sampled period. A small count or stale LastSeen may reflect low activity, connector issues or ingestion delay. TimeGenerated describes the event timestamp; investigate ingestion latency separately before attributing an apparent gap to an attacker.

KQL 2 — Candidate detection for a newly observed sign-in IP

Microsoft Sentinel Logs — KQL 2 — Candidate detection for a newly observed sign-in IP
let TargetUserId = "replace-with-user-object-id";
let BaselineStart = ago(15d);
let DetectionStart = ago(1d);
let BaselineIPs = materialize(
    SigninLogs
    | where TimeGenerated >= BaselineStart and TimeGenerated < DetectionStart
    | where UserId == TargetUserId and ResultType == "0"
    | where isnotempty(IPAddress)
    | distinct IPAddress
);
SigninLogs
| where TimeGenerated >= DetectionStart and TimeGenerated <= now()
| where UserId == TargetUserId and ResultType == "0"
| where isnotempty(IPAddress)
| where IPAddress !in (BaselineIPs)
| project TimeGenerated, UserPrincipalName, UserId, IPAddress,
    AppDisplayName, ResultType, CorrelationId
| order by TimeGenerated desc

Why this is a candidate—not a production rule

The query uses a 14-day historical baseline and a 24-hour candidate window for learning purposes. It can flag a first observed IP, but does not establish compromise. An account with no baseline history can produce misleading results. NAT, VPN gateways, roaming users, IP rotation and approved infrastructure changes also affect interpretation.

For production, use a documented and tested lookback strategy that fits scheduled-rule execution limits, data retention, query cost and the desired detection latency. Consider a maintained baseline table or watchlist where appropriate rather than scanning large historical ranges every run.

Engineering the analytics rule

  1. Create a scheduled analytics rule using a validated version of the candidate query.
  2. Choose an execution frequency and lookup period supported by the rule type and query.
  3. Make the query return the actual events to alert on; prevent duplicate alerts caused by overlapping windows.
  4. Map account and IP entities from returned columns, verifying identifier types.
  5. Add useful custom details such as application and correlation ID, without exposing unnecessary sensitive data.
  6. Choose alert grouping and incident creation based on analyst workflow.
  7. Test with known data and review simulation results before enabling the rule.

Do not paste the example into production unchanged. Replace the sample account ID, choose the appropriate schedule, test query performance and validate entity mappings in your environment.

Detection testing matrix

TestExpected behaviour
Known new IPCandidate event is returned and mapped correctly
Known baseline IPNo candidate event
Failed sign-inExcluded by the success condition
No baseline recordsFlagged as an insufficient-history condition, not treated as confirmed malicious
Connector outageSeparate data-health monitoring reports missing or stale telemetry
Overlapping execution windowsDuplicate-alert behaviour is measured and controlled

KQL 3 — Inspect recent sign-in ingestion latency

Microsoft Sentinel Logs — KQL 3 — Inspect recent sign-in ingestion latency
SigninLogs
| where TimeGenerated >= ago(24h)
| extend IngestionDelayMinutes = datetime_diff('minute', ingestion_time(), TimeGenerated)
| summarize Events=count(),
    P50DelayMinutes=percentile(IngestionDelayMinutes, 50),
    P95DelayMinutes=percentile(IngestionDelayMinutes, 95),
    LastEvent=max(TimeGenerated)

Latency and health caveats

ingestion_time() provides ingestion timing where supported; verify it is available and meaningful for your source. Event timestamps may also be affected by clock skew. Monitor the detection pipeline itself: source collection, connector health, query execution, rule health, alert creation and analyst outcomes. One successful query run does not prove continuous coverage.

Measure outcomes, not just alert counts

Record true positives, benign positives, false positives, missed detections, analyst time spent, data-source failures and changes to the detection logic. Use these observations to improve the rule. Avoid blindly excluding noisy accounts or IP ranges: broad allowlists can create permanent blind spots.

Agent Foskett investigation — the missing alert

In the case file, the suspicious sign-in is visible in SigninLogs, but the production rule searches only the last 15 minutes and executes every 30 minutes. The query window can leave uncovered intervals. A separate review finds that a broad trusted-IP exclusion also suppresses a legitimate test case.

Resolution: the team corrects the schedule/lookback relationship, narrows the exclusion to documented business context, replays representative test cases and adds rule-health monitoring. The sign-in remains an investigative lead until corroborating evidence establishes whether it was authorized.

Hands-on lab — Engineer a reliable detection

  1. Choose a permitted test account and document expected sign-in behaviour.
  2. Confirm the SigninLogs table and coverage for the intended period.
  3. Run the candidate query with a known account ID and review returned columns.
  4. Test a baseline IP, a newly observed IP and a no-history scenario.
  5. Design the rule schedule, lookup period, entity mapping and incident grouping.
  6. Document three likely false-positive causes and safe ways to validate them.
  7. Define how you would detect stale data or a failed rule execution.
  8. Write a short detection specification with owner, test results and limitations.

Knowledge check

  1. Why is a threat-hunting query not automatically a production-ready detection?
  2. What can make a zero-result query misleading?
  3. Why do the rule frequency and lookup period matter?
  4. What additional evidence is needed before treating a new sign-in IP as compromise?
  5. How can an exclusion create a detection blind spot?
  6. What would you monitor to know the detection still works next month?

Lesson 71 takeaway

A reliable detection is a maintained security control with evidence, tests, owners and monitoring—not simply a KQL query that runs on a schedule.

The Logs Already Knew. Detection Engineering Makes Sure Someone Hears Them.

Lesson 71 complete — Module 8 has begun!
You have designed a detection engineering workflow from hypothesis through validation and monitoring.
Sentinel Academy Home

Continue learning

Module 8 — Advanced Detection Engineering and SOC Optimisation • Lesson 1 of 10.
⬅ Previous lesson
Lesson 70 — Complete Advanced Threat Hunting InvestigationReview the Module 7 capstone.
🏠 Academy home
Microsoft Sentinel AcademyBrowse published lessons and modules.
Next lesson • Coming soon
Lesson 72 — Building Behaviour-Based Detection RulesComing soon — this link will be activated when Lesson 72 is published.