「Events」區段語法
規則中的 events 區段必須緊接在 meta 區段之後。這項規則會定義查詢應檢查的事件,以及這些事件必須具備哪些特定屬性,才能視為與潛在偵測結果相關。
規則必須包含 events 區段,但搜尋和資訊主頁則為選填。
使用 events 區段列出指定下列項目的述詞:
- 變數宣告
- 事件變數篩選器
- 事件變數聯結
「定義事件」專區
如果規則和查詢只著重於一種事件類型,可以包含單一事件變數,例如:
events:
$e.metadata.event_type = "USER_LOGIN" // 'e' is the common convention for a single event
如果規則和查詢需要兩個或多個不同類型事件之間的關聯性 (例如使用者登入後修改檔案),則每種事件類型都需要一個變數:
events:
$login.metadata.event_type = "USER_LOGIN" // Event 1: User Login
$file_op.metadata.event_type = "FILE_MODIFICATION" // Event 2: File Modification
宣告事件變數後,您可以使用該變數做為前置字元,存取該事件類型中的特定欄位。舉例來說,以下 event 區段會篩選 Okta 登入失敗事件:
events:
$e.metadata.vendor_name = "Okta"
$e.metadata.event_type = "USER_LOGIN"
$e.security_result.action = "FAIL"
變數宣告
如要宣告變數,請使用下列語法:
<EVENT_FIELD> = <VAR><VAR> = <EVENT_FIELD>
兩者效果相同,如下列範例所示:
$e.source.hostname = $hostname$userid = $e.principal.user.userid
這項宣告表示這個變數代表事件變數的指定欄位。如果事件欄位是重複欄位,match 變數可以代表陣列中的任何值。您也可以將多個事件欄位指派給單一比對或預留位置變數。這稱為遞移聯結條件。
例如:
$e1.source.ip = $ip$e2.target.ip = $ip
等同於:
$e1.source.ip = $ip$e1.source.ip = $e2.target.ip
使用變數時,必須透過變數宣告來宣告變數。如果使用變數但未宣告,就會觸發編譯錯誤。
如要進一步瞭解變數,請參閱「運算式、運算子和其他建構」。
事件變數篩選器
對單一事件變數執行的布林運算式會視為篩選器。
事件變數聯結
規則中使用的所有事件變數都必須與其他事件變數合併,合併方式如下:
直接透過兩個已聯結事件變數的事件欄位進行相等比較,例如:
$e1.field = $e2.field。運算式不得包含算術運算 (例如 $\text{+, -, *, /}$)。透過只涉及事件欄位的遞移聯結間接聯結 (如需「遞移聯結」的定義,請參閱變數宣告)。運算式不得包含算術。
舉例來說,假設規則中使用了 $e1、$e2 和 $e3,則下列 events 區段有效:
events:
$e1.principal.hostname = $e2.src.hostname // $e1 joins with $e2
$e2.principal.ip = $e3.src.ip // $e2 joins with $e3
events:
// $e1 joins with $e2 using function to event comparison
re.capture($e1.src.hostname, ".*") = $e2.target.hostname
events:
// $e1 joins with $e2 using an `or` expression
$e1.principal.hostname = $e2.src.hostname
or $e1.principal.hostname = $e2.target.hostname
or $e1.principal.hostname = $e2.principal.hostname
events:
// all of $e1, $e2 and $e3 are transitively joined using the placeholder variable $ip
$e1.src.ip = $ip
$e2.target.ip = $ip
$e3.about.ip = $ip
events:
// $e1 and $e2 are transitively joined using function to event comparison
re.capture($e2.principal.application, ".*") = $app
$e1.principal.hostname = $app
不過,以下範例顯示無效的 events 區段。
events:
// Event to arithmetic comparison is an invalid join condition for $e1 and $e2.
$e1.principal.port = $e2.src.port + 1
events:
$e1.src.ip = $ip
$e2.target.ip = $ip
$e3.about.ip = "192.1.2.0" //$e3 is not joined with $e1 or $e2.
events:
$e1.src.port = $port
// Arithmetic to placeholder comparison is an invalid transitive join condition.
$e2.principal.port + 800 = $port
後續步驟
其他資訊
還有其他問題嗎?向社群成員和 Google SecOps 專業人員尋求答案。