Detect suspicious inbox rules in Microsoft 365 (KQL)
After taking over a mailbox, attackers often create an inbox rule that forwards, redirects or silently deletes mail so they can read replies and hide their activity. This OfficeActivity query returns New-InboxRule and Set-InboxRule operations and extracts the parameters that matter — ForwardTo, RedirectTo, DeleteMessage and similar — from the audited command.
It is one of the most reliable business email compromise (BEC) detections because the rule parameters are recorded verbatim in the Microsoft 365 unified audit log.
The query
OfficeActivity
| where TimeGenerated > ago(24h)
| where OfficeWorkload == "Exchange"
| where Operation in ("New-InboxRule", "Set-InboxRule")
| mv-apply p = parse_json(Parameters) on (
where p.Name in (
"ForwardTo", "ForwardAsAttachmentTo", "RedirectTo",
"DeleteMessage", "MoveToFolder", "MarkAsRead")
| project ParamName = tostring(p.Name), ParamValue = tostring(p.Value)
)
| project TimeGenerated, UserId, ClientIP, Operation, ParamName, ParamValue, RuleMailbox = OfficeObjectId
| sort by TimeGenerated descLine-by-line explanation
| where Operation in ("New-InboxRule", "Set-InboxRule")Captures both rule creation and modification; attackers sometimes edit an existing benign rule rather than create a new one.
| mv-apply p = parse_json(Parameters) on ( ... )Parameters is a JSON array of name/value pairs. mv-apply expands it and keeps only the forwarding, redirect and delete actions.
where p.Name in ("ForwardTo", "RedirectTo", "DeleteMessage", ...)These are the parameters that make a rule dangerous — exfiltrating or hiding mail — as opposed to harmless sorting rules.
Required tables and columns
OperationThe audited Exchange operation, such as New-InboxRule or Set-InboxRule.ParametersJSON array of the cmdlet parameters, holding the rule's actions and conditions.UserIdThe mailbox or admin account that created or changed the rule.ClientIPSource IP of the operation, useful for correlating with a suspicious sign-in.
MITRE ATT&CK mapping
Tuning and false positives
- Exclude MoveToFolder/MarkAsRead-only rules if they generate noise; keep the forwarding and redirect actions, which are higher risk.
- Join ClientIP back to SigninLogs to confirm the rule was created from an unusual location.
Limitations
- Forwarding configured through a transport rule or mailbox forwarding (not an inbox rule) appears under different operations such as Set-Mailbox.
- Unified audit logging must be enabled; rules created before it was turned on will not appear.
Related queries
References
Last reviewed 2026-11-18.