Configure anti-malware policies in EOP

Important

Welcome to Microsoft Defender for Office 365, the new name for Office 365 Advanced Threat Protection. Read more about this and other updates in Microsoft delivers unified SIEM and XDR to modernize security operations.

In Microsoft 365 organizations with mailboxes in Exchange Online or standalone Exchange Online Protection (EOP) organizations without Exchange Online mailboxes, email messages are automatically protected against malware by EOP. EOP uses anti-malware policies for malware protection settings. For more information, see Anti-malware protection.

Admins can view, edit, and configure (but not delete) the default anti-malware policy to meet the needs of their organizations. For greater granularity, you can also create custom anti-malware policies that apply to specific users, groups, or domains in your organization. Custom policies always take precedence over the default policy, but you can change the priority (running order) of your custom policies.

You can configure anti-malware policies in the Security & Compliance Center or in PowerShell (Exchange Online PowerShell for Microsoft 365 organizations with mailboxes in Exchange Online; standalone EOP PowerShell for organizations without Exchange Online mailboxes).

What do you need to know before you begin?

Use the Security & Compliance Center to create anti-malware policies

Creating a custom anti-malware policy in the Security & Compliance Center creates the malware filter rule and the associated malware filter policy at the same time using the same name for both.

  1. In the Security & Compliance Center, go to Threat management > Policy > Anti-Malware, and then click New Add Icon.

  2. In the New anti-malware policy page that opens, configure these settings:

    • Name: Enter a unique, descriptive name for the policy.

    • Description: Enter an optional description for the policy.

    • Malware detection response: Select one of these values for the Do you want to notify recipients if their messages are quarantined? setting:

      • No: The message is quarantined with no notification to the intended recipients. This is the default value.

      • Yes and use the default notification text: The message is quarantined. A copy of the message is delivered to the recipients, but all attachments (not just the detected ones) are replaced with a single text file named Malware Alert Text.txt that contains the default text. For the default text, see Anti-malware policies.

      • Yes and use the custom notification text: The message is quarantined. A copy of the message is delivered to the recipients, but all attachments (not just the detected ones) are replaced with a single text file named Malware Alert Text.txt contains custom text you specify in the Custom alert text box.

    • Common Attachment Types Filter: Select one of these values for blocking attachment types that may harm your computer.:

      • Off

      • On: Messages with the specified attachments are treated as malware detections and are automatically quarantined. You can modify the list bu clicking the Add and Remove buttons.

    • Malware Zero-hour Auto Purge: Malware ZAP quarantines messages that have already been delivered. For more information, see Zero-hour auto purge (ZAP) in Exchange Online. Select one of these values:

      • Off

      • On (Recommended)

    • Notification: The settings in this section control sender and admin notifications when malware is detected in a message.

      • Sender Notifications: Select one or both of these options:

        • Notify internal senders: An internal sender is inside the organization.

        • Notify external senders: An external sender is outside the organization.

      • Administrator Notifications: Select one or both of these options:

        • Notify administrator about undelivered messages from internal senders: If you select this option, enter a notification email address in the Administrator email address box.

        • Notify administrator about undelivered messages from external senders: If you select this option, enter a notification email address in the Administrator email address box.

      • Customize Notifications: These settings replace the default notification text that's used for senders or administrators. For more information about the default values, see Anti-malware policies.

        • Use customized notification text: If you select this option, you need to use the From name and From address boxes to specify the sender's name and email address that's used in the customized notification message.

        • Messages from internal senders: If you elected to notify senders or administrators about undeliverable messages from internal senders, you need to use the Subject and Message boxes to specify the subject and message body of the custom notification message.

        • Messages from external senders: If you elected to notify senders or administrators about undeliverable messages from external senders, you need to use the Subject and Message boxes to specify the subject and message body of the custom notification message.

    • Applied to: The settings in this section identify the internal recipients that the policy applies to.

      • If: Click on the Select one drop-down, and select conditions for the rule:

        • The recipient is: Specifies one or more mailboxes, mail users, or mail contacts in your organization. In the Select members dialog box that appears, select one or more recipients from the list, and then click add ->. In the Check names box, you can use wildcards for multiple email addresses (for example: *@fabrikam.com). When you're finished, click OK.

        • The recipient domain is: Specifies recipients in one or more of the configured accepted domains your organization. In the dialog box that appears, select one or more domains, and then click add ->. When you're finished, click OK.

        • The recipient is a member of: Specifies one or more groups in your organization. In the Select members dialog box that appears, select one or more groups from the list, and then click add ->. When you're finished, click OK.

      You can only use a condition once, but you can specify multiple values for the condition. Multiple values of the same condition use OR logic (for example, <recipient1> or <recipient2>). Different conditions use AND logic (for example, <recipient1> and <member of group 1>). To add more conditions, click Add condition and select from the remaining options.

      • Except if: To add exceptions for the rule, click Add exception, click on the Select one drop-down, and configure the exceptions. The settings and behavior are exactly like the conditions.
  3. When you're finished, click Save.

Use the Security & Compliance Center to view anti-malware policies

  1. In the Security & Compliance Center, go to Threat management > Policy > Anti-Malware.

  2. When you select a policy, information about the policy is displayed in the details pane. To see more information about the policy, click Edit Edit icon.

    • The Enabled property value, the Priority property value, and the settings on the Applied to tab are in the malware filter rule.

    • The settings on the General and Settings tabs are in the malware filter policy.

Use the Security & Compliance Center to modify anti-malware policies

  1. In the Security & Compliance Center, go to Threat management > Policy > Anti-Malware.

  2. Select the policy, and then click Edit Edit icon. For information about the settings, see the Use the Security & Compliance Center to create anti-malware policies section in this topic.

    Notes:

    • Instead of everything on one page, the settings are divided among the General, Settings, and Applied to tabs. The Applied to tab isn't available in the default policy named Default (which is automatically applied to everyone).

    • You can't rename the default policy.

Use the Security & Compliance Center to enable or disable anti-malware policies

  1. In the Security & Compliance Center, go to Threat management > Policy > Anti-Malware.

  2. Select the policy from the list, and then configure one of the following settings:

    • Disable the policy: Clear the check box in the Enabled column. By default, anti-malware policies are enabled when you create them in the Security & Compliance Center.

    • Enable the policy: Select the check box in the Enabled column.

Use the Security & Compliance Center to set the priority of custom anti-malware policies

By default, anti-malware policies are given a priority that's based on the order they were created in (newer polices are lower priority than older policies). A lower priority number indicates a higher priority for the policy, and policies are processed in priority order (higher priority policies are processed before lower priority policies). No two policies can have the same priority, and policy processing stops after the first policy is applied.

Notes:

  • In the Security & Compliance Center, you can only change the priority of the anti-malware policy after you create it. In PowerShell, you can override the default priority when you create the malware filter rule (which can affect the priority of existing rules).

  • In the Security & Compliance Center, anti-malware policies are processed in the order that they're displayed (the first policy has the Priority value 0). The default anti-malware policy named Default has the priority value Lowest, and you can't change it.

To change the priority of a policy, move the policy up or down in the list (you can't directly modify the Priority number in the Security & Compliance Center).

  1. In the Security & Compliance Center, go to Threat management > Policy > Anti-Malware.

  2. Select a policy, and then click Move up Up Arrow icon or Move down Down Arrow icon to move the rule up or down in the list.

Use the Security & Compliance Center to remove anti-malware policies

When you use the Security & Compliance Center to remove an anti-malware policy, the malware filter rule and the corresponding malware filter policy are both deleted.

  1. In the Security & Compliance Center, go to Threat management > Policy > Anti-Malware.

  2. Select the anti-malware policy you want to remove from the list, and then click Delete Delete icon.

Use Exchange Online PowerShell or standalone EOP PowerShell to configure anti-malware policies

Use PowerShell to create anti-malware policies

Creating an anti-malware policy in PowerShell is a two-step process:

  1. Create the malware filter policy.

  2. Create the malware filter rule that specifies the malware filter policy that the rule applies to.

Notes:

  • You can create a new malware filter rule and assign an existing, unassociated malware filter policy to it. A malware filter rule can't be associated with more than one malware filter policy.

  • There are two settings that you can configure on new anti-malware policies in PowerShell that aren't available in the Security & Compliance Center until after you create the policy:

    • Create the new policy as disabled (Enabled $false on the New-MalwareFilterRule cmdlet).

    • Set the priority of the policy during creation (Priority <Number>) on the New-MalwareFilterRule cmdlet).

  • A new malware filter policy that you create in PowerShell isn't visible in the Security & Compliance Center until you assign the policy to a malware filter rule.

Step 1: Use PowerShell to create a malware filter policy

Note: In EOP, the Action parameter values DeleteMessage, DeleteAttachmentAndUseDefaultAlert, and DeleteAttachmentAndUseCustomAlert don't delete messages. Instead, the messages are quarantined. For more information about retrieving quarantined messages, see Manage quarantined messages and files as an admin in EOP.

To create a malware filter policy, use this syntax:

New-MalwareFilterPolicy -Name "<PolicyName>" [-Action <DeleteMessage | DeleteAttachmentAndUseDefaultAlert | DeleteAttachmentAndUseCustomAlert>] [-AdminDisplayName "<OptionalComments>"] [-CustomNotifications <$true | $false>] [<Inbound notification options>] [<Outbound notification options>]

This example creates a new malware filter policy named Contoso Malware Filter Policy with these settings:

  • Quarantine messages that contain malware without notifying the recipients (we aren't using the Action parameter, and the default value is DeleteMessage).

  • Don't notify the message sender when malware is detected in the message (we aren't using the EnableExternalSenderNotifications or EnableInternalSenderNotifications parameters, and the default value for both is $false).

  • Notify the administrator admin@contoso.com when malware is detected in a message from an internal sender.

New-MalwareFilterPolicy -Name "Contoso Malware Filter Policy" -EnableInternalSenderAdminNotifications $true -InternalSenderAdminAddress admin@contoso.com

For detailed syntax and parameter information, see New-MalwareFilterPolicy.

Step 2: Use PowerShell to create a malware filter rule

To create a malware filter rule, use this syntax:

New-MalwareFilterRule -Name "<RuleName>" -MalwareFilterPolicy "<PolicyName>" <Recipient filters> [<Recipient filter exceptions>] [-Comments "<OptionalComments>"]

This example creates a new malware filter rule named Contoso Recipients with these settings:

  • The malware filter policy named Contoso Malware Filter Policy is associated with the rule.

  • The rule applies to recipients in the contoso.com domain.

New-MalwareFilterRule -Name "Contoso Recipients" -MalwareFilterPolicy "Contoso Malware Filter Policy" -RecipientDomainIs contoso.com

For detailed syntax and parameter information, see New-MalwareFilterRule.

Use PowerShell to view malware filter policies

To return a summary list of all malware filter policies, run this command:

Get-MalwareFilterPolicy

To return detailed information about a specific malware filter policy, use the this syntax:

Get-MalwareFilterPolicy -Identity "<PolicyName>" | Format-List [<Specific properties to view>]

This example returns all the property values for the malware filter policy named Executives.

Get-MalwareFilterPolicy -Identity "Executives" | Format-List

This example returns only the specified properties for the same policy.

Get-MalwareFilterPolicy -Identity "Executives" | Format-List Action,AdminDisplayName,CustomNotifications,Enable*Notifications

For detailed syntax and parameter information, see Get-MalwareFilterPolicy.

Use PowerShell to view malware filter rules

To return a summary list of all malware filter rules, run this command:

Get-MalwareFilterRule

To filter the list by enabled or disabled rules, run the following commands:

Get-HostedContentFilterRule -State Disabled
Get-HostedContentFilterRule -State Enabled

To return detailed information about a specific malware filter rule, use this syntax:

Get-MalwareFilterRule -Identity "<RuleName>" | Format-List [<Specific properties to view>]

This example returns all the property values for the malware filter rule named Executives.

Get-MalwareFilterRule -Identity "Executives" | Format-List

This example returns only the specified properties for the same rule.

Get-MalwareFilterRule -Identity "Executives" | Format-List Name,Priority,State,MalwareFilterPolicy,*Is,*SentTo,*MemberOf

For detailed syntax and parameter information, see Get-MalwareFilterRule.

Use PowerShell to modify malware filter policies

Other than the following items, the same settings are available when you modify a malware filter policy in PowerShell as when you create the policy as described in the Step 1: Use PowerShell to create a malware filter policy section earlier in this topic.

  • The MakeDefault switch that turns the specified policy into the default policy (applied to everyone, unmodifiable Lowest priority, and you can't delete it) is only available when you modify a malware filter policy in PowerShell.

  • You can't rename a malware filter policy (the Set-MalwareFilterPolicy cmdlet has no Name parameter). When you rename an anti-malware policy in the Security & Compliance Center, you're only renaming the malware filter rule.

To modify a malware filter policy, use this syntax:

Set-MalwareFilterPolicy -Identity "<PolicyName>" <Settings>

For detailed syntax and parameter information, see Set-MalwareFilterPolicy.

Use PowerShell to modify malware filter rules

The only setting that isn't available when you modify a malware filter rule in PowerShell is the Enabled parameter that allows you to create a disabled rule. To enable or disable existing malware filter rules, see the next section.

Otherwise, no additional settings are available when you modify a malware filter rule in PowerShell. The same settings are available when you create a rule as described in the Step 2: Use PowerShell to create a malware filter rule section earlier in this topic.

To modify a malware filter rule, use this syntax:

Set-MalwareFilterRule -Identity "<RuleName>" <Settings>

For detailed syntax and parameter information, see Set-MalwareFilterRule.

Use PowerShell to enable or disable malware filter rules

Enabling or disabling a malware filter rule in PowerShell enables or disables the whole anti-malware policy (the malware filter rule and the assigned malware filter policy). You can't enable or disable the default anti-malware policy (it's always always applied to all recipients).

To enable or disable a malware filter rule in PowerShell, use this syntax:

<Enable-MalwareFilterRule | Disable-MalwareFilterRule> -Identity "<RuleName>"

This example disables the malware filter rule named Marketing Department.

Disable-MalwareFilterRule -Identity "Marketing Department"

This example enables same rule.

Enable-MalwareFilterRule -Identity "Marketing Department"

For detailed syntax and parameter information, see Enable-MalwareFilterRule and Disable-MalwareFilterRule.

Use PowerShell to set the priority of malware filter rules

The highest priority value you can set on a rule is 0. The lowest value you can set depends on the number of rules. For example, if you have five rules, you can use the priority values 0 through 4. Changing the priority of an existing rule can have a cascading effect on other rules. For example, if you have five custom rules (priorities 0 through 4), and you change the priority of a rule to 2, the existing rule with priority 2 is changed to priority 3, and the rule with priority 3 is changed to priority 4.

To set the priority of a malware filter rule in PowerShell, use the following syntax:

Set-MalwareFilterRule -Identity "<RuleName>" -Priority <Number>

This example sets the priority of the rule named Marketing Department to 2. All existing rules that have a priority less than or equal to 2 are decreased by 1 (their priority numbers are increased by 1).

Set-MalwareFilterRule -Identity "Marketing Department" -Priority 2

Notes:

  • To set the priority of a new rule when you create it, use the Priority parameter on the New-MalwareFilterRule cmdlet instead.

  • The default malware filter policy doesn't have a corresponding malware filter rule, and it always has the unmodifiable priority value Lowest.

Use PowerShell to remove malware filter policies

When you use PowerShell to remove a malware filter policy, the corresponding malware filter rule isn't removed.

To remove a malware filter policy in PowerShell, use this syntax:

Remove-MalwareFilterPolicy -Identity "<PolicyName>"

This example removes the malware filter policy named Marketing Department.

Remove-MalwareFilterPolicy -Identity "Marketing Department"

For detailed syntax and parameter information, see Remove-MalwareFilterPolicy.

Use PowerShell to remove malware filter rules

When you use PowerShell to remove a malware filter rule, the corresponding malware filter policy isn't removed.

To remove a malware filter rule in PowerShell, use this syntax:

Remove-MalwareFilterRule -Identity "<PolicyName>"

This example removes the malware filter rule named Marketing Department.

Remove-MalwareFilterRule -Identity "Marketing Department"

For detailed syntax and parameter information, see Remove-MalwareFilterRule.

How do you know these procedures worked?

Use the EICAR.TXT file to verify your anti-malware policy settings

Important

The EICAR.TXT file is not a virus. The European Institute for Computer Antivirus Research (EICAR) developed this file to safely test anti-virus installations and settings.

  1. Open Notepad and paste the following text into an empty file:

    X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
    

    Be sure that these are the only text characters in the file. The file size should be 68 bytes.

  2. Save the file as EICAR.TXT

    In your desktop anti-virus program, be sure to exclude the EICAR.TXT from scanning (otherwise, the file will be quarantined).

  3. Send an email message that contains the EICAR.TXT file as an attachment, using an email client that won't automatically block the file. Use your anti-malware policy settings to determine the following scenarios to test:

    • Email from an internal mailbox to an internal recipient.

    • Email from an internal mailbox to an external recipient.

    • Email from an external mailbox to an internal recipient.

  4. Verify that the message was quarantined, and verify the recipient and sender notification results based on your anti-malware policy settings. For example:

    • Recipients aren't notified, or recipients receive the original message with the EICAR.TXT attachment replaced by Malware Alert Text.txt that contains the default or customized text.

    • Internal or external senders are notified with the default or customized notification messages.

    • The admin email address that you specified is notified for internal or external message senders, with the default or customized notification messages.

  5. Delete the EICAR.TXT file after your testing is complete (so other users aren't unnecessarily alarmed by it).