Configure anti-malware policies in EOP

Tip

Did you know you can try the features in Microsoft 365 Defender for Office 365 Plan 2 for free? Use the 90-day Defender for Office 365 trial at the Microsoft 365 Defender portal trials hub. Learn about who can sign up and trial terms here.

Applies to

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 Microsoft 365 Defender portal 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 Microsoft 365 Defender portal to create anti-malware policies

Creating a custom anti-malware policy in the Microsoft 365 Defender portal creates the malware filter rule and the associated malware filter policy at the same time using the same name for both.

  1. In the Microsoft 365 Defender portal at https://security.microsoft.com, go to Email & Collaboration > Policies & Rules > Threat policies > Anti-Malware in the Policies section. To go directly to the Anti-malware page, use https://security.microsoft.com/antimalwarev2.

  2. On the Anti-malware page, click Create icon. Create.

  3. The policy wizard opens. On the Name your policy page, configure these settings:

    • Name: Enter a unique, descriptive name for the policy.
    • Description: Enter an optional description for the policy.

    When you're finished, click Next.

  4. On the Users and domains page, identify the internal recipients that the policy applies to (recipient conditions):

    • Users: The specified mailboxes, mail users, or mail contacts.
    • Groups:
      • Members of the specified distribution groups or mail-enabled security groups (dynamic distribution groups are not supported).
      • The specified Microsoft 365 Groups.
    • Domains: All recipients in the specified accepted domains in your organization.

    Click in the appropriate box, start typing a value, and select the value that you want from the results. Repeat this process as many times as necessary. To remove an existing value, click remove Remove icon. next to the value.

    For users or groups, you can use most identifiers (name, display name, alias, email address, account name, etc.), but the corresponding display name is shown in the results. For users, enter an asterisk (*) by itself to see all available values.

    Multiple values in the same condition use OR logic (for example, <recipient1> or <recipient2>). Different conditions use AND logic (for example, <recipient1> and <member of group 1>).

    • Exclude these users, groups, and domains: To add exceptions for the internal recipients that the policy applies to (recipient exceptions), select this option and configure the exceptions. The settings and behavior are exactly like the conditions.

    Important

    Multiple different types of conditions or exceptions are not additive; they're inclusive. The policy is applied only to those recipients that match all of the specified recipient filters. For example, you configure a recipient filter condition in the policy with the following values:

    • Users: romain@contoso.com
    • Groups: Executives

    The policy is applied to romain@contoso.com only if he's also a member of the Executives group. If he's not a member of the group, then the policy is not applied to him.

    Likewise, if you use the same recipient filter as an exception to the policy, the policy is not applied to romain@contoso.com only if he's also a member of the Executives group. If he's not a member of the group, then the policy still applies to him.

    When you're finished, click Next.

  5. On the Protection settings page, configure the following settings:

    • Enable the common attachments filter: If you select this option, messages with the specified attachments are treated as malware and are automatically quarantined. You can modify the list by clicking Customize file types and selecting or deselecting values in the list.

      For the default and available values, see Anti-malware policies.

      When these types are found: Select one of the following values:

      • Reject the message with a non-delivery report (NDR) (this is the default value)
      • Quarantine the message
    • Enable zero-hour auto purge for malware: If you select this option, ZAP quarantines malware messages that have already been delivered. For more information, see Zero-hour auto purge (ZAP) in Exchange Online.

    • Quarantine policy: Select the quarantine policy that applies to messages that are quarantined as malware. Quarantine policies define what users are able to do to quarantined messages, and whether users receive quarantine notifications. For more information, see Quarantine policies.

      A blank value means the default quarantine policy is used (AdminOnlyAccessPolicy for malware detections). When you later edit the anti-malware policy or view the settings, the actual quarantine policy name is shown. For more information about default quarantine policies that are used for anti-malware, see EOP anti-malware policy settings.

      Note

      The quarantine policy also determines whether recipients receive email notifications for messages that were quarantined as malware. Quarantine notifications are disabled in AdminOnlyAccessPolicy, so if you want to notify recipients that have messages quarantined as malware, create or use an existing quarantine policy where notifications are turned on.

      Regardless of the settings in the quarantine policy, users can't release their own messages that were quarantined as malware. At best, admins can configure the quarantine policy so users can request the release of their quarantined malware messages.

    • Admin notifications: Select none, one, or both of the following options:

      • Notify an admin about undelivered messages from internal senders: If you select this option, enter a recipient email address in the Admin email address box that appears.

      • Notify an admin about undelivered messages from external senders: If you select this option, enter a recipient email address in the Admin email address box that appears.

      Note

      Admin notifications are sent only for attachments that are classified as malware.

    • Customize notifications: Use the settings in this section to customize the message properties that are used for admin notifications.

      • Use customized notification text: If you select this option, use the From name and From address boxes to specify the sender's name and email address for admin notification messages.

      • Customize notifications for messages from internal senders: If you previously selected Notify an admin about undelivered messages from internal senders, use the Subject and Message boxes to specify the subject and message body of admin notification messages.

      • Customize notifications for messages from external senders: If you previously selected Notify an admin about undelivered messages from external senders, you need to use the Subject and Message boxes to specify the subject and message body of admin notification messages.

    When you're finished, click Next.

  6. On the Review page, review your settings. You can select Edit in each section to modify the settings within the section. Or you can click Back or select the specific page in the wizard.

    When you're finished, click Submit.

  7. On the confirmation page that appears, click Done.

Use the Microsoft 365 Defender portal to view anti-malware policies

  1. In the Microsoft 365 Defender portal at https://security.microsoft.com, go to Email & Collaboration > Policies & Rules > Threat policies > Anti-Malware in the Policies section. To go directly to the Anti-malware page, use https://security.microsoft.com/antimalwarev2.

  2. On the Anti-malware page, the following properties are displayed in the list of anti-malware policies:

    • Name
    • Status
    • Priority
  3. When you select a policy by clicking on the name, the policy settings are displayed in a flyout.

Use the Microsoft 365 Defender portal to modify anti-malware policies

  1. In the Microsoft 365 Defender portal at https://security.microsoft.com, go to Email & Collaboration > Policies & Rules > Threat policies > Anti-Malware in the Policies section. To go directly to the Anti-malware page, use https://security.microsoft.com/antimalwarev2.

  2. On the Anti-malware page, select a policy from the list by clicking on the name.

  3. In the policy details flyout that appears, select Edit in each section to modify the settings within the section. For more information about the settings, see the previous Use the Microsoft 365 Defender portal to create anti-malware policies section in this article.

    For the default anti-malware policy, the Users, groups, and domains section isn't available (the policy applies to everyone), and you can't rename the policy.

To enable or disable a policy or set the policy priority order, see the following sections.

Enable or disable custom anti-malware policies

You can't disable the default anti-malware policy.

  1. In the Microsoft 365 Defender portal at https://security.microsoft.com, go to Email & Collaboration > Policies & Rules > Threat policies > Anti-Malware in the Policies section. To go directly to the Anti-malware page, use https://security.microsoft.com/antimalwarev2.

  2. On the Anti-malware page, select a custom policy from the list by clicking on the name.

  3. At the top of the policy details flyout that appears, you'll see one of the following values:

    • Policy off: To turn on the policy, click Turn on icon. Turn on .
    • Policy on: To turn off the policy, click Turn off icon. Turn off.
  4. In the confirmation dialog that appears, click Turn on or Turn off.

  5. Click Close in the policy details flyout.

Back on the main policy page, the Status value of the policy will be On or Off.

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 policies are lower priority than older policies). A lower priority number indicates a higher priority for the policy (0 is the highest), 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.

To change the priority of a policy, you click Increase priority or Decrease priority in the properties of the policy (you can't directly modify the Priority number in the Microsoft 365 Defender portal). Changing the priority of a policy only makes sense if you have multiple policies.

Notes:

  • In the Microsoft 365 Defender portal, 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).
  • 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 has the priority value Lowest, and you can't change it.
  1. In the Microsoft 365 Defender portal at https://security.microsoft.com, go to Email & Collaboration > Policies & Rules > Threat policies > Anti-Malware in the Policies section. To go directly to the Anti-malware page, use https://security.microsoft.com/antimalwarev2.

  2. On the Anti-malware page, select a custom policy from the list by clicking on the name.

  3. At the top of the policy details flyout that appears, you'll see Increase priority or Decrease priority based on the current priority value and the number of custom policies:

    • The policy with the Priority value 0 has only the Decrease priority option available.
    • The policy with the lowest Priority value (for example, 3) has only the Increase priority option available.
    • If you have three or more policies, the policies between the highest and lowest priority values have both the Increase priority and Decrease priority options available.

    Click Increase priority icon. Increase priority or Decrease priority icon Decrease priority to change the Priority value.

  4. When you're finished, click Close in the policy details flyout.

Use the Microsoft 365 Defender portal to remove custom anti-malware policies

When you use the Microsoft 365 Defender portal to remove a custom anti-malware policy, the malware filter rule and the corresponding malware filter policy are both deleted. You can't remove the default anti-malware policy.

  1. In the Microsoft 365 Defender portal at https://security.microsoft.com, go to Email & Collaboration > Policies & Rules > Threat policies > Anti-Malware in the Policies section. To go directly to the Anti-malware page, use https://security.microsoft.com/antimalwarev2.

  2. On the Anti-malware page, select a custom policy from the list by clicking on the name.

  3. At the top of the policy details flyout that appears, click More actions icon. More actions > Delete policy icon Delete policy.

  4. In the confirmation dialog that appears, click Yes.

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

For more information about anti-spam policies in PowerShell, see Anti-malware policies in the Microsoft 365 Defender portal vs PowerShell.

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 Microsoft 365 Defender portal 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 Microsoft 365 Defender portal until you assign the policy to a malware filter rule.

Step 1: Use PowerShell to create a malware filter policy

To create a malware filter policy, use this syntax:

New-MalwareFilterPolicy -Name "<PolicyName>" [-AdminDisplayName "<OptionalComments>"] [-EnableFileFilter <$true | $false>] [-FileTypeAction <Reject | Quarantine>] [-FileTypes FileType1,FileType2,...FileTypeN] [-CustomNotifications <$true | $false>] [<Inbound notification options>] [<Outbound notification options>]  [-QuarantineTag <QuarantineTagName>]

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

  • Notify admin@contoso.com when malware is detected in a message from an internal sender.
  • The common attachments filter is enabled (-EnableFileFilter $true) and the default list of file types is used (we aren't using the FileTypes parameter).
  • Messages detected by the common attachments filter are rejected with an NDR (we aren't using the FileTypeAction parameter, and the default value is Reject).
  • The default quarantine policy for malware detections is used (we aren't using the QuarantineTag parameter).
New-MalwareFilterPolicy -Name "Contoso Malware Filter Policy" -EnableFileFilter $true -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 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-MalwareFilterRule -State Disabled
Get-MalwareFilterRule -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 article.

  • 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 Microsoft 365 Defender portal, 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.

Note

For detailed instructions to specify the quarantine policy to use in a malware filter policy, see Use PowerShell to specify the quarantine policy in anti-malware policies.

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 article.

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 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, and using an email service that doesn't automatically block outbound spam. 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 admin notification results based on your anti-malware policy settings. For example, 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).