Query Details
// Hunt : M365 - Inbox Rule and Transport Rule Audit (30d)
// Purpose : Full audit of all Exchange inbox and transport rules created or modified
// in the past 30 days, pre-calculated for forwarding, redirect and hiding
// indicators to support BEC and exfiltration investigations.
// Tables : OfficeActivity
// Period : P30D
//==========================================================================================
let LookbackDays = 30d;
OfficeActivity
| where TimeGenerated > ago(LookbackDays)
| where RecordType == "ExchangeAdmin"
| where Operation in (
"New-InboxRule", "Set-InboxRule", "Remove-InboxRule",
"New-TransportRule", "Set-TransportRule",
"Enable-TransportRule", "Disable-TransportRule",
"Remove-TransportRule", "New-JournalRule")
| extend Params = tostring(Parameters)
| extend
HasForward = Params has_any ("ForwardTo", "ForwardAsAttachmentTo", "RedirectTo", "RedirectMessageTo"),
HasHide = Params has_any ("DeleteMessage", "MoveToFolder", "MarkAsRead"),
HasBypass = Params has_any ("ExceptIfSenderDomainIs", "SetHeaderName"),
ExternalAddress = extract(@"(ForwardTo|RedirectTo|RedirectMessageTo).*?([a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,})", 2, Params),
FolderTarget = extract(@"(MoveToFolder).*?:([^\s,]+)", 2, Params)
| project
TimeGenerated,
UserId,
ClientIP,
Operation,
HasForward,
HasHide,
HasBypass,
ExternalAddress,
FolderTarget,
Params
| sort by TimeGenerated desc
This query is designed to audit changes to Exchange inbox and transport rules over the past 30 days. It helps identify potential security issues, such as Business Email Compromise (BEC) or data exfiltration. Here's a simple breakdown:
Time Frame: The query looks at activities from the last 30 days.
Data Source: It uses the OfficeActivity table, focusing on records related to Exchange administration.
Operations Monitored: It filters for specific operations related to inbox and transport rules, such as creating, modifying, or removing these rules.
Indicators: The query checks for certain actions within the rule parameters:
Extracted Information: It extracts email addresses involved in forwarding/redirecting and folder targets for moved emails.
Output: The results include the time of the activity, user ID, client IP, type of operation, and the extracted indicators, sorted by the most recent activity.
This query is useful for security investigations to detect unauthorized or suspicious email rule changes.

David Alonso
Released: March 18, 2026
Tables
Keywords
Operators