Detection rules › YARA-L
YARA-L rules: 01
AWS EC2 High Number Of API Calls
#Detect when an EC2 instance makes high number of API calls.
MITRE ATT&CK Coverage
| Tactic | Techniques |
|---|---|
| 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
Outcome
Outcome variables add context to a detection. When the rule generates an alert, $risk_score is displayed with it.
| Field | Expression |
|---|---|
risk_score | max(35) |
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) |
Entra ID Application Restore
#Entra ID application was restored. This implies a soft delete was performed at some point but less than 30 days ago.
Telemetry Coverage
| Platform | Record / event type |
|---|---|
| Azure | Restore application |
Rules Detecting the Same Action
These rules filter on the same operation.
- [Entra ID] Application Assigned Administrator Permissions Immediately After Obtaining Role Management Permissions (Kusto)
- [Entra ID] Application Granted Administrative Permission to Assign Microsoft Entra ID Roles (Kusto)
- Added Credentials to Existing Application (Sigma)
- Added Owner To Application (Sigma)
- Admin promotion after Role Management Application Permission Grant (Kusto)
- App Granted Microsoft Permissions (Sigma)
- App Granted Privileged Delegated Or App Permissions (Sigma)
- Application AppID Uri Configuration Changes (Sigma)
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
metadata.product_event_type = "Restore application"security_result.action = "ALLOW"
Match and Correlation
Outcome
Outcome variables add context to a detection. When the rule generates an alert, $risk_score is displayed with it.
| Field | Expression |
|---|---|
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) |
O365 AD PowerShell App Login Subsequent Activity
#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
| Tactic | Techniques |
|---|---|
| Persistence |
Telemetry Coverage
Rules Detecting the Same Action
These rules filter on the same operation.
- Azure Login Bypassing Conditional Access Policies (Sigma)
- Hunt for suspicious sign-in to Entra ID Using Extrnal Call Method (YARA-L)
- M365 Identity OAuth Flow by First-Party Microsoft App from Multiple IPs (Elastic)
- M365 Identity OAuth Flow by User Sign-in to Device Registration (Elastic)
- M365 Identity OAuth Phishing via First-Party Microsoft Application (Elastic)
- M365 Identity OAuth ROPC Grant via Legacy Authentication Client (Elastic)
- M365 Potential AiTM UserLoggedIn via Office App (Tycoon2FA) (Elastic)
- O365 Admin Login Activity To Uncommon Microsoft Cloud Apps (YARA-L)
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
metadata.product_event_type = "UserLoggedIn"target.resource.product_object_id = "1b730954-1685-4b74-9bfd-dac224a7b894"security_result.action = "ALLOW"
$other
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
Outcome
Outcome variables add context to a detection. When the rule generates an alert, $risk_score is displayed with it.
| Field | Expression |
|---|---|
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) |
principal_ip | array_distinct($login.principal.ip) |
target_resource_name | array_distinct($other.target.resource.name) |
O365 Persistent Login Activity To Azure AD PowerShell App
#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
| Tactic | Techniques |
|---|---|
| Lateral Movement |
Telemetry Coverage
| Platform | Record / event type |
|---|---|
| Microsoft 365 | UserLoggedIn |
Rules Detecting the Same Action
These rules filter on the same operation.
- Azure Login Bypassing Conditional Access Policies (Sigma)
- Hunt for suspicious sign-in to Entra ID Using Extrnal Call Method (YARA-L)
- M365 Identity OAuth Flow by First-Party Microsoft App from Multiple IPs (Elastic)
- M365 Identity OAuth Flow by User Sign-in to Device Registration (Elastic)
- M365 Identity OAuth Phishing via First-Party Microsoft Application (Elastic)
- M365 Identity OAuth ROPC Grant via Legacy Authentication Client (Elastic)
- M365 Potential AiTM UserLoggedIn via Office App (Tycoon2FA) (Elastic)
- O365 AD PowerShell App Login Subsequent Activity (YARA-L)
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
metadata.product_event_type = "UserLoggedIn"target.resource.product_object_id = "1b730954-1685-4b74-9bfd-dac224a7b894"security_result.action = "ALLOW"
Match and Correlation
Outcome
Outcome variables add context to a detection. When the rule generates an alert, $risk_score is displayed with it.
| Field | Expression |
|---|---|
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) |
principal_ip | array_distinct($login.principal.ip) |
target_user_userid | array_distinct($login.target.user.userid) |