Detection rules › YARA-L

O365 Persistent Login Activity To Azure AD PowerShell App

Severity
medium
Type
alert
Time window
1d
Match by
userid
Author
Google Cloud Security
Source
github.com/chronicle/detection-rules

Continual logins to Azure AD PowerShell app are not a security best practice, if this is observed, additional investigation is needed

MITRE ATT&CK coverage

TacticTechniques
Lateral MovementT1021.007 Remote Services: Cloud Services

Event coverage

Rules detecting the same action

Other rules on this platform that filter on the same API call or operation.

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 o365_persistent_login_activity_to_azure_ADPowerShell_app {

  meta:
    author = "Google Cloud Security"
    description = "Continual logins to Azure AD PowerShell app are not a security best practice, if this is observed, additional investigation is needed"
    rule_id = "mr_4e61ae7f-d9fc-4c2a-b086-69d9d50dc5cc"
    rule_name = "O365 Persistent Login Activity To Azure AD PowerShell App"
    tactic = "TA0008"
    technique = "T1021.007"
    type = "alert"
    platform = "azure"
    data_source = "o365"
    severity = "Medium"
    priority = "Medium"

  events:
    $login.metadata.event_type = "USER_LOGIN"
    $login.metadata.product_event_type = "UserLoggedIn"
    $login.metadata.product_name = "Office 365"
    $login.metadata.vendor_name = "Microsoft"
    $login.target.resource.product_object_id = "1b730954-1685-4b74-9bfd-dac224a7b894"
    $login.security_result.action = "ALLOW"
    $login.target.user.userid = $userid
    $login.metadata.event_timestamp.seconds = $time

  match:
    $userid over 24h

  outcome:
    $risk_score = 65
    $event_count = count_distinct($login.metadata.id)
    $entra_id_login_threshold = 2
    $security_summary = array_distinct($login.security_result.summary)
    $user_agent = array_distinct($login.network.http.user_agent)
    $country_region_login_attempt = array_distinct($login.principal.ip_geo_artifact.location.country_or_region)
    //added to populate alert graph with additional context
    $principal_ip = array_distinct($login.principal.ip)
    $target_user_userid = array_distinct($login.target.user.userid)

  condition:
    // Can set based on your own threshold
    #time > 1
}

Detection logic

Fires when $time occurs more than 1 times in the 24h window.

Events

$login USER_LOGIN

  • metadata.product_event_type = "UserLoggedIn"
  • target.resource.product_object_id = "1b730954-1685-4b74-9bfd-dac224a7b894"
  • security_result.action = "ALLOW"

Correlation

Match key
$userid (target.user.userid)
Within
1d

Outcome

Fields the detection emits on a match. $risk_score drives alerting; Chronicle surfaces the rest on the detection.

FieldExpression
risk_score65
event_countcount_distinct($login.metadata.id)
entra_id_login_threshold2
security_summaryarray_distinct($login.security_result.summary)
user_agentarray_distinct($login.network.http.user_agent)
country_region_login_attemptarray_distinct($login.principal.ip_geo_artifact.location.country_or_region)
principal_iparray_distinct($login.principal.ip)
target_user_useridarray_distinct($login.target.user.userid)