搭配事件變數使用 N OF 語法
支援的國家/地區:
Google SecOps
SIEM
本文說明如何使用 N OF 語法,在查詢的 condition 區段中編寫彈性條件邏輯。
您可以使用 N OF 語法組合多個條件,降低查詢語法的整體複雜度:
- 可指定特定清單中至少要有幾個布林運算式評估為 true。
- 避免指定所有可能的組合,減少錯誤和工作量。
N OF 語法
N OF 陳述式的語法是以半形逗號分隔的布林運算式清單,表示方式如下:
[expr1, expr2, … , exprN] (其中 [expr1, expr2, … , exprN])
以下各節將說明 N OF 語法的一些變化。
下列任一項
下列範例會檢查清單中是否至少有一個運算式為 true。
這與使用 or 聯結所有運算式相同。
condition:
ANY OF [$e1, #e2 > 5, $outcome1 = "FAILED"]
所有
如果下列清單中的所有運算式都成立,則範例成立。這與使用 and 聯結所有運算式相同。
condition:
ALL OF [$e1, $e2, $outcome1 = "SUCCESS"]
X 的 N 次方根
如果清單中至少有 N 個運算式為 true,則評估結果為 true。
condition:
2 of [$e1, $e2 > 0, $e3, arrays.contains($outcome_ips, "1.2.3.4")]
規則範例:標示機密檔案存取權
如果使用者成功登入 ($e1),下列規則會標記該使用者。接著,規則會檢查工作階段是否也符合下列其中一項條件:存取機密檔案 ($e2),或存取的機密檔案總數超過 3。
rule MultiEventNOf {
meta:
author = "google-secops"
description = "Detects user login followed by sensitive file access or multiple sensitive files."
events:
$e1.principal.user.userid = $user
$e1.metadata.event_type = "USER_LOGIN"
$e2.principal.user.userid = $user
$e2.metadata.event_type = "FILE_OPEN"
re.regex($e2.target.file.full_path, `^/cns/sensitive/`)
match:
$user over 1h
outcome:
$sensitive_file_count = count_distinct($e2.target.file.full_path)
condition:
$e1 and ANY OF [$e2, $sensitive_file_count > 3]
}
搜尋範例:標記敏感檔案存取權
以下範例說明如何將範例規則重新格式化為搜尋查詢。
$e1.principal.user.userid = $user
$e1.metadata.event_type = "USER_LOGIN"
$e2.principal.user.userid = $user
$e2.metadata.event_type = "FILE_OPEN"
re.regex($e2.target.file.full_path, `^/cns/sensitive/`)
match:
$user over 1h
outcome:
$sensitive_file_count = count_distinct($e2.target.file.full_path)
condition:
$e1 and ANY OF [$e2, $sensitive_file_count > 3]
已知限制
必要事件存在:運算式 N OF 語法無法不受限制。子句必須存在事件,才能為 true (例如
$e1或#e1 > 0)。變數類型混用:您無法在同一個 N OF 清單中,將非 UDM 變數與 UDM 事件變數合併。
視窗限制:您無法搭配 N OF 語法使用滾動視窗。
後續步驟
還有其他問題嗎?向社群成員和 Google SecOps 專業人員尋求答案。