entra_id_recently_created_user_assigned_entra_id_roles
Description
Detect users who are newly created and then immediately assigned administrator level roles
Query · yara_l
events:
(
$create.metadata.event_type = "USER_CREATION" and
$create.metadata.product_event_type = "Add user" and
$create.metadata.product_name = "Azure AD Directory Audit" and
$create.metadata.vendor_name = "Microsoft" and
$create.security_result.action = "ALLOW" and
$create.principal.user.userid = $principal_userid and
$create.target.user.userid = $target_userid
)
$create.metadata.event_timestamp.seconds < $role.metadata.event_timestamp.seconds
(
$role.metadata.event_type = "USER_CHANGE_PERMISSIONS" and
$role.metadata.product_event_type = "Add member to role" and
$role.metadata.product_name = "Azure AD Directory Audit" and
$role.metadata.vendor_name = "Microsoft" and
$role.security_result.action = "ALLOW" and
//To detect on specific roles, they can be added to a reference list and the following line uncommented
//$role.target.resource.attribute.labels["Role.Role.TemplateId"] in %msgraph_watchlist_roles_guid and
$role.principal.user.userid = $principal_userid and
re.replace($role.target.user.userid, `@.*$`, "") = $target_userid
)
match:
$principal_userid, $target_userid over 30m
outcome:
$risk_score = 85
$principal_county_region = array_distinct(strings.concat($create.principal.location.city," ",$create.principal.location.state," ",$create.principal.location.country_or_region))
$assigned_role = array_distinct($role.target.user.title)
$assigned_role_guid = array_distinct($role.target.resource.attribute.labels["Role.TemplateId"])
condition:
$create and $role