默认检测规则

YARA-L 规则语言

YARA-L 是由 Google 开发的检测规则语言。YARA-L 的用途是摆脱单纯的数据查询检测,转而进行实际的事件驱动型调查。YARA-L 衍生自恶意软件分析中常用的 YARA 语言。L 代表日志。YARA-L 使您能够在检测中充分利用来自多个来源的所有信息,并将这些事件关联到可操作的提醒中。如需了解详情,请参阅 YARA-L 2.0 语言概览

Google Security Operations 示例检测规则

为了帮助您更快地采用 Google Security Operations Detection Engine,我们提供了包含示例规则的 GitHub 代码库。此代码库包含几个不同类别的检测规则,其中包括:

  • Google Cloud CloudAudit
  • Google Workspace
  • 信息性警告
  • 恶意软件
  • MITRE ATT&CK
  • SOC 首要规则
  • 可疑事件

每个类别都会采用特定的方法来查看数据源,并指定要使用的事件和匹配语句。

示例规则和调整

以下规则会创建一个用于跟踪事件类型的事件变量 $e1。事件变量可以是对要评估的数据有意义的任何值。在此事件中评估的 UDM 字段为 metadata.eventype,因此可以将其命名为 e1。下面几行用于在 e1 中搜索正则表达式匹配的具体出现。在 Google Security Operations 中创建检测的条件是 $e1 事件发生时。为便于调整,提供了一个 not 条件来排除命令行参数的某些非恶意路径。如果您发现来自其他已知文件路径的频繁误报,则可以将更多 not 条件添加到此规则。

rule suspicious_unusual_location_svchost_execution

{
 meta:
   author = "Google Cloud Security"
   description = "Windows 'svchost' executed from an unusual location"
   yara_version = "YL2.0"
   rule_version = "1.0"

 events:
   $e1.metadata.event_type = "PROCESS_LAUNCH"
   re.regex($e1.principal.process.command_line, `\bsvchost(\.exe)?\b`) nocase
   not re.regex($e1.principal.process.command_line, `\\Windows\\System32\\`) nocase

condition:
   $e1
}

指定多个事件变量

YARA-L 支持在规则中包含多个事件变量。在以下示例中,规则包含事件 $e1$e2。条件说明了触发检测的逻辑条件。

rule ExcludeZeroValues {
  meta:
    author = "noone@google.com"

  events:
    $e1.metadata.event_type = "NETWORK_DNS"
    $e1.principal.hostname = $hostname

    // $e1.principal.user.userid may be empty string.
    $e1.principal.user.userid != "Guest"

    $e2.metadata.event_type = "NETWORK_HTTP"
    $e2.principal.hostname = $hostname

    // $e2.target.asset_id cannot be empty string as explicitly specified.
    $e2.target.asset_id != ""

  match:
    // $hostname cannot be empty string.
    $hostname over 1h

  condition:
    $e1 and $e2
}

规则结果部分

使用结果部分在规则检测中设置保留变量,为下游使用提供丰富信息。例如,您可以添加严重级别评分信息(依赖于所分析事件的数据)。以下检测会检查两个事件以对 $hostname 值进行归因。如果 $hostnames 值在 5 分钟内匹配,系统会应用严重性得分。使用时间段时,Google Security Operations 检测引擎仅检查您指定的离散时间段。

rule OutcomeRuleMultiEvent {
    meta:
      author = "noone@google.com"
    events:
      $u.udm.principal.hostname = $hostname
      $asset_context.graph.entity.hostname = $hostname

      $severity = $asset_context.graph.entity.asset.vulnerabilities.severity

    match:
      $hostname over 5m

    outcome:
      $risk_score =
        max(
            100
          +   if($hostname = "my-hostname", 100, 50)
          +   if($severity = "HIGH", 10)
          +   if($severity = "MEDIUM", 5)
          +   if($severity = "LOW", 1)
        )

      $asset_id_list =
        array(
          if($u.principal.asset_id = "",
             "Empty asset id",
             $u.principal.asset_id
          )
        )

      $asset_id_distinct_list = array_distinct($u.principal.asset_id)

      $asset_id_count = count($u.principal.asset_id)

      $asset_id_distinct_count = count_distinct($u.principal.asset_id)

    condition:
      $u and $asset_context and $risk_score > 50 and not arrays.contains($asset_id_list, "id_1234")
}

总结

YARA-L 是一种灵活的检测语言,使您能够检查安全事件,而不仅仅是返回数据查询。事件变量用于跟踪规则的条件部分中使用的字段值。您可以使用单个事件、一段时间内的多个事件、将单个值的来源(例如,来自不同数据源的 $hostname)关联,甚至可以使用正则表达式等工具提供匹配项。请务必根据您自己的环境调整规则,为此,您可以在逻辑中指定排除项。您也可以使用参考列表将内容分为一组,然后在规则中引用该列表。不要忘记,Google Security Operations 不需要在每次检测到检测时都收到提醒。您可以出于多种目的跟踪检测,并且仅针对您确定在您的环境中最关键的那些检测发出提醒。