複合偵測規則

支援的國家/地區:

在 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.hostname UDM 欄位。

  • detection.time_window.start_time.seconds 即可查看偵測開始時間戳記。

Collection API 和 SecurityResult API 可存取下列兩項:

  • 偵測中繼資料和結果值 (detection.detection)
  • 參照規則的基礎 UDM 事件 (collection_elements)

依規則 ID 或名稱參照偵測內容

您可以依規則名稱或 ID 參照規則。如果偵測邏輯取決於特定規則,且您希望只分析這些規則的結果,建議採用這種做法。依名稱或 ID 參照相關規則,可減少分析的資料量,進而提升效能並避免逾時。舉例來說,您可以直接從已知的先前偵測結果查詢 target.urlprincipal.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 位址或網域名稱等通用值,連結資料來源。

  • 定義比對時間範圍:請務必加入 match 子句,且時間範圍不得超過 48 小時。

範例:合併事件和偵測結果

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 專業人員尋求答案。