Detection rules › YARA-L

O365 AD PowerShell App Login Subsequent Activity

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

Once a user authenticates to the Azure AD PowerShell application, if they take multiple admin actions indicative of establishing their own persistence with an Entra ID application within a portion of the access token time, alert for additional investigation

MITRE ATT&CK coverage

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 2023 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_ADPowerShell_app_login_subsequent_activity {

  meta:
    author = "Google Cloud Security"
    description = "Once a user authenticates to the Azure AD PowerShell application, if they take multiple admin actions indicative of establishing their own persistence with an Entra ID application within a portion of the access token time, alert for additional investigation"
    rule_id = "mr_2d781f34-05f3-43aa-b5ec-257c03787a66"
    rule_name = "O365 AD PowerShell App Login Subsequent Activity"
    assumption = "This does not take into account attempts that were blocked, just any logging of attempts for any of these actions"
    tactic = "TA0003"
    technique = "T1098.001"
    type = "alert"
    platform = "azure"
    data_source = "o365"
    severity = "Medium"
    priority = "Medium"

  events:
    (
        $login.metadata.event_type = "USER_LOGIN" and
        $login.metadata.product_event_type = "UserLoggedIn" and
        $login.metadata.product_name = "Office 365" and
        $login.metadata.vendor_name = "Microsoft" and
        $login.target.resource.product_object_id = "1b730954-1685-4b74-9bfd-dac224a7b894" and
        $login.security_result.action = "ALLOW"
    )
    $login.target.user.userid = $userid
    $login.metadata.event_timestamp.seconds < $other.metadata.event_timestamp.seconds
    (
        (
            $other.metadata.event_type = "USER_RESOURCE_CREATION" and
            $other.metadata.product_event_type = "Add application." and
            $other.metadata.product_name = "Office 365" and
            $other.metadata.vendor_name = "Microsoft"
        )
        or
        (
            $other.metadata.event_type = "USER_RESOURCE_UPDATE_CONTENT" and
            $other.metadata.product_event_type = "Update application." and
            $other.metadata.product_name = "Office 365" and
            $other.metadata.vendor_name = "Microsoft"
        )
        or
        (
            $other.metadata.event_type = "USER_RESOURCE_UPDATE_PERMISSIONS" and
            $other.metadata.product_event_type = "Add delegated permission grant." and
            $other.metadata.product_name = "Office 365" and
            $other.metadata.vendor_name = "Microsoft"
        )
        or
        (
            $other.metadata.event_type = "USER_RESOURCE_UPDATE_CONTENT" and
            $other.metadata.product_event_type = /Update application.*Certificates and secrets management/ nocase and
            $other.metadata.product_name = "Office 365" and
            $other.metadata.vendor_name = "Microsoft"
        )
    )
    $other.principal.user.userid = $userid
    $other.metadata.product_event_type = $other_event

  match:
    $userid over 90m

  outcome:
    $risk_score = max(if($other.metadata.product_event_type = "Add application.", 10, 0) +
                        if($other.metadata.product_event_type = "Update application.", 10, 0) +
                        if($other.metadata.product_event_type = "Add delegated permission grant.", 10, 0) +
                        if($other.metadata.product_event_type = /Update application.*Certificates and secrets management/ nocase, 55, 0))
    $subsequent_action_threshold = 1
    $product_event_type = array_distinct($other.metadata.product_event_type)
    $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)
    //$principal_user_userid = array_distinct($other.principal.user.userid)
    $target_resource_name = array_distinct($other.target.resource.name)

  condition:
    $login and #other_event > 0
}

Detection logic

Fires when at least one $login event in the 90m window and $other_event occurs more than 0 times in the 90m window.

Events

$login USER_LOGIN

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

$other USER_RESOURCE_CREATION

  • metadata.product_event_type = "Add application."
  • metadata.product_event_type = "Update application."
  • metadata.product_event_type = "Add delegated permission grant."
  • metadata.product_event_type matches "Update application.*Certificates and secrets management"

Correlation

Order
$login before $other
Match key
$userid (target.user.userid)
Within
90m

Outcome

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

FieldExpression
risk_scoremax(if($other.metadata.product_event_type = "Add application.", 10, 0) + if($other.metadata.product_event_type = "Update application.", 10, 0) + if($other.metadata.product_event_type = "Add delegated permission grant.", 10, 0) + if($other.metadata.product_event_type = /Update application.*Certificates and secrets management/ nocase, 55, 0))
subsequent_action_threshold1
product_event_typearray_distinct($other.metadata.product_event_type)
country_region_login_attemptarray_distinct($login.principal.ip_geo_artifact.location.country_or_region)
principal_iparray_distinct($login.principal.ip)
target_resource_namearray_distinct($other.target.resource.name)