Detection rules › YARA-L

O365 Entra ID App Modify Permission Change On Watchlist

Severity
medium
Type
alert
Time window
5m
Match by
app_name
Author
Google Cloud Security
Source
github.com/chronicle/detection-rules

Alerts when a permission on the watchlist is applied to an Entra ID application.

References

Telemetry coverage

PlatformRecord / event type
Microsoft 365Update application.

Rules detecting the same action

These rules filter on the same operation.

Rule body

// Copyright 2023 Google LLC. Licensed under Apache-2.0.

rule o365_entra_id_app_modify_permission_change_on_watchlist {

  meta:
    author = "Google Cloud Security"
    description = "Alerts when a permission on the watchlist is applied to an Entra ID application."
    rule_id = "mr_678cafb8-ea1f-42ac-a396-238bc35e4d21"
    rule_name = "O365 Entra ID App Modify Permission Change On Watchlist"
    reference = "https://learn.microsoft.com/en-us/graph/permissions-reference"
    assumption = "The list msgraph_watchlist_permissions is populated as needed with guid permissions Example: 024d486e-b451-40bb-833d-3e66d98c5c73 //Mail.Read.Write"
    type = "alert"
    platform = "azure"
    data_source = "o365"
    severity = "Medium"
    priority = "Medium"

  events:
    $app.metadata.event_type = "USER_RESOURCE_UPDATE_CONTENT"
    $app.metadata.product_name = "Office 365"
    $app.metadata.product_event_type = "Update application."
    $app.metadata.vendor_name = "Microsoft"
    $app.security_result.action = "ALLOW"
    (
        $app.target.resource.attribute.labels.key = /NewValue_EntitlementId-/ or
        $app.target.resource.attribute.labels.key = /OldValue_EntitlementId-/
    )
    $app.security_result.detection_fields["target_1"] = $app_name

  match:
    $app_name over 5m

  outcome:
    $risk_score = 65
    $event_count = count_distinct($app.metadata.id)
    $security_summary = array_distinct($app.security_result.summary)
    $user_agent = array_distinct($app.network.http.user_agent)
    //The reference list msgraph_watchlist_permissions matches on the GUID. List contents example row:  6aedf524-7e1c-45a7-bd76-ded8cab8d0fc //SecurityEvents.ReadWrite.All
    $watchlist_permissions_after_modification = array_distinct(if($app.target.resource.attribute.labels.key = /NewValue_EntitlementId/ and $app.target.resource.attribute.labels.value IN %msgraph_watchlist_permissions, $app.target.resource.attribute.labels.value,""))
    $watchlist_permissions_before_modification = array_distinct(if($app.target.resource.attribute.labels.key = /OldValue_EntitlementId/ and $app.target.resource.attribute.labels.value IN %msgraph_watchlist_permissions, $app.target.resource.attribute.labels.value,""))
    $permissions_after_modification = array_distinct(if($app.target.resource.attribute.labels.key = /NewValue_EntitlementId/ and $app.target.resource.attribute.labels.value !="", $app.target.resource.attribute.labels.value,""))
    $permissions_before_modification = array_distinct(if($app.target.resource.attribute.labels.key = /OldValue_EntitlementId/ and $app.target.resource.attribute.labels.value !="", $app.target.resource.attribute.labels.value,""))
    $total_permissions_after_modification = count_distinct(if($app.target.resource.attribute.labels.key = /NewValue_EntitlementId/ and $app.target.resource.attribute.labels.value !="", $app.target.resource.attribute.labels.value, "")) - 1
    $total_permissions_before_modification = count_distinct(if($app.target.resource.attribute.labels.key = /OldValue_EntitlementId/ and $app.target.resource.attribute.labels.value !="", $app.target.resource.attribute.labels.value, "")) - 1
    //added to populate alert graph with additional context
    $principal_user_userid = array_distinct($app.principal.user.userid)

  condition:
    $app
}

YARA-L rule structure

Condition

Fires when at least one $app event in the 5m window.

Events

$app USER_RESOURCE_UPDATE_CONTENT

  • metadata.product_event_type = "Update application."
  • security_result.action = "ALLOW"
  • target.resource.attribute.labels.key matches "NewValue_EntitlementId-"
  • target.resource.attribute.labels.key matches "OldValue_EntitlementId-"

Match and correlation

Match key
$app_name (security_result.detection_fields["target_1"])
Within
5m

Outcome

Outcome variables add context to a detection. When the rule generates an alert, $risk_score is displayed with it.

FieldExpression
risk_score65
event_countcount_distinct($app.metadata.id)
security_summaryarray_distinct($app.security_result.summary)
user_agentarray_distinct($app.network.http.user_agent)
watchlist_permissions_after_modificationarray_distinct(if($app.target.resource.attribute.labels.key = /NewValue_EntitlementId/ and $app.target.resource.attribute.labels.value IN %msgraph_watchlist_permissions, $app.target.resource.attribute.labels.value,""))
watchlist_permissions_before_modificationarray_distinct(if($app.target.resource.attribute.labels.key = /OldValue_EntitlementId/ and $app.target.resource.attribute.labels.value IN %msgraph_watchlist_permissions, $app.target.resource.attribute.labels.value,""))
permissions_after_modificationarray_distinct(if($app.target.resource.attribute.labels.key = /NewValue_EntitlementId/ and $app.target.resource.attribute.labels.value !="", $app.target.resource.attribute.labels.value,""))
permissions_before_modificationarray_distinct(if($app.target.resource.attribute.labels.key = /OldValue_EntitlementId/ and $app.target.resource.attribute.labels.value !="", $app.target.resource.attribute.labels.value,""))
total_permissions_after_modificationcount_distinct(if($app.target.resource.attribute.labels.key = /NewValue_EntitlementId/ and $app.target.resource.attribute.labels.value !="", $app.target.resource.attribute.labels.value, "")) - 1
total_permissions_before_modificationcount_distinct(if($app.target.resource.attribute.labels.key = /OldValue_EntitlementId/ and $app.target.resource.attribute.labels.value !="", $app.target.resource.attribute.labels.value, "")) - 1
principal_user_useridarray_distinct($app.principal.user.userid)