Detection rules › YARA-L
YARA-L rules: 03
High Risk User Download Executable From Macro
#Executable downloaded by Microsoft Excel by user with GCP entity relationship
MITRE ATT&CK Coverage
| Tactic | Techniques |
|---|---|
| Execution |
Telemetry Coverage
Rule Body
// Copyright 2023 Google LLC. Licensed under Apache-2.0.
rule high_risk_user_download_executable_from_macro {
meta:
author = "Google Cloud Security"
description = "Executable downloaded by Microsoft Excel by user with GCP entity relationship"
rule_id = "mr_352c77a7-67b6-4dfb-95e5-75fef8fa4a6c"
rule_name = "High Risk User Download Executable From Macro"
type = "alert"
data_source = "zscaler nss, crowdstrike"
tags = "user entity, resource entity"
severity = "High"
priority = "High"
platform = "Windows"
assumption = "This rule assumes that GCP DLP has been deployed and resources have been assigned to a user context"
tactic = "TA0002"
technique = "T1204.002"
events:
// proxy event with suspected executable download
$proxy_event.metadata.event_type = "NETWORK_HTTP"
$proxy_event.target.url = /.*\.exe$/ or
$proxy_event.network.received_bytes > 102400
$proxy_event.principal.user.userid = $user
$proxy_event.principal.user.userid != /test/
$proxy_event.target.hostname = $hostname
// correlate with EDR event indicating Excel activity
$edr_event.target.user.userid = $user
$edr_event.target.process.file.full_path = /excel/ nocase
($edr_event.metadata.event_type = "NETWORK_HTTP" or $edr_event.metadata.event_type = "NETWORK_CONNECTION")
$edr_event.target.hostname = $hostname
// first hop into entity graph to find the permissions
$user_entity.graph.entity.user.userid = $user
$user_entity.graph.metadata.entity_type = "USER"
$user_entity.graph.metadata.source_type = "ENTITY_CONTEXT"
$user_entity.graph.relations.entity.resource.name != ""
$user_entity.graph.relations.entity.resource.name = $table_name
// second hop for the table context
$table_context.graph.entity.resource.product_object_id = $table_name
$table_context.graph.metadata.entity_type = "RESOURCE"
$table_context.graph.metadata.source_type = "ENTITY_CONTEXT"
$table_context.graph.metadata.product_name = "GCP DLP CONTEXT"
match:
$user, $hostname over 5m
outcome:
$risk_score = max(if($table_context.graph.entity.resource.attribute.labels.value = "US_SOCIAL_SECURITY_NUMBER", 80))
$entity_resource_name = array_distinct($table_context.graph.entity.resource.name)
// added to populate alert graph with additional context
$principal_hostname = array_distinct($proxy_event.principal.hostname)
// Commented out target.hostname because it is already represented in graph as match variable. If match changes, can uncomment to add to results
//$target_hostname = array_distinct($proxy_event.target.hostname)
$principal_process_pid = array_distinct($edr_event.principal.process.pid)
$principal_process_command_line = array_distinct($edr_event.principal.process.command_line)
$principal_process_file_sha256 = array_distinct($edr_event.principal.process.file.sha256)
$principal_process_file_full_path = array_distinct($edr_event.principal.process.file.full_path)
$principal_process_product_specific_process_id = array_distinct($edr_event.principal.process.product_specific_process_id)
$principal_process_parent_process_product_specific_process_id = array_distinct($edr_event.principal.process.parent_process.product_specific_process_id)
$target_process_pid = array_distinct($edr_event.target.process.pid)
$target_process_command_line = array_distinct($edr_event.target.process.command_line)
$target_process_file_sha256 = array_distinct($edr_event.target.process.file.sha256)
$target_process_file_full_path = array_distinct($edr_event.target.process.file.full_path)
$target_process_product_specific_process_id = array_distinct($edr_event.target.process.product_specific_process_id)
$target_process_parent_process_product_specific_process_id = array_distinct($edr_event.target.process.parent_process.product_specific_process_id)
// Commented out principal.user.userid because it is already represented in graph as match variable. If match changes, can uncomment to add to results
//$principal_user_userid = array_distinct($edr_event.principal.user.userid)
$target_user_userid = array_distinct($edr_event.target.user.userid)
$target_url = array_distinct($proxy_event.target.url)
condition:
$proxy_event and $edr_event and $user_entity and $table_context
}
YARA-L Rule Structure
Condition
Fires when at least one $proxy_event event in the 5m window and at least one $edr_event event in the 5m window and $user_entity matches entity context and $table_context matches entity context.
Events
$edr_event
target.process.file.full_path matches "excel"
$proxy_event
target.url matches ".*\.exe$"network.received_bytes > "102400"principal.user.userid matches "test"
$table_context
graph.metadata.entity_type = "RESOURCE"graph.metadata.source_type = "ENTITY_CONTEXT"graph.metadata.product_name = "GCP DLP CONTEXT"
$user_entity
graph.metadata.entity_type = "USER"graph.metadata.source_type = "ENTITY_CONTEXT"graph.relations.entity.resource.name is not null
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($table_context.graph.entity.resource.attribute.labels.value = "US_SOCIAL_SECURITY_NUMBER", 80)) |
entity_resource_name | array_distinct($table_context.graph.entity.resource.name) |
principal_hostname | array_distinct($proxy_event.principal.hostname) |
principal_process_pid | array_distinct($edr_event.principal.process.pid) |
principal_process_command_line | array_distinct($edr_event.principal.process.command_line) |
principal_process_file_sha256 | array_distinct($edr_event.principal.process.file.sha256) |
principal_process_file_full_path | array_distinct($edr_event.principal.process.file.full_path) |
principal_process_product_specific_process_id | array_distinct($edr_event.principal.process.product_specific_process_id) |
principal_process_parent_process_product_specific_process_id | array_distinct($edr_event.principal.process.parent_process.product_specific_process_id) |
target_process_pid | array_distinct($edr_event.target.process.pid) |
target_process_command_line | array_distinct($edr_event.target.process.command_line) |
target_process_file_sha256 | array_distinct($edr_event.target.process.file.sha256) |
target_process_file_full_path | array_distinct($edr_event.target.process.file.full_path) |
target_process_product_specific_process_id | array_distinct($edr_event.target.process.product_specific_process_id) |
target_process_parent_process_product_specific_process_id | array_distinct($edr_event.target.process.parent_process.product_specific_process_id) |
target_user_userid | array_distinct($edr_event.target.user.userid) |
target_url | array_distinct($proxy_event.target.url) |
Hunt for user API endpoint requests in the Microsoft Graph
#Identify the use of the user API call to collect a listing of users. This can be chatty due to other commands calling this single API.
Rule Body
// Copyright 2025 Google LLC. Licensed under Apache-2.0.
rule ms_graph_user_endpoint_requests {
meta:
author = "Google Cloud Security"
description = "Identify the use of the user API call to collect a listing of users. This can be chatty due to other commands calling this single API."
rule_id = "mr_e67d0d46-76ad-4718-95df-5536a154fc24"
rule_name = "Hunt for user API endpoint requests in the Microsoft Graph"
assumption = "Focus on PowerShell as part of the User agent or adding IP addresses or applications who call this endpoint should be added to focus this detection."
type = "Hunt"
data_source = "MS Graph Activity Logs"
platform = "Azure"
severity = "Info"
priority = "Info"
events:
$api.metadata.event_type = "NETWORK_HTTP"
$api.metadata.product_event_type = "Microsoft Graph Activity"
$api.target.url = "https://graph.microsoft.com/v1.0/users" nocase
//UA String could be adjusted to focus more broadly on calls to this API or focus on calls from PowerShell
//$api.network.http.user_agent = /PowerShell/ nocase
//May want to filter out IP addresses of admin consoles
//$api.principal.ip != "10.10.10.10"
$api.network.http.method = "GET"
$api.network.http.response_code = 200
$api.principal.ip = $ip
$api.network.session_id = $session
match:
$ip, $session over 5m
outcome:
$risk_score = 15
$event_count = count_distinct($api.metadata.id)
$requesting_user_guid = array_distinct($api.principal.user.userid)
$requesting_ip = array_distinct($api.principal.ip)
$user_agent = array_distinct($api.network.http.user_agent)
$location = array_distinct($api.principal.location.name)
$target_application_id_guid = array_distinct($api.target.resource.product_object_id)
$session_id = array_distinct($api.network.session_id)
$target_url = array_distinct($api.target.url)
condition:
$api
}
YARA-L Rule Structure
Condition
Fires when at least one $api event in the 5m window.
Events
$api
metadata.product_event_type = "Microsoft Graph Activity"target.url = "https://graph.microsoft.com/v1.0/users"network.http.method = "GET"network.http.response_code = "200"
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 | 15 |
event_count | count_distinct($api.metadata.id) |
requesting_user_guid | array_distinct($api.principal.user.userid) |
requesting_ip | array_distinct($api.principal.ip) |
user_agent | array_distinct($api.network.http.user_agent) |
location | array_distinct($api.principal.location.name) |
target_application_id_guid | array_distinct($api.target.resource.product_object_id) |
session_id | array_distinct($api.network.session_id) |
target_url | array_distinct($api.target.url) |
Network Traffic To Specific Country
#Identify network traffic based on target country
Telemetry Coverage
Rule Body
// Copyright 2023 Google LLC. Licensed under Apache-2.0.
rule network_traffic_to_specific_country {
meta:
author = "Google Cloud Security"
description = "Identify network traffic based on target country"
rule_id = "mr_f1ab5184-771f-48dc-82e6-11a72632fcd5"
rule_name = "Network Traffic To Specific Country"
type = "alert"
tags = "geoip enrichment"
data_source = "microsoft windows events"
severity = "Low"
priority = "Low"
events:
$network.metadata.event_type = "NETWORK_CONNECTION"
//Specify a country of interest to monitor or add additional countries using an or statement
$network.target.ip_geo_artifact.location.country_or_region = "France" nocase
$network.target.ip = $ip
match:
$ip over 30m
outcome:
$risk_score = max(35)
$event_count = count_distinct($network.metadata.id)
// added to populate alert graph with additional context
$principal_ip = array_distinct($network.principal.ip)
// Commented out target.ip because it is already represented in graph as match variable. If match changes, can uncomment to add to results
//$target_ip = array_distinct($network.target.ip)
$principal_process_pid = array_distinct($network.principal.process.pid)
$principal_process_command_line = array_distinct($network.principal.process.command_line)
$principal_process_file_sha256 = array_distinct($network.principal.process.file.sha256)
$principal_process_file_full_path = array_distinct($network.principal.process.file.full_path)
$principal_process_product_specific_process_id = array_distinct($network.principal.process.product_specific_process_id)
$principal_process_parent_process_product_specific_process_id = array_distinct($network.principal.process.parent_process.product_specific_process_id)
$target_process_pid = array_distinct($network.target.process.pid)
$target_process_command_line = array_distinct($network.target.process.command_line)
$target_process_file_sha256 = array_distinct($network.target.process.file.sha256)
$target_process_file_full_path = array_distinct($network.target.process.file.full_path)
$target_process_product_specific_process_id = array_distinct($network.target.process.product_specific_process_id)
$target_process_parent_process_product_specific_process_id = array_distinct($network.target.process.parent_process.product_specific_process_id)
$principal_user_userid = array_distinct($network.principal.user.userid)
$target_user_userid = array_distinct($network.target.user.userid)
condition:
$network
}
YARA-L Rule Structure
Condition
Fires when at least one $network event in the 30m window.
Events
$network
target.ip_geo_artifact.location.country_or_region = "France"
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($network.metadata.id) |
principal_ip | array_distinct($network.principal.ip) |
principal_process_pid | array_distinct($network.principal.process.pid) |
principal_process_command_line | array_distinct($network.principal.process.command_line) |
principal_process_file_sha256 | array_distinct($network.principal.process.file.sha256) |
principal_process_file_full_path | array_distinct($network.principal.process.file.full_path) |
principal_process_product_specific_process_id | array_distinct($network.principal.process.product_specific_process_id) |
principal_process_parent_process_product_specific_process_id | array_distinct($network.principal.process.parent_process.product_specific_process_id) |
target_process_pid | array_distinct($network.target.process.pid) |
target_process_command_line | array_distinct($network.target.process.command_line) |
target_process_file_sha256 | array_distinct($network.target.process.file.sha256) |
target_process_file_full_path | array_distinct($network.target.process.file.full_path) |
target_process_product_specific_process_id | array_distinct($network.target.process.product_specific_process_id) |
target_process_parent_process_product_specific_process_id | array_distinct($network.target.process.parent_process.product_specific_process_id) |
principal_user_userid | array_distinct($network.principal.user.userid) |
target_user_userid | array_distinct($network.target.user.userid) |