使用嵌套 if 语句实现更复杂的逻辑
支持的国家/地区:
Unified SecOps
SIEM
您可以在 outcome 和 events 部分中使用 if 语句。您还可以在另一个 if 语句的 then else 子句中使用 if 语句。借助此功能,您可以在查询中引入更复杂的逻辑。
规则、搜索和信息中心均支持此语法。
语法
if(BOOL_CLAUSE, THEN_CLAUSE, ELSE_CLAUSE)
嵌套 if 示例
搜索示例:结果部分
此示例根据 principal.hostname 分配结果得分。
$nested_if.principal.hostname != ""
outcome:
$score = max(
if($nested_if.principal.hostname = /win-adfs/,
5,
if($nested_if.principal.hostname = /server/,
3,
if($nested_if.principal.hostname = /win-atomic/,
1,
0))))
搜索示例:活动部分
此示例将占位符 IP 分配给 target.ip 或 principal.ip,只要它们不为空。如果缺少 IP 值,则会分配 no_valid_ip。
events:
$e.metadata.event_type = "NETWORK_CONNECTION"
$ip = if($e.target.ip != "",
$e.target.ip,
if($e.principal.ip != "",
$e.principal.ip,
"no_valid_ip"))
match:
$ip
规则示例:outcome 部分中嵌套的 if
rule nested_if_outcome_example {
meta:
events:
$e.metadata.event_type = "NETWORK_CONNECTION"
$e.principal.ip = $ip
match:
$ip over 5m
outcome:
$score = max(
if($e.principal.hostname = /win-adfs/,
5,
if($e.principal.hostname = /server/,
3,
if($e.principal.hostname = /win-atomic/,
1,
0))))
condition:
$e
}
规则示例:events 部分中嵌套的 if
rule nested_if_events_example {
meta:
events:
$e.metadata.event_type = "NETWORK_CONNECTION"
$ip = if($e.target.ip != "",
$e.target.ip,
if($e.principal.ip != "",
$e.principal.ip,
"no_valid_ip"))
match:
$ip over 5m
condition:
$e
}
已知限制
if() 语句是 YARA-L 2.0 中的一个函数,受函数深度限制(20)的约束。