Detection rules › YARA-L
YARA-L rules: 2b
| Rule | Severity |
|---|---|
| AWS New MFA Method Registered For User | medium |
| AWS Privilege Escalation Using IAM Login Profile | low |
| Network HTTP Low Prevalence Domain Access | critical |
AWS New MFA Method Registered For User
#Detects the registration of a new Multi Factor authentication method for an AWS user.
MITRE ATT&CK Coverage
| Tactic | Techniques |
|---|---|
| Persistence | |
| Credential Access |
Telemetry Coverage
Rule Body
// Copyright 2023 Google LLC. Licensed under Apache-2.0.
rule aws_new_mfa_method_registered_for_user {
meta:
author = "Google Cloud Security"
description = "Detects the registration of a new Multi Factor authentication method for an AWS user."
rule_id = "mr_bee2a210-111a-478a-a1a2-caeb9077eca2"
rule_name = "AWS New MFA Method Registered For User"
mitre_attack_tactic = "Credential Access, Defense Evasion, Persistence"
mitre_attack_technique = "Modify Authentication Process: Multi-Factor Authentication"
mitre_attack_url = "https://attack.mitre.org/techniques/T1556/006/"
mitre_attack_version = "v13.1"
type = "Alert"
data_source = "AWS CloudTrail"
platform = "AWS"
severity = "Medium"
priority = "Medium"
events:
$cloudtrail.metadata.vendor_name = "AMAZON"
$cloudtrail.metadata.product_name = "AWS CloudTrail"
(
$cloudtrail.metadata.product_event_type = "CreateVirtualMFADevice" or
$cloudtrail.metadata.product_event_type = "EnableMFADevice"
)
$cloudtrail.security_result.action = "ALLOW"
$cloudtrail.principal.user.user_display_name = $user_id
match:
$user_id over 1h
outcome:
$risk_score = max(
//Baseline
35 +
// High Risk for AWS Root User
if($cloudtrail.src.user.user_display_name = "AWS Root User", 50)
)
$mitre_attack_tactic = "Credential Access, Defense Evasion, Persistence"
$mitre_attack_technique = "Modify Authentication Process: Multi-Factor Authentication"
$mitre_attack_technique_id = "T1556.006"
$event_count = count_distinct($cloudtrail.metadata.id)
$network_http_user_agent = array_distinct($cloudtrail.network.http.user_agent)
$principal_ip = array_distinct($cloudtrail.principal.ip)
$principal_ip_country = array_distinct($cloudtrail.principal.ip_geo_artifact.location.country_or_region)
$principal_ip_state = array_distinct($cloudtrail.principal.ip_geo_artifact.location.state)
$principal_user_display_name = array_distinct($cloudtrail.principal.user.user_display_name)
$recipient_aws_account_id = array_distinct($cloudtrail.additional.fields["recipientAccountId"])
$aws_region = array_distinct($cloudtrail.principal.location.name)
$target_resource_name = array_distinct($cloudtrail.target.resource.name)
$target_resource_product_object_id = array_distinct($cloudtrail.target.resource.product_object_id)
condition:
$cloudtrail
}
YARA-L Rule Structure
Condition
Fires when at least one $cloudtrail event in the 1h window.
Events
$cloudtrail
metadata.product_event_type = "CreateVirtualMFADevice" or "EnableMFADevice"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 | max( 35 + if($cloudtrail.src.user.user_display_name = "AWS Root User", 50) ) |
event_count | count_distinct($cloudtrail.metadata.id) |
network_http_user_agent | array_distinct($cloudtrail.network.http.user_agent) |
principal_ip | array_distinct($cloudtrail.principal.ip) |
principal_ip_country | array_distinct($cloudtrail.principal.ip_geo_artifact.location.country_or_region) |
principal_ip_state | array_distinct($cloudtrail.principal.ip_geo_artifact.location.state) |
principal_user_display_name | array_distinct($cloudtrail.principal.user.user_display_name) |
recipient_aws_account_id | array_distinct($cloudtrail.additional.fields["recipientAccountId"]) |
aws_region | array_distinct($cloudtrail.principal.location.name) |
target_resource_name | array_distinct($cloudtrail.target.resource.name) |
target_resource_product_object_id | array_distinct($cloudtrail.target.resource.product_object_id) |
AWS Privilege Escalation Using IAM Login Profile
#Detect when a user creates or updates a login profile for another user and escalates privileges using this new user from the same IP.
MITRE ATT&CK Coverage
| Tactic | Techniques |
|---|---|
| Persistence |
Telemetry Coverage
Rule Body
// Copyright 2023 Google LLC. Licensed under Apache-2.0.
rule aws_privilege_escalation_using_iam_login_profile {
meta:
author = "Google Cloud Security"
description = "Detect when a user creates or updates a login profile for another user and escalates privileges using this new user from the same IP."
rule_id = "mr_b0d13079-dbe7-4c19-a8e9-23f98655a29b"
rule_name = "AWS Privilege Escalation Using IAM Login Profile"
mitre_attack_tactic = "Persistence"
mitre_attack_technique = "Cloud Account"
mitre_attack_url = "https://attack.mitre.org/techniques/T1136/003/"
mitre_attack_version = "v13.1"
type = "Alert"
data_source = "AWS CloudTrail"
platform = "AWS"
severity = "Low"
priority = "Low"
events:
$profile.metadata.vendor_name = "AMAZON"
$profile.metadata.product_name = "AWS CloudTrail"
$profile.metadata.product_event_type = "CreateLoginProfile" or $profile.metadata.product_event_type = "UpdateLoginProfile"
$profile.security_result.action= "ALLOW"
$profile.principal.user.userid = $p_userid
$profile.target.user.userid = $t_userid
$login.metadata.vendor_name = "AMAZON"
$login.metadata.product_name = "AWS CloudTrail"
$login.metadata.event_type = "USER_LOGIN"
$login.metadata.product_event_type = "ConsoleLogin"
$login.security_result.action= "ALLOW"
//Same IP address
$login.principal.ip = $profile.principal.ip
//User created and logged in
$profile.principal.user.user_display_name != $profile.target.user.userid
$login.target.user.user_display_name = $profile.target.user.userid
$profile.metadata.event_timestamp.seconds < $login.metadata.event_timestamp.seconds
match:
$p_userid over 1h
outcome:
$risk_score = max(35)
$mitre_attack_tactic = "Persistence"
$mitre_attack_technique = "Cloud Account"
$mitre_attack_technique_id = "T1136.003"
$event_count = count_distinct($login.metadata.id)
$network_http_user_agent = array_distinct($login.network.http.user_agent)
$principal_ip = array_distinct($login.principal.ip)
$principal_ip_country = array_distinct($login.principal.ip_geo_artifact.location.country_or_region)
$principal_ip_state = array_distinct($login.principal.ip_geo_artifact.location.state)
$principal_user_display_name = array_distinct($login.principal.user.user_display_name)
$dc_principal_user_display_name = count_distinct($login.principal.user.user_display_name)
$is_mfa_used = array_distinct($login.principal.user.attribute.labels["mfaAuthenticated"])
$target_resource_name = array_distinct($login.target.resource.name)
$target_resource_product_object_id = array_distinct($login.target.resource.product_object_id)
condition:
$profile and $login
}
YARA-L Rule Structure
Condition
Fires when at least one $profile event in the 1h window and at least one $login event in the 1h window.
Events
$profile
metadata.product_event_type = "CreateLoginProfile" or "UpdateLoginProfile"security_result.action = "ALLOW"principal.user.user_display_name cross_field_compare "profile.target.user.userid"
$login
metadata.product_event_type = "ConsoleLogin"security_result.action = "ALLOW"principal.ip cross_field_compare "profile.principal.ip"target.user.user_display_name cross_field_compare "profile.target.user.userid"
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($login.metadata.id) |
network_http_user_agent | array_distinct($login.network.http.user_agent) |
principal_ip | array_distinct($login.principal.ip) |
principal_ip_country | array_distinct($login.principal.ip_geo_artifact.location.country_or_region) |
principal_ip_state | array_distinct($login.principal.ip_geo_artifact.location.state) |
principal_user_display_name | array_distinct($login.principal.user.user_display_name) |
dc_principal_user_display_name | count_distinct($login.principal.user.user_display_name) |
is_mfa_used | array_distinct($login.principal.user.attribute.labels["mfaAuthenticated"]) |
target_resource_name | array_distinct($login.target.resource.name) |
target_resource_product_object_id | array_distinct($login.target.resource.product_object_id) |
Network HTTP Low Prevalence Domain Access
#Detects network web access to a low prevalence domain
Rule Body
// Copyright 2023 Google LLC. Licensed under Apache-2.0.
rule network_http_low_prevalence_domain_access {
meta:
author = "Google Cloud Security"
description = "Detects network web access to a low prevalence domain"
rule_id = "mr_c376478e-1c93-4d27-8bea-a56c3c0052f5"
rule_name = "Network HTTP Low Prevalence Domain Access"
type = "alert"
tags = "prevalence"
data_source = "zscalar"
severity = "Critical"
priority = "Critical"
events:
$http.metadata.event_type = "NETWORK_HTTP"
$http.principal.ip = $ip
// filter out URLs with RFC 1918 IP addresses, i.e., internal assets
not re.regex($http.target.hostname, `(127(?:\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$)|(10(?:\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$)|(192\.168(?:\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){2}$)|(172\.(?:1[6-9]|2\d|3[0-1])(?:\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){2})`)
// only match valid FQDN, filter out background non-routable noise
re.regex($http.target.hostname, `(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]`)
$http.target.hostname = $domain_name
$prevalence.graph.entity.domain.name = $domain_name
// derived from events ingested by Google SecOps
$prevalence.graph.metadata.entity_type = "DOMAIN_NAME"
$prevalence.graph.metadata.source_type = "DERIVED_CONTEXT"
$prevalence.graph.entity.domain.prevalence.day_count = 10
// tune prevalence as fits your results
$prevalence.graph.entity.domain.prevalence.rolling_max > 0
$prevalence.graph.entity.domain.prevalence.rolling_max <= 3
match:
$ip over 1h
outcome:
$risk_score = max(
// increment risk score based upon rolling_max prevalence
if ( $prevalence.graph.entity.domain.prevalence.rolling_max >= 10, 10) +
if ( $prevalence.graph.entity.domain.prevalence.rolling_max >= 2 and $prevalence.graph.entity.domain.prevalence.rolling_max <= 9 , 20) +
if ( $prevalence.graph.entity.domain.prevalence.rolling_max = 1, 30)
)
$event_count = count_distinct($http.metadata.id)
$domain_list = array_distinct($domain_name)
$domain_count = count_distinct($domain_name)
// added to populate alert graph with additional context
$principal_hostname = array_distinct($http.principal.hostname)
$target_hostname = array_distinct($http.target.hostname)
$principal_user_userid = array_distinct($http.principal.user.userid)
$target_url = array_distinct($http.target.url)
condition:
$http and $prevalence
}
YARA-L Rule Structure
Condition
Fires when at least one $http event in the 1h window and $prevalence matches entity context.
Events
$http
target.hostname matches "(127(?:\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$)|(10(?:\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$)|(192\.168(?:\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){2}$)|(172\.(?:1[6-9]|2\d|3[0-1])(?:\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){2})"target.hostname matches "(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]"
$prevalence
graph.metadata.entity_type = "DOMAIN_NAME"graph.metadata.source_type = "DERIVED_CONTEXT"graph.entity.domain.prevalence.day_count = "10"graph.entity.domain.prevalence.rolling_max > "0"graph.entity.domain.prevalence.rolling_max <= "3"
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 ( $prevalence.graph.entity.domain.prevalence.rolling_max >= 10, 10) + if ( $prevalence.graph.entity.domain.prevalence.rolling_max >= 2 and $prevalence.graph.entity.domain.prevalence.rolling_max <= 9 , 20) + if ( $prevalence.graph.entity.domain.prevalence.rolling_max = 1, 30) ) |
event_count | count_distinct($http.metadata.id) |
domain_list | array_distinct($domain_name) |
domain_count | count_distinct($domain_name) |
principal_hostname | array_distinct($http.principal.hostname) |
target_hostname | array_distinct($http.target.hostname) |
principal_user_userid | array_distinct($http.principal.user.userid) |
target_url | array_distinct($http.target.url) |