Detection rules › YARA-L

YARA-L rules: 19

AWS Security Group Open To The World

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

Detect when an AWS security group is opened to the world (0.0.0.0/0) or (::/0)

MITRE ATT&CK Coverage

TacticTechniques
Defense Impairment

Telemetry Coverage

Rule Body

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

rule aws_security_group_open_to_world {

  meta:
    author = "Google Cloud Security"
    description = "Detect when an AWS security group is opened to the world (0.0.0.0/0) or (::/0)"
    rule_id = "mr_51e7e8c9-f460-4207-8aa9-70a58d3d1ee3"
    rule_name = "AWS Security Group Open To The World"
    mitre_attack_tactic = "Defense Evasion"
    mitre_attack_technique = "Impair Defenses"
    mitre_attack_url = "https://attack.mitre.org/techniques/T1562/"
    mitre_attack_version = "v13.1"
    type = "Alert"
    data_source = "AWS CloudTrail"
    platform = "AWS"
    severity = "High"
    priority = "High"

  events:
    $cloudtrail.metadata.vendor_name = "AMAZON"
    $cloudtrail.metadata.product_name = "AWS CloudTrail"
    $cloudtrail.metadata.product_event_type = "AuthorizeSecurityGroupIngress"
    (
        $cloudtrail.target.resource.attribute.labels["ipPermissions cidrIp"] = "0.0.0.0/0" or
        $cloudtrail.target.resource.attribute.labels["ipPermissions cidrIpv6"] = "::/0"
    )
    $cloudtrail.security_result.action = "ALLOW"
    $cloudtrail.additional.fields["recipientAccountId"] = $accountId

  match:
    $accountId over 1h

  outcome:
    $risk_score = max(75)
    $mitre_attack_tactic = "Defense Evasion"
    $mitre_attack_technique = "Impair Defenses"
    $mitre_attack_technique_id = "T1562"
    $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 = "AuthorizeSecurityGroupIngress"
  • target.resource.attribute.labels["ipPermissions cidrIp"] = "0.0.0.0/0"
  • target.resource.attribute.labels["ipPermissions cidrIpv6"] = "::/0"
  • security_result.action = "ALLOW"

Match and Correlation

Match key
$accountId (additional.fields["recipientAccountId"])
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($cloudtrail.metadata.id)
network_http_user_agentarray_distinct($cloudtrail.network.http.user_agent)
principal_iparray_distinct($cloudtrail.principal.ip)
principal_ip_countryarray_distinct($cloudtrail.principal.ip_geo_artifact.location.country_or_region)
principal_ip_statearray_distinct($cloudtrail.principal.ip_geo_artifact.location.state)
principal_user_display_namearray_distinct($cloudtrail.principal.user.user_display_name)
recipient_aws_account_idarray_distinct($cloudtrail.additional.fields["recipientAccountId"])
aws_regionarray_distinct($cloudtrail.principal.location.name)
target_resource_namearray_distinct($cloudtrail.target.resource.name)
target_resource_product_object_idarray_distinct($cloudtrail.target.resource.product_object_id)

Network Connection First Seen In Past Day

#
Severity
low
Type
alert
Time window
1d
Match by
ip
Author
Google Cloud Security
Source
github.com/chronicle/detection-rules

Detect network connection to an ip address that was only seen for the first time in the past 24 hours

Telemetry Coverage

Rule Body

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

rule network_connection_first_seen_in_past_day {

  meta:
    author = "Google Cloud Security"
    description = "Detect network connection to an ip address that was only seen for the first time in the past 24 hours"
    rule_id = "mr_c3c9e4d3-eaa5-4f5b-9c64-70ce93247c51"
    rule_name = "Network Connection First Seen In Past Day"
    type = "alert"
    tags = "first last seen"
    data_source = "microsoft windows , gcp firewall, microsoft sysmon, crowdstrike, gcp scc, zeek"
    severity = "Low"
    priority = "Low"

  events:
    $network.metadata.event_type = "NETWORK_CONNECTION"
    $network.target.ip = $ip
    //Target IP is not part of RFC1918 space, can modify as needed
    not net.ip_in_range_cidr ($network.target.ip, "10.0.0.0/24")
    not net.ip_in_range_cidr ($network.target.ip, "172.16.0.0/20")
    not net.ip_in_range_cidr ($network.target.ip, "192.168.0.0/16")

    //derived from events ingested by Chronicle
    $entity.graph.entity.artifact.ip  = $ip
    $entity.graph.metadata.entity_type = "IP_ADDRESS"
    $entity.graph.metadata.source_type = "DERIVED_CONTEXT"
    $entity.graph.entity.artifact.first_seen_time.seconds > 0

    //calculate the different between current time and the first time the ip was listed as seen in the entity graph
    86400 > timestamp.current_seconds() - $entity.graph.entity.artifact.first_seen_time.seconds

  match:
    $ip over 24h

  outcome:
    $risk_score = 35
    $event_count = count_distinct($network.metadata.id)
    //added to populate alert graph with additional context
    $principal_ip = array_distinct($network.principal.ip)
    // Commented out target.ip because it is already represented in graph as match variable. If match changes, can uncomment to add to results
    //$target_ip = array_distinct($network.target.ip)
    $principal_process_pid = array_distinct($network.principal.process.pid)
    $principal_process_command_line = array_distinct($network.principal.process.command_line)
    $principal_process_file_sha256 = array_distinct($network.principal.process.file.sha256)
    $principal_process_file_full_path = array_distinct($network.principal.process.file.full_path)
    $principal_process_product_specific_process_id = array_distinct($network.principal.process.product_specific_process_id)
    $principal_process_parent_process_product_specific_process_id = array_distinct($network.principal.process.parent_process.product_specific_process_id)
    $target_process_pid = array_distinct($network.target.process.pid)
    $target_process_command_line = array_distinct($network.target.process.command_line)
    $target_process_file_sha256 = array_distinct($network.target.process.file.sha256)
    $target_process_file_full_path = array_distinct($network.target.process.file.full_path)
    $target_process_product_specific_process_id = array_distinct($network.target.process.product_specific_process_id)
    $target_process_parent_process_product_specific_process_id = array_distinct($network.target.process.parent_process.product_specific_process_id)
    $principal_user_userid = array_distinct($network.principal.user.userid)
    $target_user_userid = array_distinct($network.target.user.userid)

  condition:
    $network and $entity
}

YARA-L Rule Structure

Condition

Fires when at least one $network event in the 24h window and $entity matches entity context.

Events

$entity entity context (IP_ADDRESS)

  • graph.metadata.entity_type = "IP_ADDRESS"
  • graph.metadata.source_type = "DERIVED_CONTEXT"
  • graph.entity.artifact.first_seen_time.seconds > "0"
  • timestamp.current_seconds() time_arithmetic "graph.entity.artifact.first_seen_time.seconds" or "86400"

$network NETWORK_CONNECTION (3, 5156)

  • target.ip cidr_match "10.0.0.0/24"
  • target.ip cidr_match "172.16.0.0/20"
  • target.ip cidr_match "192.168.0.0/16"

Match and Correlation

Match key
$ip (target.ip)
Within
1d

Outcome

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

FieldExpression
risk_score35
event_countcount_distinct($network.metadata.id)
principal_iparray_distinct($network.principal.ip)
principal_process_pidarray_distinct($network.principal.process.pid)
principal_process_command_linearray_distinct($network.principal.process.command_line)
principal_process_file_sha256array_distinct($network.principal.process.file.sha256)
principal_process_file_full_patharray_distinct($network.principal.process.file.full_path)
principal_process_product_specific_process_idarray_distinct($network.principal.process.product_specific_process_id)
principal_process_parent_process_product_specific_process_idarray_distinct($network.principal.process.parent_process.product_specific_process_id)
target_process_pidarray_distinct($network.target.process.pid)
target_process_command_linearray_distinct($network.target.process.command_line)
target_process_file_sha256array_distinct($network.target.process.file.sha256)
target_process_file_full_patharray_distinct($network.target.process.file.full_path)
target_process_product_specific_process_idarray_distinct($network.target.process.product_specific_process_id)
target_process_parent_process_product_specific_process_idarray_distinct($network.target.process.parent_process.product_specific_process_id)
principal_user_useridarray_distinct($network.principal.user.userid)
target_user_useridarray_distinct($network.target.user.userid)

Back to all YARA-L rules