Microsoft Defender XDR
Hunting and detection

Custom Detection Rules

In brief

The wizard documentation now presents updated configuration steps, including a preview Incident settings step. Entity mapping supports repeated entity types and up to four identifier-and-column pairs per entity; newly supported identifiers are in preview.

What Defender admins need to know

Administrators can create more detailed entity mappings when configuring rules. Review mappings carefully because identified entities affect incident correlation.

Summaries are generated from the documentation change itself.

Documentation change

The comparison below shows only the changed extract. Use the full-page view for complete context.

  • From Advanced hunting — Go to Advanced hunting, prepare and run your query, then select Create detection rule. This approach lets you validate your query results before creating the rule.
  • From the custom detections list — Go to Custom detection rules and select + Create detection rule. This approach opens the rule wizard directly, where you can write or paste a query and configure all rule settings in one place.

Regardless of which entry point you use, follow these steps toprepare the query, then configure the rule:wizard steps in this order:

  1. Prepare the queryGeneral
  2. Create new rule and provide alert detailsAlert settings
  3. Define alert enrichment detailsIncident settings (preview)
  4. SpecifyAutomated actions
  5. Set the rule scopeScope
  6. Review and turn on the rulecreate

1. Prepare the query

    - `SenderMailFromAddress` (sender address displayed by email client)
    - `SenderObjectId`
    - `RecipientObjectId`
- Account:User:
    - `AccountObjectId`
    - `AccountSid`
    - `AccountUpn`

2. Create new rule and provide alert details

In the query editor, select Create detection rule. In the wizard, configure General and specifyAlert settings with the following rule and alert details:

  • Detection name - Name of the detection rule; make it unique.
  • Frequency - Interval for running the query and taking action. For more information, see Rule frequency.

3. Define alert enrichment details

YouIn Alert settings, you can enrich alerts by providing and defining more details. When you enrich alerts, you can:

  • Create a dynamic alert title and description
  • Add custom details to display in the alert side panel

Link entities

Note

Mapping up to four identifiers per entity, adding the same entity type more than once, and the newly supported identifiers are in preview.

Identify the columns in your query results where you expect to find the main affected or impacted entity. For example, a query might return sender (SenderFromAddress or SenderMailFromAddress) and recipient (RecipientEmailAddress) addresses. Identifying which of these columns represent the main impacted entity helps the service aggregate relevant alerts, correlate incidents, and target response actions.

You can select only one column for eachadd the same entity type (mailbox, user,more than once and map up to four identifier and column pairs to each entity. For example, map one Device entity to DeviceName and another Device entity to RemoteDeviceName, or device)map several IP entities to IPAddress, LocalIP, and RemoteIP. You can't select columns that aren't returned by your query.

Expanded entity mapping

Note

Mapping up to four identifiers per entity, adding the same entity type more than once, and the newly supported identifiers are in preview.

You can link a wide range of entity types to your alerts. Linking more entities helps the correlation engine group alerts to the same incidents and to correlate incidents together. If you're a Microsoft Sentinel customer, this also means that you can map any entity from your third-party data sources that are ingested into Microsoft Sentinel.

For Microsoft Defender XDR data, the entities are automatically selected. If the data is from Microsoft Sentinel, you need to select the entities manually.

Note

Entities impactIdentified entities determine how alerts are grouped into incidents. Make sure to carefully review the entities to ensure a high quality of incidents.incident correlation. For more information, see Alert correlation and incident merging in the Microsoft Defender portal.

The expandedIn the Alert settings step, the Entity mapping section follows Alert details and Custom details. It has two sections where you can select entities:parts:

  • Impacted Assets - Select Add assets– Addto add impacted assets that appear in the selected events. You can add the following types of assets:
    • AccountUser
    • Device
    • Mailbox
    • Cloud applicationApplication
    • Azure resource
    • Amazon Web Services resource
    • Google Cloud Platform resource
  • Related evidenceEvidence– - Select Add entitiesto add nonassets that appear in the selected events. The supported entity types are:
    • Process
    • File
    • Registry value
    • IP
    • OAuth applicationApplication
    • DNS
    • Security group
    • URL

You can currently map only assets as impacted entities.

Screenshot that shows the entity mapping options in the Custom detections wizard.Screenshot of Impacted Assets with one Device entity mapped to three identifiers and query result columns.

After youScreenshot of Related Evidence with a Process entity mapping and the Add identifier and Add entities controls.

For each entity, use the following steps in either Impacted Assets or Related Evidence:

  1. Choose the entity type under Entity.
  2. Choose an Identifier and the query result Column that contains it. Both fields are required.
  3. To map more identifiers to the same entity, select anAdd identifier. Each entity type, selectsupports up to four identifier and column pairs.
  4. To remove an identifier type that exists inrow or a whole entity, select the selected query results so you can use itdelete (trash) icon next to identify this entity. it.

For example, map a Registry value entity by Key to RegistryKey and by ValueName to RegistryValueName.

Each entity type has a list of supported identifiers, as shownidentifiers in the relevant dropdown menu.Identifier dropdown. To better understand eachan identifier, read theits description displayed when you hover over it.

Newly supported identifiers (preview)

The following identifiers are available in preview for existing entity types:

EntityNewly supported identifiers
UserObjectGuid, AadTenantId, PUID, IsDomainJoined, DisplayName
DeviceAzureID, OMSAgentID, OSFamily, OSVersion, IsDomainJoined
Cloud ApplicationInstanceName, SaasId
FileDirectory
ProcessElevationToken, CreationTimeUtc
Registry valueValue, ValueType
MailboxDisplayName, Upn, ExternalDirectoryObjectId, RiskLevel
Mail ClusterNetworkMessageIds, CountByDeliveryStatus, CountByThreatType, CountByProtectionStatus, MailCount, QueryTime, IsVolumeAnomaly, ClusterSourceIdentifier, ClusterSourceType, ClusterQueryStartTime, ClusterQueryEndTime, ClusterGroup
Mail MessageP1Sender, P1SenderDisplayName, P1SenderDomain, P2SenderDisplayName, P2SenderDomain, InternetMessageId, Threats, ReceivedDate, BodyFingerprintBin1, BodyFingerprintBin2, BodyFingerprintBin3, BodyFingerprintBin4, BodyFingerprintBin5, AntispamDirection, DeliveryAction, DeliveryLocation, Language, ThreatDetectionMethods

The supported identifiers for IP, URL, Azure resource, and Security Group are unchanged; these entity types already support the same identifiers in custom detection rules and Microsoft Sentinel analytics rules.

After selecting the identifier, select a column from the query results that contains the selected identifier. Select Explore query and results to open the advanced hunting context panel. This option allows you to explore your query and results to make sure you choose the right column for the selected identifier.

4. Incident settings (preview)

Note

Alert grouping for custom detection rules is in preview.

In Incident settings, use Alert grouping to combine related alerts from the same custom detection rule into a single incident instead of creating one incident per alert. As with alert grouping in Microsoft Sentinel analytics rules, this gives analysts one place to investigate recurring or related activity.

Alert grouping (preview)

Configure alert grouping in the custom detection rule wizard:

  1. In Incident settings, expand Alert grouping.
  2. Turn on Group related alerts, triggered by this custom detection rule, into incidents. The default is Disabled. The remaining alert grouping settings are unavailable until you turn it on.
  3. Under Limit the group to alerts created within the selected time frame, enter a number and choose a unit. This setting is required and defaults to 5 Hours. Only alerts created within this time frame are grouped together.
  4. Under Group alerts triggered by this custom detection rule into a single incident by, choose one option:
    • Grouping alerts into a single incident if all the entities match (recommended). This option is selected by default.
    • Grouping all alerts triggered by this rule into a single incident.
    • Grouping alerts into a single incident if the selected entity types and details match. Select the entities and details to match in the Select entities and Select details dropdowns, which become available when you choose this option.

Screenshot of the custom detection wizard with alert grouping enabled, a five-hour time frame, and all entities matching.

Alert grouping has the following behavior and limits:

  • Up to 150 alerts per incident. After an incident reaches this limit, a new incident is created with the same incident details, and additional alerts are grouped into it. This limit is separate from the 150-alert limit per rule run, which limits how many alerts a rule can generate each time it runs.
  • Closed incidents aren't reopened. Unlike Microsoft Sentinel analytics rules, custom detection rules don't have a Re-open closed matching incidents option. If a new alert matches a closed incident, a new incident is created.
  • Defender correlation still applies. Alert grouping doesn't prevent Defender from linking other alerts or merging existing incidents.

Note

Microsoft Defender correlation activities can link other alerts or merge existing incidents to the generated incident, regardless of the alert grouping settings defined in the custom detection rule.

5. Specify actions

IfIn Automated actions, if your custom detection rule uses Defender data, it can automatically take actions on devices, files, users, or emails that the query returns.

Screenshot that shows actions for custom detections in the Microsoft Defender portal.

The columns NetworkMessageId and RecipientEmailAddress must be present in the output results of the query to apply actions to email messages.

5.6. Set the rule scope

Set the scope toIn Scope, specify which devices the rule covers. The scope influences rules that check devices and doesn't affect rules that check only mailboxes and user accounts or identities.

When setting the scope, select:

Users can create or edit a custom detection rule only if they have the corresponding permissions for the devices included in the scope of the rule. For example, admins can only create or edit rules that are scoped to all device groups if they have permissions for all device groups.

6.7. Review and turn on the rule

After reviewingIn Review and create, review the rule, then select Create to save it. The custom detection rule runs immediately. It runs again based on the configured frequency to check for matches, generate alerts, and take response actions.

Important

How custom detections handle duplicate alerts

\ No newline at end of file An important consideration when creating and reviewing custom detection rules is alert noise and fatigue. Custom detections group and deduplicate events into a single alert. If a custom detection rule runs twice on an event that contains the same entities, custom details, and dynamic details, it creates one alert for both events. If the detection rule recognizes that the events are identical, it logs one of the events on the created alert and takes care of the duplicates. Duplicates can occur when the lookback period is longer than the frequency. If the events are different, the custom detection logs both events on the alert. \ No newline at end of file

This event-to-alert deduplication is separate from alert-to-incident grouping. \ No newline at end of file