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

Lesson 72 — Building Behaviour-Based Detection Rules

Static indicators tell us what to look for. Behaviour-based detections help us recognise meaningful changes in how accounts and systems operate—even when an attacker uses legitimate tools.

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

Turn a suspicious change in account behaviour into a tested, explainable Sentinel detection.

✓ Establish a meaningful account baseline
✓ Identify newly observed source IPs
✓ Compare current activity with history
✓ Validate signals before enabling alerts

Agent Foskett case file — The familiar account, unfamiliar network

A finance administrator signs in successfully from an IP address that has not appeared in the account’s recent history. The authentication succeeds, no malicious file is detected, and the source address is not on a threat-intelligence blocklist.

The question is not simply “Is this IP bad?” It is “Is this behaviour sufficiently different from the account’s established pattern to justify investigation?” Agent Foskett must build a detection that explains the change without treating every new IP as an attack.

Learning objectives

  • Explain the difference between indicator-based and behaviour-based detections.
  • Build a historical baseline using Microsoft Entra sign-in telemetry.
  • Compare recent successful sign-ins with the baseline using KQL.
  • Handle sparse history, NAT, VPNs and legitimate travel without creating blind spots.
  • Define alert thresholds, entity mapping, testing and operational ownership.

What makes a detection behaviour-based?

An indicator-based rule looks for a known value, such as a malicious domain. A behaviour-based rule looks for an activity pattern or a meaningful deviation from an established norm. Examples include a privileged account using a previously unseen source network, a service account suddenly authenticating interactively, or a device executing an unusual administrative tool.

Important: unusual does not mean malicious. A new VPN exit node, a business trip or an infrastructure change may explain the deviation. A useful detection preserves the evidence needed to investigate those alternatives.

Design the detection hypothesis

Hypothesis: a successful interactive sign-in from an IP address not observed for the same account during the preceding 14 days deserves review, particularly when the account has sufficient historical activity to make the baseline meaningful.

  • Source: SigninLogs in a Sentinel-connected Log Analytics workspace.
  • Entity: prefer UserId for stable account identity; retain UserPrincipalName for analyst readability.
  • Observation: successful recent sign-ins compared with older successful sign-ins.
  • Output: account, source IP, recent timestamp and history count.
  • Limitation: a new IP is an investigation lead, not proof of compromise.

Prerequisites and telemetry checks

Confirm that Microsoft Entra sign-in data is connected and available in SigninLogs, that you have permission to query it, and that your retention covers the baseline window. This example focuses on interactive sign-ins in SigninLogs; non-interactive sign-ins require their own data source and logic.

Run the coverage query first. If data is absent or the account has too little history, the baseline cannot support a reliable novelty claim.

KQL 1 — Check baseline coverage

Microsoft Sentinel Logs — Check baseline coverage
SigninLogs
| where TimeGenerated between (ago(15d) .. now())
| where ResultType == "0"
| summarize SuccessfulSignIns=count(),
    Accounts=dcount(UserId), SourceIPs=dcount(IPAddress),
    FirstEvent=min(TimeGenerated), LastEvent=max(TimeGenerated)
| extend LastEventAgeMinutes=datetime_diff('minute', now(), LastEvent)

Interpreting the coverage results

Check whether the first event is old enough for the planned 14-day baseline and whether the most recent event is fresh. A workspace with only two days of sign-in history cannot reliably determine what was normal over the previous fortnight. Also check ingestion delay and connector health before interpreting zero results.

KQL 2 — Detect newly observed account source IPs

Microsoft Sentinel Logs — Behaviour-based candidate detection
let DetectionWindow = 1h;
let BaselineWindow = 14d;
let MinBaselineSignIns = 10;
let Baseline = materialize(
    SigninLogs
    | where TimeGenerated >= ago(BaselineWindow + DetectionWindow)
      and TimeGenerated < ago(DetectionWindow)
    | where ResultType == "0"
    | where isnotempty(UserId) and isnotempty(IPAddress)
    | summarize BaselineSignIns=count(),
        KnownIPs=make_set(IPAddress, 1000) by UserId
    | where BaselineSignIns >= MinBaselineSignIns
);
SigninLogs
| where TimeGenerated >= ago(DetectionWindow)
| where ResultType == "0"
| where isnotempty(UserId) and isnotempty(IPAddress)
| join kind=inner Baseline on UserId
| where not(set_has_element(KnownIPs, IPAddress))
| summarize FirstSeen=min(TimeGenerated),
    LastSeen=max(TimeGenerated), SignInCount=count(),
    UserPrincipalName=take_any(UserPrincipalName),
    BaselineSignIns=take_any(BaselineSignIns)
    by UserId, IPAddress
| project LastSeen, FirstSeen, UserPrincipalName,
    UserId, IPAddress, SignInCount, BaselineSignIns
| order by LastSeen desc

How the detection works

  1. Baseline: builds a per-account set of previously observed successful sign-in IP addresses.
  2. Minimum history: requires at least ten baseline sign-ins, reducing misleading results for rarely used accounts.
  3. Recent window: evaluates successful sign-ins during the last hour.
  4. Novelty: flags IP addresses absent from the account’s historical set.
  5. Evidence: returns the account, IP address, time range and activity counts for investigation.

The make_set(..., 1000) limit is deliberate and must be evaluated: accounts with more than 1,000 distinct historical IPs may be misclassified because their baseline set is truncated. For high-cardinality environments, use a distinct account/IP baseline joined with a leftanti operation instead.

KQL 3 — Alternative for high-cardinality IP history

Microsoft Sentinel Logs — Distinct baseline with leftanti
let DetectionWindow = 1h;
let BaselineWindow = 14d;
let KnownAccountIPs =
    SigninLogs
    | where TimeGenerated >= ago(BaselineWindow + DetectionWindow)
      and TimeGenerated < ago(DetectionWindow)
    | where ResultType == "0"
    | where isnotempty(UserId) and isnotempty(IPAddress)
    | distinct UserId, IPAddress;
let EligibleAccounts =
    SigninLogs
    | where TimeGenerated >= ago(BaselineWindow + DetectionWindow)
      and TimeGenerated < ago(DetectionWindow)
    | where ResultType == "0" and isnotempty(UserId)
    | summarize BaselineSignIns=count() by UserId
    | where BaselineSignIns >= 10;
SigninLogs
| where TimeGenerated >= ago(DetectionWindow)
| where ResultType == "0"
| where isnotempty(UserId) and isnotempty(IPAddress)
| join kind=inner EligibleAccounts on UserId
| join kind=leftanti KnownAccountIPs on UserId, IPAddress
| summarize LastSeen=max(TimeGenerated), SignInCount=count(),
    UserPrincipalName=take_any(UserPrincipalName),
    BaselineSignIns=take_any(BaselineSignIns)
    by UserId, IPAddress
| project LastSeen, UserPrincipalName, UserId,
    IPAddress, SignInCount, BaselineSignIns
| order by LastSeen desc

Choosing the correct baseline strategy

The set-based query is convenient for moderate account/IP cardinality, while the leftanti approach avoids a capped IP array. Neither is automatically the fastest: compare query execution time, scanned data volume and results in your workspace. For production, scope to relevant identities or risk groups where justified and ensure the schedule/lookback configuration is aligned with ingestion latency.

Baseline contamination: if an attacker’s IP was already observed during the historical period, the novelty test will not detect it. Combine novelty with other signals rather than relying on it as a sole control.

Add context before creating incidents

  • Check whether the IP belongs to an approved VPN, corporate proxy or recently changed network provider.
  • Review Conditional Access, authentication requirements, device and location details when available.
  • Look for correlated account changes, suspicious mailbox rules, impossible travel patterns or unusual application access.
  • Use watchlists for documented business context, but avoid blanket exclusions of all trusted networks.
  • Keep the original IP, user identifier and event timestamps in the alert for analyst validation.

Configure a production analytics rule

  1. Validate the query in Logs using real data and authorised test accounts.
  2. Create a scheduled analytics rule with a one-hour lookup and an execution cadence appropriate to your ingestion delay and acceptable detection latency.
  3. Map UserId to the Account entity identifier and IPAddress to the IP entity; include useful custom details.
  4. Choose incident grouping and alert thresholds based on testing, not assumptions.
  5. Document suppression logic, owner, response runbook, review date and data prerequisites.
  6. Monitor rule executions and data freshness; verify whether late-arriving events require overlap and deduplication.

Do not automatically disable accounts or block IPs solely because an address is new. Use corroboration and an approved response process.

Validation matrix

Test scenarioExpected behaviour
Established account, known IPNo novelty result
Established account, new IPCandidate result with evidence
New account with sparse historyExcluded by minimum-history guardrail
Approved VPN IP changeCandidate reviewed and contextualised
Baseline contains attacker IPMay be missed; requires other detections
Delayed or missing sign-in dataDetected by data-quality monitoring, not mistaken for safety

Agent Foskett investigation — the new IP

The candidate rule flags a finance administrator’s successful sign-in from a new IP. The analyst checks the account history, device and Conditional Access context, then discovers the organisation changed its VPN egress address that morning. The signal was valid—the IP really was new—but the behaviour was authorised.

The detection remains useful because it surfaced a change with supporting evidence. The team documents the VPN change, updates the appropriate business context and verifies that a truly unfamiliar source still produces a result. They do not silence the rule with a broad permanent exclusion.

Hands-on lab — Build and validate the behaviour rule

  1. Identify an approved test account with at least 14 days of sign-in history.
  2. Run KQL 1 and record coverage and freshness.
  3. Run KQL 2, inspect returned entities and check whether the 1,000-IP cap is appropriate.
  4. Run KQL 3 and compare results and query cost.
  5. Validate one known IP, one newly observed IP and one sparse-history account.
  6. Document at least three legitimate explanations for a novel IP.
  7. Draft the analytics-rule configuration and analyst triage instructions.
  8. Record known blind spots, test evidence and an owner for ongoing tuning.

Knowledge check

  1. Why does a new IP address not prove account compromise?
  2. What does the minimum-history requirement protect against?
  3. How can a capped make_set() baseline affect results?
  4. Why might a compromised account escape a novelty-based rule?
  5. What should be mapped as entities and retained as alert context?
  6. How would you validate and tune this detection without creating a blind spot?

Lesson 72 takeaway

Behaviour-based detection engineering is about defensible change detection: establish a trustworthy baseline, measure meaningful deviations, preserve investigation context and test the edge cases.

The Logs Already Knew. Agent Foskett Asked What Changed.

Lesson 72 complete — behaviour-based detection engineered!
You have built, tested and contextualised a sign-in behaviour detection with production safeguards.
Sentinel Academy Home

Continue learning

Module 8 — Advanced Detection Engineering and SOC Optimisation • Lesson 2 of 10.
⬅ Previous lesson
Lesson 71 — Advanced Detection Engineering in Microsoft SentinelReview the Module 8 introduction.
🏠 Academy home
Microsoft Sentinel AcademyBrowse all published lessons.
Next lesson • Coming soon
Lesson 73 — Detecting Multi-Stage Attacks with KQLComing soon — automatically activated when published.