Detection rules › YARA-L
AWS Privilege Escalation Using IAM Access Key
Detect when a user creates a new access key for another user and escalates privileges using this newly created access key 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_access_key {
meta:
author = "Google Cloud Security"
description = "Detect when a user creates a new access key for another user and escalates privileges using this newly created access key from the same IP."
rule_id = "mr_a28c56ea-b5e6-4e23-8cb8-f306587b832b"
rule_name = "AWS Privilege Escalation Using IAM Access Key"
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:
$accesskey.metadata.vendor_name = "AMAZON"
$accesskey.metadata.product_name = "AWS CloudTrail"
$accesskey.metadata.product_event_type = "CreateAccessKey"
$accesskey.security_result.action= "ALLOW"
$accesskey.principal.user.user_display_name != $accesskey.target.user.userid
$accesskey.principal.user.userid = $p_userid
$accesskey.target.user.userid = $t_userid
$privesc.metadata.vendor_name = "AMAZON"
$privesc.metadata.product_name = "AWS CloudTrail"
//Same IP address and Access Key used
$accesskey.principal.ip = $privesc.principal.ip
$accesskey.target.resource.product_object_id = $privesc.additional.fields["accessKeyId"]
$accesskey.metadata.event_timestamp.seconds < $privesc.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($privesc.metadata.id)
$network_http_user_agent = array_distinct($privesc.network.http.user_agent)
$principal_ip = array_distinct($privesc.principal.ip)
$principal_ip_country = array_distinct($privesc.principal.ip_geo_artifact.location.country_or_region)
$principal_ip_state = array_distinct($privesc.principal.ip_geo_artifact.location.state)
$principal_user_display_name = array_distinct($privesc.principal.user.user_display_name)
$dc_principal_user_display_name = count_distinct($privesc.principal.user.user_display_name)
$is_mfa_used = array_distinct($privesc.principal.user.attribute.labels["mfaAuthenticated"])
$target_resource_name = array_distinct($privesc.target.resource.name)
$target_resource_product_object_id = array_distinct($privesc.target.resource.product_object_id)
$product_event_types = array_distinct($privesc.metadata.product_event_type)
condition:
$accesskey and $privesc
}
YARA-L rule structure
Condition
Fires when at least one $accesskey event in the 1h window and at least one $privesc event in the 1h window.
Events
$accesskey
metadata.product_event_type = "CreateAccessKey"security_result.action = "ALLOW"
$privesc
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($privesc.metadata.id) |
network_http_user_agent | array_distinct($privesc.network.http.user_agent) |
principal_ip | array_distinct($privesc.principal.ip) |
principal_ip_country | array_distinct($privesc.principal.ip_geo_artifact.location.country_or_region) |
principal_ip_state | array_distinct($privesc.principal.ip_geo_artifact.location.state) |
principal_user_display_name | array_distinct($privesc.principal.user.user_display_name) |
dc_principal_user_display_name | count_distinct($privesc.principal.user.user_display_name) |
is_mfa_used | array_distinct($privesc.principal.user.attribute.labels["mfaAuthenticated"]) |
target_resource_name | array_distinct($privesc.target.resource.name) |
target_resource_product_object_id | array_distinct($privesc.target.resource.product_object_id) |
product_event_types | array_distinct($privesc.metadata.product_event_type) |