Detection rules › YARA-L
Entra ID Add User Outside PIM
Adding users to roles is expected but if it occurs outside of PIM, validation should occur
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Persistence | T1098.003 Account Manipulation: Additional Cloud Roles |
Event coverage
Rule body yaral
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
rule entra_id_add_user_outside_pim {
meta:
author = "Google Cloud Security"
description = "Adding users to roles is expected but if it occurs outside of PIM, validation should occur"
rule_id = "mr_bc0a22e2-7ab1-4368-9408-3e6a5b666bec"
rule_name = "Entra ID Add User Outside PIM"
tactic = "TA0003"
technique = "T1098.003"
assumption = "The list entra_id_watchlist_roles or entra_id_watchlist_roles_guid is populated with role names, ie Exchange Administrator or 29232cdf-9323-42fd-ade2-1d097af3e4de, respectively"
type = "alert"
platform = "azure"
data_source = "azure ad"
severity = "Medium"
priority = "Medium"
events:
$app.metadata.event_type = "USER_UNCATEGORIZED"
$app.metadata.product_name = "Azure AD Directory Audit"
$app.metadata.vendor_name = "Microsoft"
$app.security_result.action = "ALLOW"
$app.metadata.product_event_type = "Add member to role outside of PIM (permanent)" //triggered via PS API call
//Can add watchlist of specific roles by name using the following commented out line
//$app.target.resource.name in %entra_id_watchlist_roles
//Can add watchlist of specific roles by guid using the following commented out line
//$app.target.resource.attribute.labels["TemplateId"] in %entra_id_watchlist_roles_guid
$app.principal.user.userid = $user
match:
$user over 5m
outcome:
$risk_score = 65
$event_count = count_distinct($app.metadata.id)
$assigned_role = array_distinct($app.target.resource.name)
$assigned_role_guid = array_distinct($app.target.resource.attribute.labels["TemplateId"])
$network_session = array_distinct($app.network.session_id)
$userid_making_modification = array_distinct($app.principal.user.userid)
$principal_user_email_addresses = array_distinct($app.principal.user.email_addresses)
$modified_userid = array_distinct($app.target.user.email_addresses)
condition:
$app
}
Detection logic
Fires when at least one $app event in the 5m window.
Events
$app
security_result.action = "ALLOW"metadata.product_event_type = "Add member to role outside of PIM (permanent)"
Correlation
Outcome
Fields the detection emits on a match. $risk_score drives alerting; Chronicle surfaces the rest on the detection.
| Field | Expression |
|---|---|
risk_score | 65 |
event_count | count_distinct($app.metadata.id) |
assigned_role | array_distinct($app.target.resource.name) |
assigned_role_guid | array_distinct($app.target.resource.attribute.labels["TemplateId"]) |
network_session | array_distinct($app.network.session_id) |
userid_making_modification | array_distinct($app.principal.user.userid) |
principal_user_email_addresses | array_distinct($app.principal.user.email_addresses) |
modified_userid | array_distinct($app.target.user.email_addresses) |