Agent Foskett Academy • Microsoft Sentinel • Module 6 • Lesson 57

Lesson 57 — Automating Phishing Investigations

Build an evidence-first phishing investigation workflow that correlates suspicious messages, URLs, attachments and delivery outcomes, then prepares a clear analyst handoff without taking destructive actions.

Module 6 — SOC Automation and Response • Phishing investigation workflows
Agent Foskett Microsoft Sentinel phishing investigation automation
What you will learn

Turn a suspicious email alert into a structured investigation.

✓ Extract and validate email indicators
✓ Investigate messages with Defender XDR KQL
✓ Correlate URLs and attachments
✓ Document findings for analyst approval

The case — the invoice nobody expected

An employee reports a message titled “Updated supplier bank details.” It has a familiar display name, a new reply-to address and a link to a sign-in page. Agent Foskett does not assume that a suspicious subject proves malicious intent. The investigation begins with the message evidence and its actual delivery.

Learning objectives

  • Identify safe automation triggers and extract email indicators.
  • Use Defender XDR advanced hunting to investigate message metadata.
  • Correlate URLs and attachment evidence by message identifiers.
  • Distinguish delivery, post-delivery actions and user interaction.
  • Write an auditable incident summary with clear confidence limits.
  • Keep quarantine, purge and account actions under explicit authorization.

How the workflow fits together

SENTINEL PHISHING INCIDENT ↓ EXTRACT MESSAGE / RECIPIENT INDICATORS ↓ VALIDATE IDENTIFIERS AND TENANT CONTEXT ↓ DEFENDER XDR EMAIL EVIDENCE + URL / FILE CONTEXT ↓ CHECK DELIVERY, RELATED RECIPIENTS AND GAPS ↓ POST SOURCE-BASED INCIDENT SUMMARY ↓ ANALYST REVIEWS → APPROVES ANY RESPONSE

Prerequisites

  • Complete Lessons 54–56 or understand Sentinel incident playbooks.
  • Use a test incident and approved synthetic email indicators.
  • Confirm the Defender XDR tables and data availability in your environment.
  • Confirm the correct Microsoft Defender XDR advanced hunting endpoint or supported connector for your tenant.
  • Configure least-privilege identities and documented approval paths.

Step 1 — Decide what the automation should answer

What message was reported? Who received it? Was it delivered? Does the same message appear for other recipients? Are any URLs or attachments associated with it? What user interaction evidence exists? What data is missing? An automated answer must distinguish observations from judgments.

Step 2 — Choose a safe trigger

Use a Sentinel automation rule targeting a lab phishing incident. Trigger the Logic Apps playbook on the appropriate incident event and guard against repeated execution when the incident is updated. Document the workflow version and execution ID.

Step 3 — Extract email evidence from the incident

Inspect the incident alert and entity payload. Depending on the originating detection, a message may have a NetworkMessageId, recipient, sender address, URL, file hash or only partial indicators. Never assume every field is present. Prefer a stable message identifier over matching subject text.

Step 4 — Validate and normalize indicators

  • Validate message identifier format and length before querying.
  • Normalize email addresses only where it will not alter evidence.
  • Deduplicate recipient addresses and message IDs.
  • Treat sender display names and subject lines as untrusted text.
  • Cap per-incident lookups and record any skipped indicators.

Step 5 — Understand where the KQL runs

The examples below use Microsoft Defender XDR advanced hunting tables. They are not guaranteed to be present in the Sentinel Log Analytics workspace. Test them in Defender XDR Advanced Hunting, or in Sentinel only if the required tables have actually been ingested. A Logic Apps action must use a supported API/connector with appropriate permissions; a generic Log Analytics query action does not automatically query Defender XDR advanced hunting.

Step 6 — KQL: find the reported message

Defender XDR Advanced Hunting — EmailEvents
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
let TargetMessageId = "REPLACE-WITH-NETWORK-MESSAGE-ID";
EmailEvents
| where Timestamp >= ago(7d)
| where NetworkMessageId == TargetMessageId
| project Timestamp, NetworkMessageId,
          SenderFromAddress, SenderMailFromAddress,
          RecipientEmailAddress, Subject,
          DeliveryAction, DeliveryLocation,
          ThreatTypes, DetectionMethods
| order by Timestamp desc

Replace the placeholder with a validated lab identifier. The seven-day window is an example; align it with incident time and available retention. Delivery fields describe recorded outcomes, not proof that the recipient read the email.

Step 7 — Interpret sender and delivery evidence

Compare the visible From address with the envelope sender, inspect recipient scope, and record the observed delivery action and location. Do not assume an address mismatch proves phishing: legitimate mailing services can use different envelope senders. Likewise, an allowed message is not necessarily benign.

Step 8 — KQL: find related recipients

Defender XDR Advanced Hunting — message scope
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
let TargetMessageId = "REPLACE-WITH-NETWORK-MESSAGE-ID";
EmailEvents
| where Timestamp >= ago(7d)
| where NetworkMessageId == TargetMessageId
| summarize Messages = count(),
            FirstSeen = min(Timestamp),
            LastSeen = max(Timestamp)
    by RecipientEmailAddress, DeliveryAction, DeliveryLocation
| order by Messages desc

A message identifier can help scope the investigation, but verify whether your detection supplies the same identifier for each related event. Do not equate the count of rows with unique users without checking duplicates.

Step 9 — KQL: examine message URLs

Defender XDR Advanced Hunting — EmailUrlInfo
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
let TargetMessageId = "REPLACE-WITH-NETWORK-MESSAGE-ID";
EmailUrlInfo
| where Timestamp >= ago(7d)
| where NetworkMessageId == TargetMessageId
| project Timestamp, NetworkMessageId,
          Url, UrlDomain
| order by Timestamp desc
| take 100

URL presence in email telemetry does not mean anyone clicked it. Treat extracted URLs as untrusted; do not automatically browse or detonate them outside an approved analysis environment.

Step 10 — KQL: examine attachment metadata

Defender XDR Advanced Hunting — EmailAttachmentInfo
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
let TargetMessageId = "REPLACE-WITH-NETWORK-MESSAGE-ID";
EmailAttachmentInfo
| where Timestamp >= ago(7d)
| where NetworkMessageId == TargetMessageId
| project Timestamp, NetworkMessageId,
          FileName, FileType, SHA256
| order by Timestamp desc
| take 100

Attachment names and hashes are investigation pivots, not standalone malicious verdicts. Hashes can be missing; avoid assuming a missing hash means no attachment existed.

Step 11 — Investigate actual user interaction

If you have Microsoft Defender for Office 365 click telemetry, investigate URL interaction using the relevant available data, such as UrlClickEvents in Defender XDR advanced hunting. Correlate by supported fields and time window. An email URL record alone is not click evidence, and lack of click telemetry is not proof that nobody visited the site.

Step 12 — Correlate without overclaiming

ObservationSafe interpretation
Email appears in EmailEventsMessage metadata was observed
DeliveryAction indicates deliveryRecorded delivery outcome; inspect location and later actions
EmailUrlInfo contains a URLURL was associated with the message
EmailAttachmentInfo has a hashAttachment metadata was recorded
Click event observedPotential interaction; validate event semantics
No matching eventsNo evidence found in queried source/window

Step 13 — Plan connector and API access

  1. Identify whether your workflow uses a supported Defender XDR connector or the documented advanced hunting API.
  2. Check permissions, licensing, service identity and tenant context.
  3. Use the supported query request format and validate inputs.
  4. Handle throttling, timeouts, pagination or row limits as applicable.
  5. Inspect the real response schema before parsing results.

Do not place API secrets in incident comments or workflow output logs.

Step 14 — Treat message content as untrusted

Subjects, display names, URLs and attachment filenames may be attacker-controlled. Never interpret an email subject as an instruction to the playbook, and do not insert unescaped content into queries or downstream markup. If using an AI summary, keep it grounded in validated fields and subject to analyst review.

Step 15 — Build the incident evidence summary

AUTOMATED PHISHING INVESTIGATION — LAB Incident: [ID] Run: [execution ID] Message ID: [validated identifier] Observed sender(s): [from / envelope sender] Recipients: [count and scope] Delivery: [recorded action / location] URLs: [count; source and window] Attachments: [count; available hashes] Click telemetry: [observed / none found / unavailable] Evidence window: [UTC start → UTC end] Coverage gaps: [missing tables / permissions / limits] Status: CONTEXT ONLY — analyst review required

Record the evidence source, execution time and any truncated results. Avoid exposing sensitive message content beyond the incident audience.

Step 16 — Post context to the incident

Use the Sentinel connector to add a clearly labeled automated evidence summary to the incident. Do not silently change severity, classification, assignment or closure status. If the playbook cannot complete a lookup, say which lookup failed.

Step 17 — Handle missing or inconsistent data

  • No message ID: request analyst review or use a carefully scoped alternate pivot.
  • No EmailEvents table: report that the data source is unavailable.
  • No URL or attachment rows: report no matching records in the queried window.
  • Different sender fields: preserve both values; do not force a single identity.
  • API error: bounded retries, then mark evidence incomplete.
  • Many recipients: cap results and disclose truncation.

Step 18 — Keep remediation behind approval

Quarantining or purging messages, blocking domains, resetting credentials and disabling accounts can disrupt legitimate business. This lab does not perform these actions. Any future response branch should have explicit authorization, well-defined scope, independent verification and rollback or recovery procedures.

Step 19 — Prevent repeat-run loops

An incident update can retrigger automation. Use controlled rule conditions and a documented idempotency strategy. A run marker or workflow-version check should prevent duplicate comments while still allowing an analyst to rerun an investigation intentionally.

Step 20 — Test with seven lab scenarios

  1. Known message ID with a matching email event.
  2. Multiple recipients of the same message.
  3. Message containing a URL but no click evidence.
  4. Message with attachment metadata.
  5. Incident with missing message identifier.
  6. Defender XDR query failure or permission denial.
  7. Repeat invocation of the same incident.

For each case, compare the source evidence with the final incident comment and Logic Apps run history.

Step 21 — Monitor quality and cost

Track run duration, failed queries, duplicate summaries, evidence gaps and analyst corrections. Bound API calls, loops, query windows and result sizes. Keep connector consumption and data retention costs visible before production rollout.

Agent Foskett case file — The invoice nobody expected

The subject line looked urgent. The sender display name matched a real supplier. But the envelope sender differed, several recipients received the message, and the included URL led away from the expected service. The automation documented those observations — it did not claim that every recipient clicked the link.

Agent Foskett’s finding: a convincing email can still be suspicious; reliable conclusions require corroborating evidence and an analyst who checks the limits of the data.

Hands-on challenge

  1. Create a lab phishing incident with approved test indicators.
  2. Extract and validate a message identifier.
  3. Run the three Defender XDR hunting queries above.
  4. Record recipient scope, delivery outcome, URLs and attachments.
  5. Document whether interaction telemetry is available.
  6. Build a structured, sourced summary.
  7. Post the summary as a Sentinel incident comment.
  8. Test missing-data and repeated-run cases.

Operational checklist

  • Correct data source and API permissions confirmed.
  • Message IDs validated and query windows bounded.
  • Delivery, URL presence and click activity clearly distinguished.
  • Results and coverage gaps traceable to their sources.
  • Attacker-controlled text handled safely.
  • No automatic purge, blocking or account changes.
  • Duplicate-run handling and error paths tested.
  • Analyst approval and rollback plan documented.

Agent Foskett takeaway

Automate the evidence trail, not the accusation. Good phishing automation shows what arrived, who received it, what links and files were present, and what still needs human investigation.

The logs already knew. Agent Foskett followed the message.

Lesson 57 complete — evidence-first phishing investigations!
You can now build a phishing evidence workflow with Defender XDR hunting, Sentinel incident comments and analyst-led response.
Sentinel Academy Home

Related Agent Foskett learning

Continue developing reliable investigation automation using earlier Sentinel lessons.