Malicious forwarding rules: how to find and block them
Malicious forwarding rules copy or hide mail after an account takeover. See where they hide in Microsoft 365 and Google Workspace, and how to find them.

Malicious forwarding rules are settings an attacker adds to a mailbox after taking it over, so that mail is copied to an outside address or moved out of the owner's sight. To find them, check three places in Microsoft 365 (inbox rules, mailbox forwarding and mail flow rules) and the forwarding settings in Google Workspace, then block automatic forwarding to outside addresses for everyone who does not need it.
The rules keep working after the attacker loses the password. Microsoft lists "Remove any suspicious mailbox forwarding that the attacker added" as its own step, separate from the password reset1.
What malicious forwarding rules do
A forwarding rule gives the attacker a copy of the mail without signing in again. MITRE ATT&CK, the public catalogue of attacker techniques, says forwarding rules "can allow adversaries to maintain persistent access to victim's emails"2.
Hiding rules are the second half. They move incoming mail to a folder the owner never opens, mark it as read, or delete it. MITRE lists this as its own technique, Email Hiding Rules (T1564.008)3. Microsoft's guidance for analysts says attackers move mail "into another less noticeable folder (like RSS), or forward mails to an external account"4.
The rules are written to catch payment mail. Microsoft describes rules that "forward all emails that contain keywords, such as 'finance' and 'invoice' in the subject or message body"5. It also explains why they go unnoticed: "maintenance of inbox rules is common task done by users"5, so one more rule does not stand out.
The full takeover pattern, from stolen sign-in to quiet rule, is in how email account takeover works.
Where forwarding rules hide in Microsoft 365
Microsoft 365 has three separate places that can forward mail. Microsoft names all three: "Inbox Rules, Exchange Transport Rule (ETR), and SMTP Forwarding"6.
| Place | Set by | Fields |
|---|---|---|
| Inbox rule | The mailbox user, or anyone signed in as them | ForwardTo, ForwardAsAttachmentTo, RedirectTo, MoveToFolder, DeleteMessage, MarkAsRead |
| Mailbox forwarding (SMTP forwarding) | An administrator | ForwardingSmtpAddress, ForwardingAddress |
| Mail flow rule (transport rule) | An administrator | CopyTo, BlindCopyTo |
Microsoft says users set inbox rules "deliberately or as a result of a compromised account", while mailbox forwarding is set by an admin7. So an attacker with one user's password can create inbox rules, and an attacker who reaches an admin account can set the other two. Check all three, because a clean inbox rule list does not prove a clean mailbox.
How to find forwarding rules in Microsoft 365
Each place in the table has its own admin view, and the audit log shows when a rule was made.
- REVIEW. In the Exchange admin center, expand Reports, select Mail flow, and open the Auto forwarded messages report8. It lists mail already forwarded to outside domains, with the forwarding type (Mail flow rules, Inbox rules or SMTP forwarding), the forwarder and the recipient domain9. It shows the last 7 days by default, so widen the date range, export it, and run "How to find forwarding rules in Microsoft 365", steps 2 to 4, on every forwarder the business cannot explain. (Google Workspace: no matching report is documented; use "How to find forwarding rules in Google Workspace", step 2.) The report shows forwarding that has sent mail out, so it misses hiding rules and rules that have not fired yet.
- REVIEW. For each mailbox, run
Get-InboxRule -Mailbox <user> -IncludeHidden | Format-List Name,Enabled,RedirectTo,Forward*,Identityin Exchange Online PowerShell1. A value in RedirectTo, ForwardTo or ForwardAsAttachmentTo that the owner did not set is a sign of takeover. Follow "What to do when you find one", steps 1 to 5. (Google Workspace: list filters with the Gmail API method users.settings.filters.list.) The IncludeHidden switch matters because attackers can hide a rule from the normal view2, and the cmdlet does not run under the Global Reader role, so use an Exchange admin account10. - REVIEW. For every rule the owner does not recognise, run
Get-InboxRule -Identity "<rule identity>" -IncludeHidden | Format-Listto show all its fields1, then read the keyword fields (SubjectContainsWords, BodyContainsWords, SubjectOrBodyContainsWords) and any MoveToFolder or MarkAsRead action. Microsoft's analyst guidance says to check whether the destination folder relates to the keywords4. If a rule sends "invoice" or "payment" mail to RSS Subscriptions or Archive and the owner did not create it, treat the account as taken over. (Google Workspace: read the criteria and actions in the same users.settings.filters.list output.) A hiding rule keeps the owner from seeing the attacker's replies in a payment thread. - REVIEW. Run
Get-Mailbox -Identity <user> | Format-List Forwarding*Address,DeliverTo*1. Mailbox forwarding is an admin setting7, so a ForwardingSmtpAddress value that no administrator set on request was set from an admin account. Check admin sign-ins and roles before anything else. (Google Workspace: call users.settings.getAutoForwarding and users.settings.forwardingAddresses.list for the user.) DeliverToMailboxAndForward set to False means the owner never sees the original mail. In the Exchange admin center the same setting is under Recipients > Mailboxes, then Mailbox > Email forwarding11. - REVIEW. In the Exchange admin center, go to Mail flow > Rules and read every rule that copies or redirects mail12. Note each rule with no named owner or business reason, then delete it in "How to stop forwarding rules from working", step 5. (Google Workspace: Menu > Apps > Google Workspace > Gmail > Routing, where a setting can deliver mail to more recipients13.) A mail flow rule can apply to every message in the organisation, so one bad rule can copy everyone's mail.
- REVIEW. In the Microsoft Purview portal, open Audit and search the operations New-InboxRule, Set-InboxRule and UpdateInboxRules, typed exactly14,15. The takeover started no later than each bad rule's creation time, so read back from there to the first suspicious sign-in. (Google Workspace: Menu > Reporting > Audit and investigation > User log events16.) The client and time tell you which sign-in created the rule.
To check a single hijacked account step by step, including the sign-in signs that come before the rule, see how to spot a hijacked mailbox when MFA did not stop it.
How to find forwarding rules in Google Workspace
Google Workspace gives fewer admin views of forwarding rules, so the forwarding setting and the Gmail API do most of the work.
- REVIEW. In the Google Admin console, go to Menu > Apps > Google Workspace > Gmail > End User Access and click Automatic forwarding17. Note every organisational unit where "Allow users to automatically forward incoming email" is on, and which of them has a business need, then change the rest in "How to stop forwarding rules from working", step 1. Google says the setting is on by default17, so every user can forward until you change it.
- REVIEW. For each user, call the Gmail API methods users.settings.getAutoForwarding ("Gets the auto-forwarding setting for the specified account"), users.settings.forwardingAddresses.list and users.settings.filters.list18,19. Google's own guidance for compromised accounts says "You can retrieve user account settings (such as forwarding settings) through the Gmail API"20. Treat any outside address the user cannot explain as a takeover and go to "What to do when you find one". A forwarding address or filter the user did not create is how a hijacked Gmail account sends payment mail out or hides it.
- REVIEW. In the Admin console, go to Menu > Reporting > Audit and investigation > User log events16 and look for the event Google logs when a user "has enabled out of domain email forwarding"21. The event names the destination address. To find who else sent mail to that address, search Menu > Reporting > Audit and investigation > Gmail log events by recipient22, then run "How to find forwarding rules in Google Workspace", step 2, on each sender.
How to stop forwarding rules from working
One outbound policy setting blocks inbox rules and mailbox forwarding to outside addresses for the whole tenant.
- CHANGE. In the Microsoft Defender portal, go to Email & collaboration > Policies & rules > Threat policies > Anti-spam, open the outbound spam policy, and set Automatic forwarding rules to "Off - Forwarding is disabled"23. (Google Workspace: untick "Allow users to automatically forward incoming email", or allow internal addresses only, in "How to find forwarding rules in Google Workspace", step 1.) Microsoft says this "disables any Inbox rules (users) or mailbox forwarding (admins) that redirect messages to external addresses", and the sender gets a bounce with the code
5.7.5207. - CHANGE. In the same outbound spam policy (Email & collaboration > Policies & rules > Threat policies > Anti-spam), set the value explicitly even if you think it is already off23. Microsoft changed the default to Off in 2021 for new organisations, but organisations that were actively using the Automatic setting kept it7. (Google Workspace: set it per organisational unit, Override rather than Inherit.) If a team needs to forward outside, put those users in a separate policy set to On, so the exception has an owner.
- CHANGE. In the Defender portal, go to Email & collaboration > Policies & rules > Alert policy and turn on "Suspicious email forwarding activity" (severity High) and "Creation of forwarding/redirect rule", each with a named recipient who reads them24,25. (Google Workspace: no forwarding alert is documented; schedule "How to find forwarding rules in Google Workspace", step 2.) The second alert only tracks rules made in Outlook on the web or PowerShell, so "How to find forwarding rules in Microsoft 365", step 6, still matters.
- CHANGE. Turn audit logging on if it is off. In Exchange Online PowerShell (not Security & Compliance PowerShell, where the value always shows False), run
Get-AdminAuditLogConfig | Format-List UnifiedAuditLogIngestionEnabled15. If it returns False, turn it on withSet-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $true, or in the Microsoft Purview portal26. (Google Workspace: no equivalent switch is documented.) Without the log you cannot date a rule or see who made it. - CHANGE. Delete each mail flow rule from "How to find forwarding rules in Microsoft 365", step 5, that no one owns, in the same Mail flow > Rules list12. (Google Workspace: delete the unowned setting in the same Routing page13.) Keeping an unowned copy rule leaves an exit no one is watching.
The outbound policy has limits. "Automatic forwarding of messages between internal users isn't affected"7, and a hiding rule that only moves and marks mail is not blocked, so keep the review steps on a schedule.
What to do when you find one
A malicious forwarding rule means someone else has had access to the mailbox. Respond to the account, then to the rule.
- CHANGE. Disable the rule with
Disable-InboxRule -Mailbox <user> -Identity "<rule name>", so it stops while you investigate, then remove it withRemove-InboxRule27. Clear any forwarding the user did not ask for in the Exchange admin center under Recipients > Mailboxes, then Mailbox > Email forwarding11. (Google Workspace: turn off outside forwarding for the user's organisational unit, as in "How to stop forwarding rules from working", step 1.) A disabled rule stops sending mail out at once and keeps its details for the investigation. - CHANGE. Reset the password and revoke sign-in sessions with
Revoke-MgUserSignInSession -UserId <user>1. (Google Workspace: Menu > Directory > Users, Reset password, then the user's Security > Sign in cookies > Reset28.) Microsoft warns: "Don't send the new password to the user through email, because the attacker could have access to the mailbox at this point"1. - REVIEW. Read the audit log from the first suspicious sign-in to the end of the clean-up, as Microsoft advises1. List every message sent to the attacker's address: in the Exchange admin center, go to Mail flow > Message trace and filter by that recipient29. For mail a hiding rule moved, open the folder named in the rule (for example RSS Subscriptions) in the user's mailbox and list what is there. (Google Workspace: Menu > Reporting > Audit and investigation > Gmail log events for the same window22.) The list tells you which threads the attacker read.
- STAFF. Send the finance team the list of invoice and payment threads from "What to do when you find one", step 3, the same day, and ask them to confirm any bank detail in those threads by phone before the next payment30, as in how to check a payment change request. An attacker who read a payment thread can reply in it.
- REVIEW. Check every other mailbox for forwarding to the same outside address: in the Exchange admin center, go to Mail flow > Message trace and filter by that address as the recipient29. (Google Workspace: run "How to find forwarding rules in Google Workspace", step 2, on every user.) Run "What to do when you find one", steps 1 to 4, on each mailbox it finds. One attacker address can receive mail from more than one hijacked account.
Find malicious forwarding rules with AegisAI
AegisAI account takeover detection treats a new inbox rule as one signal among several on the same account, in its page's words: "Impossible travel, new devices, inbox rule changes and suspicious internal sends, weighed together per account"31. The result is "One finding raised, with the reasons and the next steps", so a new rule is read next to the sign-in that came before it.
AegisAI does not revoke sessions today. The page says: "Every finding comes with recommended steps, and your team acts in Entra ID, Okta or Google Workspace"31. The block policy and the review steps above stay your team's job. Book a demo to see how AegisAI reads rule changes and sign-ins together.
Frequently asked questions
Does a password reset remove malicious forwarding rules?
No. Microsoft treats removing forwarding as a separate step from the reset1; see "What to do when you find one", step 1.
Can I see forwarding rules for every mailbox at once?
Partly. The Auto forwarded messages report covers the whole tenant9; see "How to find forwarding rules in Microsoft 365", step 1.
Will blocking outside forwarding break anything?
It stops automatic forwarding to any outside address, including a user's personal account or a partner's inbox. External senders get a bounce. Internal senders get one only when the forwarding is set on the mailbox, not by an inbox rule23. Users with a real need go in their own policy.
How far back can I check when a forwarding rule was created?
Microsoft keeps Exchange Online audit records for one year for users with E5 or an equivalent licence, and 180 days for other users32. A rule older than that window cannot be dated from the audit log.
Are Gmail filters the same as forwarding rules?
A Gmail filter can forward, delete or archive matching mail, so it plays the same part as an Outlook inbox rule. Admins can read a user's filters with the Gmail API method users.settings.filters.list, which "Lists the message filters of a Gmail user"19.
Sources
Each number in the text opens the source with the same number.
- 1Microsoft LearnRespond to a compromised email account in Microsoft 365
- 2MITRE ATT&CKEmail Collection: Email Forwarding Rule, Sub-technique T1114.003
- 3MITRE ATT&CKHide Artifacts: Email Hiding Rules, Sub-technique T1564.008
- 4Microsoft LearnAlert classification for suspicious inbox manipulation rules
- 5Microsoft LearnAlert classification for suspicious inbox forwarding rules
- 6Microsoft LearnAlert classification for suspicious email forwarding activity
- 7Microsoft LearnControl external email forwarding and fix 5.7.520 errors
- 8Microsoft LearnMail flow reports in the new EAC in Exchange Online
- 9Microsoft LearnAuto forwarded messages report in the new Exchange admin center (EAC) in Exchange Online
- 10Microsoft LearnGet-InboxRule (ExchangePowerShell)
- 11Microsoft LearnConfigure email forwarding for a mailbox in Exchange Online
- 12Microsoft LearnManage mail flow rules in Exchange Online
- 13Google Workspace Admin HelpAdd Gmail routing settings
- 14Microsoft LearnAudit log activities
- 15Microsoft LearnSearch the audit log
- 16Google Workspace Admin HelpUser log events
- 17Google Workspace Admin HelpLet users automatically forward their own Gmail emails
- 18Google for DevelopersMethod: users.settings.getAutoForwarding
- 19Google for DevelopersMethod: users.settings.filters.list
- 20Google Workspace Admin HelpIdentify and secure compromised accounts
- 21Google for DevelopersLogin Audit Activity Events
- 22Google Workspace Admin HelpGmail log events
- 23Microsoft LearnConfigure outbound spam policies
- 24Microsoft LearnAlert policies in the Microsoft Defender portal
- 25Microsoft LearnAlert policies in the Microsoft Defender portal: list of default alert policies
- 26Microsoft LearnTurn auditing on or off
- 27Microsoft LearnDetect and remediate Outlook rules and custom forms injection attacks
- 28Google Workspace Admin HelpReset a user's password
- 29Microsoft LearnMessage trace in the new EAC in Exchange Online
- 30National Cyber Security Centre (Ireland)Protecting Against Business Email Compromise and Payment Fraud, 25 July 2025
- 31AegisAIAccount Takeover Protection (Early Access)
- 32Microsoft LearnManage audit log retention policies
.png)