Detection rules › YARA-L

AWS Privilege Escalation Using IAM Access Key

Severity
low
Type
Alert
Time window
1h
Match by
p_userid
Author
Google Cloud Security
Source
github.com/chronicle/detection-rules

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

TacticTechniques
PersistenceT1136.003 Create Account: Cloud Account

Event coverage

Rule body yaral

/*
 * Copyright 2023 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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
}

Detection logic

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

No field filters (binds the event for correlation only).

Correlation

Joined on
$accesskey.principal.user.user_display_name != $accesskey.target.user.userid
$accesskey.principal.ip = $privesc.principal.ip
$accesskey.target.resource.product_object_id = $privesc.additional.fields["accessKeyId"]
Order
$accesskey before $privesc
Match key
$p_userid (principal.user.userid)
Within
1h

Outcome

Fields the detection emits on a match. $risk_score drives alerting; Chronicle surfaces the rest on the detection.

FieldExpression
risk_scoremax(35)
event_countcount_distinct($privesc.metadata.id)
network_http_user_agentarray_distinct($privesc.network.http.user_agent)
principal_iparray_distinct($privesc.principal.ip)
principal_ip_countryarray_distinct($privesc.principal.ip_geo_artifact.location.country_or_region)
principal_ip_statearray_distinct($privesc.principal.ip_geo_artifact.location.state)
principal_user_display_namearray_distinct($privesc.principal.user.user_display_name)
dc_principal_user_display_namecount_distinct($privesc.principal.user.user_display_name)
is_mfa_usedarray_distinct($privesc.principal.user.attribute.labels["mfaAuthenticated"])
target_resource_namearray_distinct($privesc.target.resource.name)
target_resource_product_object_idarray_distinct($privesc.target.resource.product_object_id)
product_event_typesarray_distinct($privesc.metadata.product_event_type)