复合检测规则
Google SecOps 中的复合检测涉及关联多个 YARA-L 规则。本文档介绍了如何构建复合规则。如需了解详情,请参阅复合检测概览。
了解规则结构
复合检测规则始终是多事件规则,并且遵循与单事件规则相同的结构和语法。
复合规则包含以下基本组成部分:
events部分:定义输入内容,即规则分析的具体检测结果或事件。match部分:指定如何在定义的时间窗口内连接输入。condition部分:包含最终逻辑,用于确定联接的事件是否符合触发提醒的条件。
在 events 部分中定义输入
构建复合检测规则的第一步是在 events 部分中定义规则的输入。复合规则的输入来自集合,其中存储了其他查询生成的检测结果。
Google SecOps 提供以下两种方法来访问集合中的数据。
使用变量或元标签引用检测内容
如需在不引用原始 UDM 事件的情况下访问检测中的数据,您可以使用 outcome 变量、match 变量或 meta 标签。我们建议您采用这种方法,因为它可以提高灵活性,并更好地兼容不同类型的规则。
例如,如果您需要在不同上下文中查找某个字符串(例如网址、文件名或注册表项),则多个规则可以将该字符串存储在通用 outcome 变量中。如需从复合规则访问此字符串,请从 detection 开始,并使用集合资源中的元素找到相关信息。
示例:假设某检测规则生成了以下信息:
结果变量:
dest_domain = "cymbal.com"UDM 字段:
target.hostname = "cymbal.com"
在复合规则中,您可以使用以下路径访问此数据:
detection.detection.outcomes["dest_domain"]来访问dest_domain结果变量。detection.collection_elements.references.event.target.hostname访问target.hostnameUDM 字段。detection.time_window.start_time.seconds可访问检测的开始时间戳。
Collection API 和 SecurityResult API 均可用于访问以下内容:
- 检测元数据和结果值 (
detection.detection) - 引用规则中的基础 UDM 事件 (
collection_elements)
通过规则 ID 或名称引用检测内容
您可以通过规则名称或 ID 引用规则。如果您的检测逻辑依赖于特定规则,并且您希望将分析的数据减少到仅包含这些规则的结果,我们建议您采用此方法。按名称或 ID 引用相关规则可减少分析的数据量,从而提高性能并防止超时。例如,您可以从已知的先前检测结果中直接查询 target.url 或 principal.ip 等字段。
按规则 ID 引用规则(推荐):使用
detection.detection.rule_id字段按 ID 引用规则。您可以在 Google SecOps 中规则的网址中找到规则 ID。用户生成的规则的 ID 格式为ru_UUID,而精选的检测的 ID 格式为ur_UUID。例如:detection.detection.rule_id = "ru_e0d3f371-6832-4d20-b0ad-1f4e234acb2b"按规则名称引用规则:使用
detection.detection.rule_name字段按名称引用规则。您可以指定确切的规则名称,也可以使用正则表达式来匹配该名称。例如:detection.detection.rule_name = "My Rule Name"detection.detection.rule_name = "/PartOfName/"
match 部分中的联接输入源
如需在复合规则中关联相关的检测结果、事件或实体,请使用 events 部分中定义的变量来定义 match 部分。这些变量可以包括规则标签、结果变量、匹配变量、检测字段或集合元素。
如需了解语法,请参阅匹配部分语法。
定义 condition 部分
定义 condition 部分,以评估 match 部分的结果。
如果条件为 true,则会生成提醒。如需了解相关语法,请参阅条件部分语法。
将高级技巧应用于复合规则
本部分介绍如何在构建复合规则时应用高级技巧。
合并事件和检测结果
复合规则可以组合多个数据源,包括 UDM 事件、实体图数据和检测字段。需遵守以下指南:
为每个来源使用不同的变量:为每个数据源(例如,
$e表示事件,$d表示检测结果)分配唯一的事件变量,其中数据源包括事件、实体和检测结果。基于共享上下文联接来源:使用规则条件中的常见值(例如用户 ID、IP 地址或域名)连接数据源。
定义匹配窗口:始终包含一个时间窗口不超过 48 小时的
match子句。
示例:合并事件和检测结果
rule CheckCuratedDetection_with_EDR_and_EG {
meta:
author = "noone@cymbal.com"
events:
$d.detection.detection.rule_name = /SCC: Custom Modules: Configurable Bad Domain/
$d.detection.collection_elements.references.event.network.dns.questions.name = $domain
$d.detection.collection_elements.references.event.principal.asset.hostname = $hostname
$e.metadata.log_type = "LIMACHARLIE_EDR"
$e.metadata.product_event_type = "NETWORK_CONNECTIONS"
$domain = re.capture($e.principal.process.command_line, "\\s([a-zA-Z0-9.-]+\\.[a-zA-Z0-9.-]+)$")
$hostname = re.capture($e.principal.hostname, "([^.]*)")
$prevalence.graph.metadata.entity_type = "DOMAIN_NAME"
$prevalence.graph.metadata.source_type = "DERIVED_CONTEXT"
$prevalence.graph.entity.hostname = $domain
$prevalence.graph.entity.domain.prevalence.day_count = 10
$prevalence.graph.entity.domain.prevalence.rolling_max <= 5
$prevalence.graph.entity.domain.prevalence.rolling_max > 0
match:
$hostname over 1h
outcome:
$risk_score = 80
$CL_target = array($domain)
condition:
$e and $d and $prevalence
}
创建顺序复合检测
顺序复合检测可识别相关事件的模式,其中检测顺序非常重要,例如检测到暴力破解登录尝试,随后又检测到成功登录。这些模式可以组合使用多个基本检测、原始 UDM 事件或同时使用两者。
如需创建顺序复合检测,您必须在规则中强制执行该顺序。如需强制执行预期序列,请使用以下方法之一:
滑动窗口:在
match条件中使用滑动窗口定义检测序列。时间戳比较:比较规则逻辑中的检测时间戳,以验证它们是否按所选顺序发生。
示例:顺序复合检测
events:
$d1.detection.detection.rule_name = "fileEvent_rule"
$userid = $d1.detection.detection.outcomes["user"]
$hostname = $d1.detection.detection.outcomes["hostname"]
$d2.detection.detection.rule_name = "processExecution_rule"
$userid = $d2.detection.detection.outcomes["user"]
$hostname = $d2.detection.detection.outcomes["hostname"]
$d3.detection.detection.rule_name = "networkEvent_rule"
$userid = $d3.detection.detection.outcomes["user"]
$hostname = $d3.detection.detection.outcomes["hostname"]
$d3.detection.collection_elements.references.event.metadata.event_timestamp.seconds > $d2.detection.collection_elements.references.event.metadata.event_timestamp.seconds
match:
$userid over 24h after $d1
需要更多帮助?获得社区成员和 Google SecOps 专业人士的解答。