Reference · Accounts and sessions
Hidden inbox rules and forwarding in Microsoft 365, Outlook.com and Gmail
Find the inbox rules attackers hide in a taken-over mailbox: rules that forward mail out, delete it, or move invoices to the RSS folder and mark them read; mailbox SMTP forwarding; Gmail filters; and third-party apps with OAuth access.
| Target artifact | Inbox rules, including hidden ones; mailbox forwarding to an outside address; Gmail filters, forwarding addresses and delegates; third-party apps granted access to the mailbox. |
|---|---|
| Default behaviour | Rules run silently on every new message. After getting into a mailbox, attackers add rules that forward mail out, delete it, or move messages containing words such as "invoice" to a folder nobody reads and mark them read. Some rules do not appear in Outlook. |
| Safe state | Every rule, filter and forwarding address is one you created; automatic forwarding to outside addresses is off for the organization unless someone needs it; only apps you recognize have access. |
| Check in Microsoft 365 | Get-InboxRule -Mailbox user@example.com -IncludeHidden | Format-List Name, Enabled, SubjectOrBodyContainsWords, ForwardTo, RedirectTo, MoveToFolder, MarkAsRead, DeleteMessage |
| Check across the organization | Get-HostedOutboundSpamFilterPolicy | Format-List Name, AutoForwardingMode |
| Check in Gmail | Settings, See all settings, then Forwarding and POP/IMAP and Filters and Blocked Addresses |
| Fix in Microsoft 365 | Disable-InboxRule -Mailbox user@example.com -Identity 'RULE NAME', after saving the rules as evidence |
| Fix across the organization | Set-HostedOutboundSpamFilterPolicy -Identity Default -AutoForwardingMode Off |
| Fix in Gmail | choose Disable forwarding, and delete the filters you did not create |
What a malicious rule looks like
Microsoft's guide for investigating suspicious inbox rules lists these signs:
| Sign | Why it matters |
|---|---|
| Forwards or redirects to an outside address | Copies every matching message to the attacker |
| Deletes messages | Hides replies and security alerts from the owner |
| Moves messages to a little-used folder, such as RSS, and marks them read | The owner never sees them, but the attacker can |
| Looks for words such as "invoice", "phish", "do not reply", "suspicious email" or "spam" | Hides payment conversations and warnings |
| Has no condition at all, or deletes every incoming message | Catches everything; Microsoft calls a rule that deletes all incoming mail with no keyword filter an indicator of malicious activity |
In Microsoft 365, the conditions sit in SubjectContainsWords, BodyContainsWords and SubjectOrBodyContainsWords. For a rule that moves messages and marks them read, Microsoft suggests checking whether the destination folder has anything to do with the words the rule looks for.
Microsoft 365
Connect, list and save the evidence
Connect-ExchangeOnline
Get-InboxRule -Mailbox user@example.com -IncludeHidden | Format-List Name, Enabled, From, SubjectContainsWords, BodyContainsWords, SubjectOrBodyContainsWords, ForwardTo, ForwardAsAttachmentTo, RedirectTo, MoveToFolder, MarkAsRead, DeleteMessage
Get-InboxRule -Mailbox user@example.com -IncludeHidden | Export-Clixml -Path .\inbox-rules-evidence.xml-IncludeHidden matters: attackers sometimes create rules that do not show up in Outlook.
Mailbox forwarding (SMTP forwarding)
Forwarding can also be set on the mailbox itself, outside any rule:
Get-Mailbox -Identity user@example.com | Format-List Forwarding*Address, DeliverTo*
Set-Mailbox -Identity user@example.com -ForwardingAddress $null -ForwardingSmtpAddress $null -DeliverToMailboxAndForward $falseTurn off automatic forwarding to outside addresses
The outbound spam policy's Automatic forwarding setting controls both inbox rules and mailbox forwarding that send mail to outside addresses. Its default, Automatic, meant on when it was introduced and was changed to off in 2021, but organizations that were already using it can still have forwarding on. Microsoft advises setting On or Off explicitly:
Get-HostedOutboundSpamFilterPolicy | Format-List Name, AutoForwardingMode
Set-HostedOutboundSpamFilterPolicy -Identity Default -AutoForwardingMode OffWith Off, a forwarded message bounces with the error 5.7.520 Access denied, Your organization does not allow external forwarding. Forwarding between internal users is not affected. If someone needs to forward outside, give them a separate policy rather than turning it on for everyone.
When were rules created or changed?
Search-UnifiedAuditLog -StartDate (Get-Date).AddDays(-30) -EndDate (Get-Date) -Operations New-InboxRule, Set-InboxRule, UpdateInboxRules -ResultSize 1000 | Select-Object CreationDate, UserIds, Operations, AuditDataMicrosoft has announced the retirement of Search-UnifiedAuditLog on 15 October 2027 in favour of the Microsoft Graph audit log query API.
Apps the user gave access
Users can review and revoke their own grants at myapplications.microsoft.com: hover over an app, select the three dots, Manage your application, then Revoke Permissions. Permissions an administrator consented to can only be removed by an administrator, who can list a user's grants with Microsoft Graph PowerShell:
Get-MgUserOauth2PermissionGrant -UserId user@example.com | Select-Object ClientId, ConsentType, ScopeWarning Outlook client rules
Changing inbox rules with PowerShell removes any client-side rules the user created in Outlook. Tell the user before you do it.
Outlook.com and Gmail
Outlook.com
In Settings, open Mail, then check Forwarding and Rules. Turn off forwarding to any address you did not add, and delete rules you did not create.
Gmail
In Settings, choose See all settings, then:
- Forwarding and POP/IMAP: choose Disable forwarding if there is an address you did not add.
- Filters and Blocked Addresses: delete filters that forward, delete, archive or mark as read mail you did not set up.
- Accounts and Import, under Grant access to your account: remove any delegate you do not recognize.
Then review Linked apps at myaccount.google.com/linkedapps and choose Remove access for anything unfamiliar.
Remove the rules only after the account is secured: change the password and end every session first, or the attacker can put them back. See Account compromise triage.
Related guides and lookups
Sources
- Microsoft Learn: alert grading for suspicious inbox manipulation rules
- Microsoft Learn: Get-InboxRule
- Microsoft Learn: responding to a compromised email account
- Microsoft Learn: outbound spam policies and external email forwarding
- Microsoft Learn: Set-HostedOutboundSpamFilterPolicy
- Microsoft Support: revoke application permissions in My Apps
- Microsoft Learn: Get-MgUserOauth2PermissionGrant
- Office 365 for IT Pros: Search-UnifiedAuditLog retirement, October 2026
- Gmail Help: automatic forwarding
- Gmail Help: filters
- Gmail Help: delegates
- Google Account Help: linked apps