Query Details

Defender XDR Alert Tuning Rule Changes

MDXDR Alert Tuning Rule Changes

Query

CloudAppEvents
| where ActionType in (
    "CreateSuppressionRule",
    "DeleteSuppressionRule",
    "DisableSuppressionRule",
    "EditSuppressionRule",
    "EnableSuppressionRule"
)
| extend RuleOperation = case(
    ActionType == "CreateSuppressionRule",  "Created",
    ActionType == "DeleteSuppressionRule",  "Deleted",
    ActionType == "DisableSuppressionRule", "Disabled",
    ActionType == "EditSuppressionRule",    "Modified",
    ActionType == "EnableSuppressionRule",  "Enabled",
    "Unknown"
)
| extend
    RuleId = tostring(RawEventData.SuppressionRuleId),
    RuleTitle = tostring(RawEventData.RuleTitle),
    RuleAction = tostring(RawEventData.Action),
    RuleIsEnabled = tobool(RawEventData.IsEnabled),
    IoaDefinitionId = tostring(RawEventData.IoaDefinitionId),
    RuleConditions = parse_json(tostring(RawEventData.RuleConditions)),
    ScopeConditions = parse_json(tostring(RawEventData.ScopeConditions)),
    UserId = tostring(RawEventData.UserId),
    UserKey = tostring(RawEventData.UserKey),
    UserType = toint(RawEventData.UserType),
    OrganizationId = tostring(RawEventData.OrganizationId),
    AuditEventId = tostring(RawEventData.Id),
    AuditOperation = tostring(RawEventData.Operation),
    AuditCreationTime = todatetime(RawEventData.CreationTime),
    ClientIP = tostring(RawEventData.ClientIP),
    RecordType = toint(RawEventData.RecordType),
    Workload = tostring(RawEventData.Workload)
| extend
    ConditionType = tostring(RuleConditions.conditionType),
    LogicalOperator = tostring(RuleConditions.logicalOperator)
| extend ConditionArray = case(
    ConditionType == "Simple", pack_array(RuleConditions),
    ConditionType == "Complex", RuleConditions.conditions,
    dynamic([])
)
| extend ConditionCount = coalesce(array_length(ConditionArray), 0)
| extend ConditionArray = iff(
    ConditionCount == 0,
    dynamic([null]),
    ConditionArray
)
| mv-apply Condition = ConditionArray on (
    extend
        EntityRole = tostring(Condition.entityRole),
        IocDisplayName = tostring(Condition.iocDisplayName),
        IocType = tostring(Condition.iocType),
        PredicateOperator = tostring(Condition.predicate.operator),
        PredicateValue = tostring(Condition.predicate.value),
        PredicateValueType = tostring(Condition.predicate.valueType),
        PredicateType = tostring(Condition.predicate.predicateType)
    | summarize
        EntityRoles = make_set_if(EntityRole, isnotempty(EntityRole)),
        IocDisplayNames = make_set_if(IocDisplayName, isnotempty(IocDisplayName)),
        IocTypes = make_set_if(IocType, isnotempty(IocType)),
        PredicateOperators = make_set_if(PredicateOperator, isnotempty(PredicateOperator)),
        PredicateValues = make_set_if(PredicateValue, isnotempty(PredicateValue)),
        PredicateValueTypes = make_set_if(PredicateValueType, isnotempty(PredicateValueType)),
        PredicateTypes = make_set_if(PredicateType, isnotempty(PredicateType)),
        ConditionDetails = make_list_if(
            bag_pack(
                "EntityRole", EntityRole,
                "IocDisplayName", IocDisplayName,
                "IocType", IocType,
                "Operator", PredicateOperator,
                "Value", PredicateValue,
                "ValueType", PredicateValueType,
                "PredicateType", PredicateType
            ),
            isnotempty(PredicateType)
        )
)
| project
    TimeGenerated,
    RuleOperation,
    RuleId,
    RuleTitle,
    RuleAction,
    RuleIsEnabled,
    IoaDefinitionId,
    ConditionType,
    ConditionCount,
    LogicalOperator,
    EntityRoles,
    IocDisplayNames,
    IocTypes,
    PredicateOperators,
    PredicateValues,
    PredicateValueTypes,
    PredicateTypes,
    ConditionDetails,
    RuleConditions,
    ScopeConditions,
    AccountDisplayName,
    AccountObjectId,
    AccountType,
    UserId,
    UserKey,
    UserType,
    IPAddress,
    ClientIP,
    IsAdminOperation,
    IsExternalUser,
    AuditEventId,
    AuditOperation,
    AuditCreationTime
| order by TimeGenerated desc
// Defender XDR Alert Tuning Rules

About this query

Explanation

This query is designed to audit changes to alert tuning rules in Microsoft Defender XDR. It helps identify and review modifications that might impact alert visibility. Here's a simplified breakdown of what the query does:

  1. Data Source: It uses the CloudAppEvents table from Microsoft Defender for Cloud Apps and Microsoft Defender XDR.

  2. Action Filtering: The query filters events where the action type involves creating, deleting, disabling, editing, or enabling suppression rules. These actions are related to how alerts are managed and tuned.

  3. Rule Operation Mapping: It maps each action type to a more understandable operation name, such as "Created" for CreateSuppressionRule.

  4. Data Extraction: The query extracts various details about each rule change, including:

    • Rule ID and title
    • Whether the rule is enabled
    • Conditions and scope of the rule
    • User and organization details involved in the change
    • IP address and client information
  5. Condition Analysis: It analyzes the conditions associated with each rule, breaking them down into components like entity roles, indicator types, and predicates (conditions that must be met for the rule to apply).

  6. Output: The query projects a set of fields that provide a comprehensive view of each rule change, including the time it was generated, the operation performed, and detailed condition information.

  7. Sorting: Results are ordered by the time the event was generated, with the most recent changes appearing first.

The purpose of this query is to help security teams monitor and review changes to alert rules, ensuring that unauthorized or inappropriate modifications do not suppress important alerts. It provides a detailed audit trail for rule changes, allowing for thorough investigation and context review.