Detection rules › YARA-L

YARA-L rules: 01

AWS EC2 High Number Of API Calls

#
Severity
low
Type
Alert
Time window
5m
Match by
instanceId, ip
Author
Google Cloud Security
Source
github.com/chronicle/detection-rules

Detect when an EC2 instance makes high number of API calls.

MITRE ATT&CK Coverage

TacticTechniques
Discovery

Rule Body

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

rule aws_ec2_high_number_of_api_calls {

  meta:
    author = "Google Cloud Security"
    description = "Detect when an EC2 instance makes high number of API calls."
    rule_id = "mr_d19289e1-4385-4757-bf54-0f61e7a789a4"
    rule_name = "AWS EC2 High Number Of API Calls"
    mitre_attack_tactic = "Discovery"
    mitre_attack_technique = "Cloud Infrastructure Discovery"
    mitre_attack_url = "https://attack.mitre.org/techniques/T1580/"
    mitre_attack_version = "v13.1"
    type = "Alert"
    data_source = "AWS CloudTrail"
    platform = "AWS"
    severity = "Low"
    priority = "Low"

  events:
    $api.metadata.vendor_name = "AMAZON"
    $api.metadata.product_name = "AWS CloudTrail"
    $api.principal.resource.type = "AssumedRole"
    $api.principal.user.userid = /\/i-.*$/ //regex to be improved
    re.capture($api.principal.user.userid, ":assumed-role/.*/(.*)$") = $instanceId
    $api.principal.ip = $ip

  match:
    $ip, $instanceId over 5m

  outcome:
    $risk_score = max(35)
    $mitre_attack_tactic = "Discovery"
    $mitre_attack_technique = "Cloud Infrastructure Discovery"
    $mitre_attack_technique_id = "T1580"
    $event_count = count_distinct($api.metadata.id)
    $network_http_user_agent = array_distinct($api.network.http.user_agent)
    $principal_ip = array_distinct($api.principal.ip)
    $principal_ip_country = array_distinct($api.principal.ip_geo_artifact.location.country_or_region)
    $principal_ip_state = array_distinct($api.principal.ip_geo_artifact.location.state)
    $principal_user_display_name = array_distinct($api.principal.user.user_display_name)
    $dc_product_event_type = count_distinct($api.metadata.product_event_type)
    $aws_region = array_distinct($api.principal.location.name)
    $target_resource_name = array_distinct($api.target.resource.name)
    $target_resource_product_object_id = array_distinct($api.target.resource.product_object_id)

  condition:
    $api and $dc_product_event_type > 7
}

YARA-L Rule Structure

Condition

Fires when at least one $api event in the 5m window and $dc_product_event_type > 7.

Events

$api

  • principal.resource.type = "AssumedRole"
  • principal.user.userid matches "\/i-.*$"

Match and Correlation

Match key
$instanceId, $ip (principal.ip)
Within
5m

Outcome

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

FieldExpression
risk_scoremax(35)
event_countcount_distinct($api.metadata.id)
network_http_user_agentarray_distinct($api.network.http.user_agent)
principal_iparray_distinct($api.principal.ip)
principal_ip_countryarray_distinct($api.principal.ip_geo_artifact.location.country_or_region)
principal_ip_statearray_distinct($api.principal.ip_geo_artifact.location.state)
principal_user_display_namearray_distinct($api.principal.user.user_display_name)
dc_product_event_typecount_distinct($api.metadata.product_event_type)
aws_regionarray_distinct($api.principal.location.name)
target_resource_namearray_distinct($api.target.resource.name)
target_resource_product_object_idarray_distinct($api.target.resource.product_object_id)

Entra ID Application Restore

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

Entra ID application was restored. This implies a soft delete was performed at some point but less than 30 days ago.

Telemetry Coverage

PlatformRecord / event type
AzureRestore application

Rules Detecting the Same Action

These rules filter on the same operation.

Rule Body

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

rule entra_id_application_restore {

  meta:
    author = "Google Cloud Security"
    description = "Entra ID application was restored. This implies a soft delete was performed at some point but less than 30 days ago."
    rule_id = "mr_ed0a04f9-4ceb-499e-9e6f-01e4507b8da5"
    rule_name = "Entra ID Application Restore"
    type = "alert"
    platform = "azure"
    data_source = "azure ad audit"
    severity = "Medium"
    priority = "Medium"

  events:
    $app.metadata.event_type = "SERVICE_CREATION"
    $app.metadata.product_event_type = "Restore application"
    $app.metadata.product_name = "Azure AD Directory Audit"
    $app.metadata.vendor_name = "Microsoft"
    $app.security_result.action = "ALLOW"
    $app.principal.user.userid = $user

  match:
    $user over 5m

  outcome:
    $risk_score = 65
    $event_count = count_distinct($app.metadata.id)
    $principal_ip = array_distinct($app.principal.ip)
    $principal_email = array_distinct($app.principal.user.email_addresses)
    $principal_county_region = array_distinct($app.principal.ip_geo_artifact.location.country_or_region)
    $user_agent = array_distinct($app.network.http.user_agent)
    $network_session = array_distinct($app.network.session_id)
    $target_application = array_distinct($app.target.resource.name)
    $target_application_id = array_distinct($app.target.resource.product_object_id)

  condition:
    $app
}

YARA-L Rule Structure

Condition

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

Events

$app SERVICE_CREATION

  • metadata.product_event_type = "Restore application"
  • security_result.action = "ALLOW"

Match and Correlation

Match key
$user (principal.user.userid)
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)
principal_iparray_distinct($app.principal.ip)
principal_emailarray_distinct($app.principal.user.email_addresses)
principal_county_regionarray_distinct($app.principal.ip_geo_artifact.location.country_or_region)
user_agentarray_distinct($app.network.http.user_agent)
network_sessionarray_distinct($app.network.session_id)
target_applicationarray_distinct($app.target.resource.name)
target_application_idarray_distinct($app.target.resource.product_object_id)

MITRE ATT&CK T1021.002 Windows Admin Share With Asset Entity

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

Net use commands for SMB/Windows admin shares based on asset entity group

MITRE ATT&CK Coverage

Telemetry Coverage

Rule Body

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

rule mitre_attack_T1021_002_windows_admin_share_with_asset_entity {

  meta:
    author = "Google Cloud Security"
    description = "Net use commands for SMB/Windows admin shares based on asset entity group"
    rule_id = "mr_7b7fbe57-12a8-4254-ad73-b9e9024cbc8a"
    rule_name = "MITRE ATT&CK T1021.002 Windows Admin Share With Asset Entity"
    tactic = "TA0008"
    technique = "T1021.002"
    type = "alert"
    tags = "asset entity"
    platform = "Windows"
    assumption = "Assumes ingestion of Windows assets to entity graph"
    data_source = "microsoft sysmon, microsoft windows events"
    severity = "Low"
    priority = "Low"

  events:
    $process.metadata.event_type = "PROCESS_LAUNCH"
    $process.target.process.command_line = /net.*use.*(C|ADMIN|IPC)\$/ nocase
    $process.principal.ip = $ip

    // Correlate with asset entity data
    $asset.graph.entity.ip = $ip
    $asset.graph.metadata.entity_type = "ASSET"
    $asset.graph.metadata.source_type = "ENTITY_CONTEXT"
    $asset.graph.entity.asset.platform_software.platform = "WINDOWS"
    // Can be modified to focus rule on different groups or removed if not needed
    $asset.graph.relations.entity.group.group_display_name = "Domain Computers"

  match:
    $ip over 5m

  outcome:
    $risk_score = 35
    $event_count = count_distinct($process.metadata.id)
    // added to populate alert graph with additional context
    // Commented out principal.hostname because principal.ip is already represented in graph as match variable. If match changes, can uncomment to add to results
    //$principal_hostname = array_distinct($process.principal.hostname)
    $principal_process_pid = array_distinct($process.principal.process.pid)
    $principal_process_command_line = array_distinct($process.principal.process.command_line)
    $principal_process_file_sha256 = array_distinct($process.principal.process.file.sha256)
    $principal_process_file_full_path = array_distinct($process.principal.process.file.full_path)
    $principal_process_product_specific_process_id = array_distinct($process.principal.process.product_specific_process_id)
    $principal_process_parent_process_product_specific_process_id = array_distinct($process.principal.process.parent_process.product_specific_process_id)
    $target_process_pid = array_distinct($process.target.process.pid)
    $target_process_command_line = array_distinct($process.target.process.command_line)
    $target_process_file_sha256 = array_distinct($process.target.process.file.sha256)
    $target_process_file_full_path = array_distinct($process.target.process.file.full_path)
    $target_process_product_specific_process_id = array_distinct($process.target.process.product_specific_process_id)
    $principal_user_userid = array_distinct($process.principal.user.userid)

  condition:
    $process and $asset
}

YARA-L Rule Structure

Condition

Fires when at least one $process event in the 5m window and $asset matches entity context.

Events

$asset entity context (ASSET)

  • graph.metadata.entity_type = "ASSET"
  • graph.metadata.source_type = "ENTITY_CONTEXT"
  • graph.entity.asset.platform_software.platform = "WINDOWS"
  • graph.relations.entity.group.group_display_name = "Domain Computers"

$process PROCESS_LAUNCH (1, 4688)

  • target.process.command_line matches "net.*use.*(C|ADMIN|IPC)\$"

Match and Correlation

Match key
$ip (principal.ip)
Within
5m

Outcome

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

FieldExpression
risk_score35
event_countcount_distinct($process.metadata.id)
principal_process_pidarray_distinct($process.principal.process.pid)
principal_process_command_linearray_distinct($process.principal.process.command_line)
principal_process_file_sha256array_distinct($process.principal.process.file.sha256)
principal_process_file_full_patharray_distinct($process.principal.process.file.full_path)
principal_process_product_specific_process_idarray_distinct($process.principal.process.product_specific_process_id)
principal_process_parent_process_product_specific_process_idarray_distinct($process.principal.process.parent_process.product_specific_process_id)
target_process_pidarray_distinct($process.target.process.pid)
target_process_command_linearray_distinct($process.target.process.command_line)
target_process_file_sha256array_distinct($process.target.process.file.sha256)
target_process_file_full_patharray_distinct($process.target.process.file.full_path)
target_process_product_specific_process_idarray_distinct($process.target.process.product_specific_process_id)
principal_user_useridarray_distinct($process.principal.user.userid)

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

Telemetry Coverage

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_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
}

YARA-L Rule Structure

Condition

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"

Match and Correlation

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

Outcome

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

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)

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 Movement

Telemetry Coverage

PlatformRecord / event type
Microsoft 365UserLoggedIn

Rules Detecting the Same Action

These rules filter on the same operation.

Rule Body

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

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
}

YARA-L Rule Structure

Condition

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"

Match and Correlation

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

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($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)

Back to all YARA-L rules