搜索最佳做法

支持的平台:

本文档介绍了 Google 推荐的在 Google Security Operations 中使用搜索功能的最佳实践。如果搜索查询未经过精心构建,则可能需要大量计算资源。 性能还取决于 Google SecOps 实例中数据的规模和复杂程度。

使用编入索引的 UDM 字段可实现最快速度

提高搜索性能最有效的方法是使用已编入索引的字段构建查询。这些字段经过优化,可实现快速检索。 编入索引的已知统一数据模型 (UDM) 字段如下所示:

主要字段

  • principal.asset.hostname
  • principal.asset.ip
  • principal.asset.mac
  • principal.file.md5
  • principal.file.sha1
  • principal.file.sha256
  • principal.hostname
  • principal.ip
  • principal.mac
  • principal.process.file.md5
  • principal.process.file.sha1
  • principal.process.file.sha256
  • principal.process.parent_process.file.md5
  • principal.process.parent_process.file.sha1
  • principal.process.parent_process.file.sha256
  • principal.user.email_addresses
  • principal.user.product_object_id
  • principal.user.userid
  • principal.user.windows_sids

来源字段

  • source.user.userid
  • src.asset.hostname
  • src.hostname
  • src.ip

目标字段

  • target.asset.hostname
  • target.file.md5
  • target.file.sha1
  • target.file.sha256
  • target.hostname
  • target.ip
  • target.process.file.md5
  • target.process.file.sha1
  • target.process.file.sha256
  • target.user.email_addresses
  • target.user.product_object_id
  • target.user.userid
  • target.user.windows_sid

其他字段

  • about.file.md5
  • about.file.sha1
  • about.file.sha256
  • intermediary.hostname
  • intermediary.ip
  • network.dns.questions.name
  • network.email.from
  • network.email.to
  • observer.hostname
  • observer.ip

构建效果良好的搜索查询以提升效果

编写优化的查询是最大限度地提高速度并最大限度地减少安全数据资源消耗的关键。所有查询条件都必须严格遵循以下基本结构:

udm-field operator value

例如:principal.hostname = "win-server"

由于 Google SecOps 在搜索期间可以注入大量数据,因此您必须尽可能缩小查询的时间范围,以缩小搜索范围并提高搜索性能。

在搜索查询中使用正则表达式

在构建 UDM 搜索查询时,您可以使用标准逻辑运算符和比较运算符来构建复杂的表达式:

  • 逻辑运算符:使用 ANDORNOT 组合条件。如果您省略了两个条件之间的运算符,系统会假定为 AND
  • 运算符优先级:使用英文括号 () 可替换默认的优先级顺序。您可以在括号内使用的逻辑运算符(ORANDNOT)数量上限为 169 个。
  • 比较运算符:根据 UDM 字段类型(字符串、整数、时间戳),字段运算符可以包括:=!=>=><<=

或者,为了高效搜索大量值,您可以使用参考列表

使用 nocase 作为搜索修饰符

您可以将 nocase 修饰符附加到字符串比较条件,使搜索不区分大小写,即忽略大小写。

例如,以下搜索无效:

target.user.userid = "TIM.SMITH" nocase

避免在枚举字段中使用正则表达式

搜索枚举字段(具有一系列预定义值的字段)时,您无法使用正则表达式,例如 metadata.event_typenetwork.ip_protocol

以下示例是一项无效的搜索: metadata.event_type = /NETWORK_*/

而以下示例是有效的搜索:(metadata.event_type = "NETWORK_CONNECTION"metadata.event_type = "NETWORK_DHCP")

在“事件”字段中使用 any 和 all 运算符

Search 中,某些 UDM 字段(例如 principal.iptarget.file.md5)被标记为重复,因为它们可以在单个事件中包含值列表或消息类型。默认情况下,重复字段始终使用 any 运算符处理(没有用于指定 all 的选项)。

使用 any 运算符时,如果重复字段中的任何值满足条件,则谓词的评估结果为 true。例如,如果您搜索 principal.ip != "1.2.3.4",并且搜索结果中的活动同时包含 principal.ip = "1.2.3.4"principal.ip = "5.6.7.8",系统会生成匹配项。这样一来,搜索范围会扩大,包含与任一运算符匹配的结果,而不是仅包含与所有运算符都匹配的结果。

重复字段中的每个元素都是单独处理的。如果在搜索结果中的事件中找到重复字段,系统会针对该字段中的每个元素评估相应事件。这可能会导致意外行为,尤其是在使用 != 运算符进行搜索时。

使用 any 运算符时,如果重复字段中的任何值满足条件,则谓词的评估结果为 true

使用 Unix 纪元时间作为时间戳

系统会使用 Unix 纪元时间(自 1970 年 1 月 1 日星期四 00:00:00 UTC 以来经过的总秒数)来匹配时间戳字段。

搜索特定时间戳时,以下(以纪元时间表示)是有效的时间戳:

metadata.ingested_timestamp.seconds = 1660784400

以下时间戳无效:

metadata.ingested_timestamp = "2022-08-18T01:00:00Z"

从过滤条件中排除字段

以下字段有意排除在搜索过滤条件之外。虽然它们包含关键元数据,但其高度唯一的值可能会引入不必要的搜索细节,从而降低查询引擎的整体效率和效果:

  • metadata.id
  • metadata.product_log_id
  • *.timestamp

需要更多帮助?从社区成员和 Google SecOps 专业人士那里获得解答。