Detection rules › YARA-L

GCP Service API Key Retrieved

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

Detects a successful attempt to retrieve the service API Keys.

MITRE ATT&CK coverage

TacticTechniques
Credential Access

Telemetry coverage

Rule body

// Copyright 2024 Google LLC. Licensed under Apache-2.0.

 rule gcp_service_api_key_retrieved {

  meta:
    author = "Google Cloud Security"
    description = "Detects a successful attempt to retrieve the service API Keys."
    rule_id = "mr_ee63778e-20ac-482c-84ef-abf5ceacd36e"
    rule_name = "GCP Service API Key Retrieved"
    mitre_attack_tactic = "Credential Access"
    mitre_attack_technique = "Credentials from Password Stores"
    mitre_attack_url = "https://attack.mitre.org/techniques/T1555/"
    mitre_attack_version = "v14.1"
    type = "Alert"
    data_source = "GCP Cloud Audit"
    platform = "GCP"
    severity = "High"
    priority = "High"

  events:
    $gcp.metadata.log_type = "GCP_CLOUDAUDIT"
    $gcp.metadata.product_event_type = "google.api.apikeys.v2.ApiKeys.GetKeyString"
    $gcp.target.application = "apikeys.googleapis.com"
    $gcp.security_result.action = "ALLOW"
    $gcp.principal.user.userid = $userid

  match:
    $userid over 1h

  outcome:
    $risk_score = max(75)
    $mitre_attack_tactic = "Credential Access"
    $mitre_attack_technique = "Credentials from Password Stores"
    $mitre_attack_technique_id = "T1555"
    $event_count = count_distinct($gcp.metadata.id)
    $network_http_user_agent = array_distinct($gcp.network.http.user_agent)
    $principal_ip = array_distinct($gcp.principal.ip)
    $principal_ip_country = array_distinct($gcp.principal.ip_geo_artifact.location.country_or_region)
    $principal_ip_state = array_distinct($gcp.principal.ip_geo_artifact.location.state)
    $principal_user_id = array_distinct($gcp.principal.user.userid)
    $principal_user_display_name = array_distinct($gcp.principal.user.user_display_name)
    $target_resource_name = array_distinct($gcp.target.resource.name)
    $dc_target_resource_name = count_distinct($gcp.target.resource.name)

  condition:
    $gcp
}

YARA-L rule structure

Condition

Fires when at least one $gcp event in the 1h window.

Events

$gcp

  • metadata.log_type = "GCP_CLOUDAUDIT"
  • metadata.product_event_type = "google.api.apikeys.v2.ApiKeys.GetKeyString"
  • target.application = "apikeys.googleapis.com"
  • security_result.action = "ALLOW"

Match and correlation

Match key
$userid (principal.user.userid)
Within
1h

Outcome

Outcome variables add context to a detection. When the rule generates an alert, $risk_score is displayed with it.

FieldExpression
risk_scoremax(75)
event_countcount_distinct($gcp.metadata.id)
network_http_user_agentarray_distinct($gcp.network.http.user_agent)
principal_iparray_distinct($gcp.principal.ip)
principal_ip_countryarray_distinct($gcp.principal.ip_geo_artifact.location.country_or_region)
principal_ip_statearray_distinct($gcp.principal.ip_geo_artifact.location.state)
principal_user_idarray_distinct($gcp.principal.user.userid)
principal_user_display_namearray_distinct($gcp.principal.user.user_display_name)
target_resource_namearray_distinct($gcp.target.resource.name)
dc_target_resource_namecount_distinct($gcp.target.resource.name)