Detection rules › YARA-L

Google Cloud Service Account Key Created or Uploaded

Severity
medium
Type
alert
Time window
30m
Match by
sa_key_id
Author
Google Cloud Security
Source
github.com/chronicle/detection-rules

Detects when a service account key is created in or uploaded to a monitored Google Cloud project.

MITRE ATT&CK coverage

References

Telemetry coverage

Rules detecting the same action

These rules filter on the same operation.

Rule body

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

rule google_cloud_service_account_key_created_or_uploaded {

  meta:
    author = "Google Cloud Security"
    description = "Detects when a service account key is created in or uploaded to a monitored Google Cloud project."
    rule_id = "mr_751d64b3-2aef-4c5b-bf39-abc6577f6ce8"
    rule_name = "Google Cloud Service Account Key Created or Uploaded"
    assumption = "Google SecOps is ingesting Google Cloud logs. Reference: https://cloud.google.com/chronicle/docs/ingestion/cloud/ingest-gcp-logs"
    type = "alert"
    severity = "Medium"
    priority = "Medium"
    platform = "Google Cloud"
    data_source = "GCP Cloud Audit"
    mitre_attack_tactic = "Persistence"
    mitre_attack_technique = "Account Manipulation: Additional Cloud Credentials"
    mitre_attack_url = "https://attack.mitre.org/techniques/T1098/001/"
    mitre_attack_version = "v15"
    reference = "https://cloud.google.com/iam/docs/best-practices-for-managing-service-account-keys"

  events:
    $gc.metadata.log_type = "GCP_CLOUDAUDIT"
    $gc.metadata.product_name = "Google Cloud IAM"
    (
        $gc.metadata.product_event_type = "google.iam.admin.v1.CreateServiceAccountKey" or
        $gc.metadata.product_event_type = "google.iam.admin.v1.UploadServiceAccountKey"
    )
    $gc.security_result.action = "ALLOW"
    $gc.security_result.detection_fields["key_id"] = $sa_key_id

  match:
    $sa_key_id over 30m

  outcome:
    $risk_score = max(65)
    $mitre_attack_tactic = "Persistence"
    $mitre_attack_technique = "Account Manipulation: Additional Cloud Credentials"
    $mitre_attack_technique_id = "T1098.001"
    $event_count = count_distinct($gc.metadata.id)
    $principal_ip = array_distinct($gc.principal.ip)
    $principal_user_userid = array_distinct($gc.principal.user.userid)
    $principal_ip_country = array_distinct($gc.principal.ip_geo_artifact.location.country_or_region)
    $principal_ip_state = array_distinct($gc.principal.ip_geo_artifact.location.state)
    $principal_ip_city = array_distinct($gc.principal.location.city)
    $security_result_summary = array_distinct($gc.security_result.summary)
    $sa_key_expiry_date = array_distinct(timestamp.get_date(cast.as_int($gc.about.labels["res_valid_before_time"])))

  condition:
    $gc
}

YARA-L rule structure

Condition

Fires when at least one $gc event in the 30m window.

Events

$gc

  • metadata.log_type = "GCP_CLOUDAUDIT"
  • metadata.product_event_type is one of:
    • google.iam.admin.v1.CreateServiceAccountKey
    • google.iam.admin.v1.UploadServiceAccountKey
  • security_result.action = "ALLOW"

Match and correlation

Match key
$sa_key_id (security_result.detection_fields["key_id"])
Within
30m

Outcome

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

FieldExpression
risk_scoremax(65)
event_countcount_distinct($gc.metadata.id)
principal_iparray_distinct($gc.principal.ip)
principal_user_useridarray_distinct($gc.principal.user.userid)
principal_ip_countryarray_distinct($gc.principal.ip_geo_artifact.location.country_or_region)
principal_ip_statearray_distinct($gc.principal.ip_geo_artifact.location.state)
principal_ip_cityarray_distinct($gc.principal.location.city)
security_result_summaryarray_distinct($gc.security_result.summary)
sa_key_expiry_datearray_distinct(timestamp.get_date(cast.as_int($gc.about.labels["res_valid_before_time"])))