使用 YARA-L 2.0 的 UDM 搜尋和資訊主頁條件
「condition
」部分會定義將資料納入搜尋結果的條件。
系統會根據 events
區段中定義的事件和預留位置變數,評估這些條件。您可以使用 and
關鍵字合併這些條件。
限制
搜尋條件有下列限制:
必要:「
match
」部分為必填欄位。或者,您也可以直接在events
區段中定義未分組的篩選條件。必要:事件和預留位置變數必須在
condition
區段中彙整。系統僅支援整數和浮點數比較運算式。這些運算式左側必須有變數,右側則必須有整數或浮點數 (例如
#c > 1
、$port = 80
)。支援的運算子為<
、>
和=
。condition
區段中的變數和子句順序不會影響結果。如要在
condition
區段中使用結果變數,請定義並匯總這些變數。 您可以在「events
」部分篩選未匯總的結果變數。系統不支援直接對變數執行數學運算 (例如
#e1 + 5 > 6
、$o1.sum($pl) > 0
)。如果
OR
條件適用於相同的基礎事件,則不會有額外限制。在不同事件中使用OR
時,適用下列限制:OR
不支援不存在比較。舉例來說,系統不支援math.log($outcome1_sent_bytes) > 5 OR (#placeholder2) < 10
。如果
OR
子句涵蓋不同事件,則不支援非 UDM 變數。不過,OR
支援單一事件背景資訊,或與AND
分組。例如:$entity and ($udm_event_1 or $placeholder_derived_from_udm_event_1)
。以下是另一個範例:$entity and ($udm_event_1 or $outcome_udm_event_1_bytes > 1000)
。
計算字元數 (#
)
如果事件或預留位置變數名稱前面有 #
字元 (例如 #c
),則代表該事件的相異發生次數,或是滿足與該變數相關聯的 events
區段中所有條件的相異值數量。舉例來說,#c > 1
表示事件或預留位置 c
必須出現多次。
查詢範例:
$e1.principal.hostname = $hostname
$e1.target.hostname = "fedex.com"
$e1.target.port = 3042 // tcp/udp
$e2.principal.hostname = $hostname
$e2.target.hostname = "homedepot.com"
$e2.target.port = 3042 // tcp/udp
match:
$hostname over 1h
condition:
#e1 > 0 or #e2 > 1
值字元 ($
)
$
字元的函式取決於內容。
結果變數:放在結果變數名稱 (例如
$risk_score
) 前時,代表變數的值。事件或預留位置變數:放在事件或預留位置變數名稱 (例如
$event
) 前時,等同於#event > 0
,表示該事件至少須發生一次。
活動和預留位置條件
您可以使用 and
關鍵字,為事件和預留位置變數結合多個條件述詞。
or
用法範例 (單一事件):
condition:
$ph2 and $ph3
重要事項:在 events
或 condition
區段中編寫邏輯時,請使用 !
表示否定。請只在 outcome
區段中使用 not
關鍵字。
有界和無界條件
事件變數條件可以有界限或無界限。
有界條件必須有相關聯的事件變數。也就是說,任何偵測結果都必須至少出現一次事件。
範例:
$var
(等同於#var > 0
)#var > n
(其中n >= 0
)#var >= m
(其中m > 0
)
查詢範例:
$e1.principal.hostname = $hostname
$e1.target.hostname = "fedex.com"
match:
$hostname over 1h
condition:
#e1 > 0
無界限條件允許相關聯的事件變數不存在。 也就是說,偵測結果中可能不會顯示任何事件發生次數。 對事件變數中的欄位進行任何參照,都會產生零值。使用這些 進行不存在的搜尋。
範例:
!$var
(等同於#var = 0
)#var >= 0
#var < n
(其中n > 0
)#var <= m
(其中m >= 0
)
查詢範例:
$e1.principal.hostname = $hostname
$e1.target.hostname = "fedex.com"
$e1.target.port = 3042 // tcp/udp
match:
$hostname over 1h
outcome:
$bytes_sent = sum($e1.network.sent_bytes)
condition:
$bytes_sent >= 0
注意:對於不存在的搜尋查詢 (使用無界限條件),偵測引擎會將預期延遲時間延後 1 小時。
無界限條件的搜尋查詢必須符合下列條件:
至少要有一個 UDM 事件設有界限條件,也就是至少要有一個 UDM 事件。
具有無界限條件的預留位置必須與至少一個有界限的 UDM 事件建立關聯。
具有無界條件的實體必須與至少一個有界 UDM 事件建立關聯。
結果條件
您可以使用結果變數定義結果條件,並搭配邏輯運算子 (and
、or
、not
)。比較語法取決於結果變數的資料類型。
- 整數和浮點數:使用
=
、>
、>=
、<
、<=
、!=
(例如$risk_score > 10
、$risk_score <= 5.5
)。 - 字串:使用
=
或!=
(例如$severity = "HIGH"
)。 - 整數或陣列清單:使用
arrays.contains()
(例如arrays.contains($event_ids, "id_1234")
)。
查詢範例:
$e1.principal.hostname = $hostname
$e1.target.hostname = "fedex.com"
$e1.target.port = 3042 // tcp/udp
match:
$hostname over 1h
outcome:
$bytes_sent = sum($e1.network.sent_bytes)
condition:
$e1
UDM 搜尋中的 X 個條件有 N 個符合
UDM 搜尋條件支援「N of X」語法,可彈性評估多項條件。這個語法可讓您指定條件是否成立,只要N
(特定數字) 的 X
(布林運算式清單) 評估結果為 true,條件即成立。
範例:假設您想從 VirusTotal (VT) 擴充功能提供的預先定義標記清單中,找出顯示多種可疑行為 (但不一定全部) 的程序。「N of X」語法可讓您指定必須符合的條件數量下限,藉此解決這個問題。
下列 UDM 搜尋查詢會尋找至少符合三項條件的程序:
$e.metadata.event_type = "PROCESS_LAUNCH"
$e.target.process.file.full_path = $process
match:
$process
outcome:
$first_seen = earliest($e.metadata.event_timestamp)
$last_seen = latest($e.metadata.event_timestamp)
$total_events = count($e.metadata.id)
// Collect all unique tags associated with this process from all its launch events
$tags = array_distinct($e.target.process.file.tags)
condition:
// Trigger if at least 3 of the following conditions (tag checks) are true
3 of [
arrays.contains($tags, "malware"),
arrays.contains($tags, "detect-debug-environment"),
arrays.contains($tags, "checks-disk-space"),
arrays.contains($tags, "checks-cpu-name"),
arrays.contains($tags, "invalid-signature"),
arrays.contains($tags, "self-delete")
]
order:
$total_events desc
ANY 和 ALL 運算子
如果列出的布林運算式中至少有一個為 true
,則 ANY of [expressions]
的計算結果為 true
。ALL of [expressions]
要求列出的每個運算式都必須是 true
。使用 AND
等關鍵字,將這些運算子與其他條件合併。
範例:
$e.metadata.event_type = "PROCESS_LAUNCH"
$e.target.process.file.full_path = $process
match:
$process
outcome:
$first_seen = timestamp.get_timestamp(min($e.metadata.event_timestamp.seconds))
$last_seen = timestamp.get_timestamp(max($e.metadata.event_timestamp.seconds))
$total = count($e.metadata.id)
$tags = array_distinct($e.target.process.file.tags)
$vt_first_seen_time = max(if((timestamp.current_seconds() - $e.target.process.file.first_seen_time.seconds) < 86400, 1 , 0))
$vt_last_analysis_time = max(if((timestamp.current_seconds() - $e.target.process.file.last_analysis_time.seconds) < 86400, 1 , 0))
$vt_last_modification_time = max(if((timestamp.current_seconds() - $e.target.process.file.last_modification_time.seconds) < 86400, 1 , 0))
$vt_last_seen_time = max(if((timestamp.current_seconds() - $e.target.process.file.last_seen_time.seconds) < 86400, 1 , 0))
condition:
3 of [
arrays.contains($tags, "malware"),
arrays.contains($tags, "detect-debug-environment"),
arrays.contains($tags, "checks-disk-space"),
arrays.contains($tags, "checks-cpu-name"),
arrays.contains($tags, "invalid-signature"),
arrays.contains($tags, "self-delete")
]
and ANY of [
$vt_first_seen_time = 1,
$vt_last_analysis_time = 1,
$vt_last_modification_time = 1,
$vt_last_seen_time = 1
]
order:
$total desc
unselect:
$vt_first_seen_time,
$vt_last_analysis_time,
$vt_last_modification_time,
$vt_last_seen_time
還有其他問題嗎?向社群成員和 Google SecOps 專業人員尋求答案。