在規則中使用情境豐富的資料
為協助安全分析師進行調查,Google Security Operations 會從不同來源擷取情境資料、分析擷取的資料,並提供客戶環境中構件的其他情境資訊。本文提供範例,說明分析師如何在 Detection Engine 規則中使用內容豐富的資料。
如要進一步瞭解資料擴充功能,請參閱「Google SecOps 如何擴充事件和實體資料」。
在規則中使用普遍程度補充欄位
下列範例說明如何在 Detection Engine 中使用與盛行率相關的擴充欄位。如需參考資料,請參閱與盛行率相關的補充欄位清單。
找出使用率偏低的網域存取權
偵測到相符項目時,這項偵測規則會產生偵測事件,而非偵測快訊。主要用途是在調查資產時做為次要指標。舉例來說,有其他嚴重性更高的警示觸發事件。
$enrichment.graph.metadata.entity_type = "FILE"
$enrichment.graph.metadata.product_name = "VirusTotal Relationships"
$enrichment.graph.metadata.vendor_name = "VirusTotal"
如要進一步瞭解如何新增篩選器來提升規則效能,請參閱「新增事件類型篩選器」。
如要瞭解各項擴充類型,請參閱「Google SecOps 如何擴充事件和實體資料」。
在規則中使用普遍程度補充欄位
下列範例說明如何在 Detection Engine 中使用與盛行率相關的擴充欄位。如需參考資料,請參閱與盛行率相關的補充欄位清單。
找出使用率偏低的網域存取權
這項規則可用於偵測對低普及度分數網域的存取行為。如要有效使用這項功能,必須先建立構件的普遍程度分數基準。以下範例使用參照清單調整結果,並套用門檻盛行率值。
rule network_prevalence_low_prevalence_domain_access {
  meta:
    author = "Google Security Operations"
    description = "Detects access to a low prevalence domain. Requires baseline of prevalence be in place for effective deployment."
    severity = "LOW"
  events:
        $e.metadata.event_type = "NETWORK_HTTP"
        $e.principal.ip = $ip
        // filter out URLs with RFC 1918 IP addresses, internal assets
        not re.regex($e.target.hostname, `(127(?:\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$)|(10(?:\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$)|(192\.168(?:\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){2}$)|(172\.(?:1[6-9]|2\d|3[0-1])(?:\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){2})`)
        // used an explicit exclusion reference list
        not $e.target.hostname in %exclusion_network_prevalence_low_prevalence_domain_access
        // only match valid FQDN, filter out background non-routable noise
        re.regex($e.target.hostname, `(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]`)
        $domainName = $e.target.hostname
        //join event ($e) to entity graph ($d)
        $e.target.hostname = $d.graph.entity.domain.name
        $d.graph.metadata.entity_type = "DOMAIN_NAME"
        // tune prevalence as fits your results
        $d.graph.entity.domain.prevalence.rolling_max > 0
        $d.graph.entity.domain.prevalence.rolling_max <= 10
  match:
        $ip over 1h
  outcome:
    $risk_score = max(
        // increment risk score based upon rolling_max prevalence
        if ( $d.graph.entity.domain.prevalence.rolling_max >= 10, 10) +
        if ( $d.graph.entity.domain.prevalence.rolling_max >= 2 and $d.graph.entity.domain.prevalence.rolling_max <= 9 , 20) +
        if ( $d.graph.entity.domain.prevalence.rolling_max = 1, 30)
    )
    $domain_list = array_distinct($domainName)
    $domain_count = count_distinct($domainName)
  condition:
    $e and #d > 10
}
找出與 IOC 相符但使用率偏低的網域
這項偵測規則會產生偵測警示,並提供高準確度的比對結果,比較低普及率網域和已知的 IOC。
rule network_prevalence_uncommon_domain_ioc_match {
  meta:
    author = "Google Security Operations"
    description = "Lookup Network DNS queries against Entity Graph for low prevalence domains with a matching IOC entry."
    severity = "MEDIUM"
  events:
    $e.metadata.event_type = "NETWORK_DNS"
    $e.network.dns.questions.name = $hostname
    //only match FQDNs, such as: exclude chrome dns access tests and other internal hosts
    $e.network.dns.questions.name = /(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]/
    //prevalence entity graph lookup
    $p.graph.metadata.entity_type = "DOMAIN_NAME"
    $p.graph.entity.domain.prevalence.rolling_max > 0
    $p.graph.entity.domain.prevalence.rolling_max <= 3
    $p.graph.entity.domain.name = $hostname
    //ioc entity graph lookup
    $i.graph.metadata.vendor_name = "ET_PRO_IOC"
    $i.graph.metadata.entity_type = "DOMAIN_NAME"
    $i.graph.entity.hostname = $hostname
  match:
    $hostname over 10m
  outcome:
    $risk_score = max(
        //increment risk score based upon rolling_max prevalence
        if ( $p.graph.entity.domain.prevalence.rolling_max = 3, 50) +
        if ( $p.graph.entity.domain.prevalence.rolling_max = 2, 70) +
        if ( $p.graph.entity.domain.prevalence.rolling_max = 1, 90)
    )
  condition:
    $e and $p and $i
}
在規則中使用實體的首次出現時間
您可以編寫包含實體記錄中 first_seen_time 或 last_seen_time 欄位的規則。
first_seen_time 和 last_seen_time 欄位會填入描述網域、IP 位址和檔案 (雜湊) 的實體。如果是描述使用者或資產的實體,系統只會填入 first_seen_time 欄位。如果是描述其他類型 (例如群組或資源) 的實體,系統不會計算這些值。
如需已填入的 UDM 欄位清單,請參閱「計算實體的首次和最後一次出現時間」。
以下範例說明如何在規則中使用 first_seen_time:
rule first_seen_data_exfil {
    meta:
        author = "Google Security Operations"
        description = "Example usage first_seen data"
        severity = "LOW"
    events:
        $first_access.metadata.event_type = "NETWORK_HTTP"
        $ip = $first_access.principal.ip
        // Join first_access event with entity graph to use first/last seen data.
        $ip = $first_last_seen.graph.entity.ip
        $first_last_seen.graph.metadata.entity_type = "IP_ADDRESS"
        // Check that the first_access UDM event is the first_seen occurrence in the enterprise.
        $first_last_seen.graph.entity.artifact.first_seen_time.seconds = $first_access.metadata.event_timestamp.seconds
        $first_last_seen.graph.entity.artifact.first_seen_time.nanos   = $first_access.metadata.event_timestamp.nanos
        // Check for another access event that appears shortly after the first_seen event,
        // where lots of data is being sent.
        $next_access_data_exfil.metadata.event_type = "NETWORK_CONNECTION"
        // Next access event goes to the same IP as the first.
        $next_access_data_exfil.principal.ip = $ip
        // Next access occurs within 60 seconds after first access.
        $next_access_data_exfil.metadata.event_timestamp.seconds > $first_access.metadata.event_timestamp.seconds
        60 > $next_access_data_exfil.metadata.event_timestamp.seconds  - $first_access.metadata.event_timestamp.seconds
        // Lots of data is being sent over the next access event.
        $next_access_data_exfil.network.sent_bytes > 10 * 1024 * 1024 * 1024 // 10GB
        // Extract hostname of next access event, for match section.
        $hostname = $next_access_data_exfil.principal.hostname
    match:
        $hostname over 1h
    condition:
        $first_access and $next_access_data_exfil and $first_last_seen
}
在規則中使用經過地理位置資訊補充的欄位
儲存地理位置強化資料的 UDM 欄位可用於偵測引擎規則。如需已填入的 UDM 欄位清單,請參閱「使用地理位置資料擴充事件」。
以下範例說明如何偵測使用者實體是否從多個不同狀態進行驗證。
rule geoip_user_login_multiple_states_within_1d {
  meta:
    author = "Google Security Operations"
    description = "Detect multiple authentication attempts from multiple distinct locations using geolocation-enriched UDM fields."
    severity = "INFORMATIONAL"
  events:
    $geoip.metadata.event_type = "USER_LOGIN"
    (
      $geoip.metadata.vendor_name = "Google Workspace" or
      $geoip.metadata.vendor_name = "Google Cloud Platform"
    )
    /* optionally, detect distinct locations at a country */
    (
      $geoip.principal.ip_geo_artifact.location.country_or_region != "" and
      $geoip.principal.ip_geo_artifact.location.country_or_region = $country
    )
    (
      $geoip.principal.ip_geo_artifact.location.state != "" and
      $geoip.principal.ip_geo_artifact.location.state = $state
    )
    $geoip.target.user.email_addresses = $user
  match:
    $user over 1d
  condition:
    $geoip and #state > 1
}
在規則中使用安全瀏覽功能擴充欄位
Google SecOps 會從與檔案雜湊相關的威脅清單擷取資料。這類資訊會以實體形式儲存在 Google SecOps 中。
如需已填入的 UDM 欄位清單,請參閱「使用安全瀏覽威脅清單中的資訊擴充實體」。
您可以建立 Detection Engine 規則,找出與從安全瀏覽擷取的實體相符的項目。以下是 Detection Engine 規則範例,會根據這項經過擴充的資訊進行查詢,以建構情境感知分析。
rule safe_browsing_file_execution {
    meta:
        author = "Google Security Operations"
        description = "Example usage of Safe Browsing data, to detect execution of a file that's been deemed malicious"
        severity = "LOW"
    events:
        // find a process launch event, match on hostname
        $execution.metadata.event_type = "PROCESS_LAUNCH"
        $execution.principal.hostname = $hostname
        // join execution event with Safe Browsing graph
        $sb.graph.entity.file.sha256 = $execution.target.process.file.sha256
        // look for files deemed malicious
        $sb.graph.metadata.entity_type = "FILE"
        $sb.graph.metadata.threat.severity = "CRITICAL"
        $sb.graph.metadata.product_name = "Google Safe Browsing"
        $sb.graph.metadata.source_type = "GLOBAL_CONTEXT"
    match:
        $hostname over 1h
    condition:
        $execution and $sb
}
在規則中使用 WHOIS 補充欄位
您可以編寫規則,在代表網域的實體中搜尋 WHOIS 擴充欄位。這些實體的 entity.metadata.entity_type 欄位設為 DOMAIN_NAME。如要查看系統會填入哪些 UDM 欄位,請參閱「使用 WHOIS 資料充實實體」。
以下範例規則說明如何執行這項操作。這項規則包含 events 部分的下列篩選器欄位,有助於提升規則效能。
$whois.graph.metadata.entity_type = "DOMAIN_NAME"
$whois.graph.metadata.product_name = "WHOISXMLAPI Simple Whois"
$whois.graph.metadata.vendor_name = "WHOIS"
rule whois_expired_domain_executable_download {
 meta:
   author = "Google Security Operations"
   description = "Example usage of WHOIS data, detecting an executable file download from a domain that's recently expired"
   severity = "LOW"
 events:
        $access.metadata.event_type = "NETWORK_HTTP"
        $hostname = $access.principal.hostname
        // join access event to entity graph to use WHOIS data
        $whois.graph.entity.domain.name = $access.target.hostname
        // use WHOIS data to look for expired domains
        $whois.graph.metadata.entity_type = "DOMAIN_NAME"
        $whois.graph.metadata.product_name = "WHOISXMLAPI Simple Whois"
        $whois.graph.metadata.vendor_name = "WHOIS"
        $whois.graph.entity.domain.expiration_time.seconds < $access.metadata.event_timestamp.seconds
        // join access event with executable file creation event by principal hostname
        $creation.principal.hostname = $access.principal.hostname
        $creation.metadata.event_type = "FILE_CREATION"
        $creation.target.file.full_path = /exe/ nocase
        // file creation comes after expired domain access
        $creation.metadata.event_timestamp.seconds >
           $access.metadata.event_timestamp.seconds
   match:
       $hostname over 1h
 condition:
        $access and $whois and $creation
}
查詢 Google Cloud 威脅情報資料
Google SecOps 會從 Google Cloud 威脅情報 (GCTI) 資料來源擷取資料,為您提供環境中活動的背景資訊,以利調查。您可以查詢下列資料來源:
- GCTI Tor 結束節點
 - GCTI 良性二進位檔
 - GCTI 遠端存取工具
 
如要瞭解這些威脅動態消息和所有填入的欄位,請參閱「擷取及儲存 Google Cloud 威脅情報資料」。
本文中的預留位置 <variable_name> 代表規則中用於識別 UDM 記錄的不重複變數名稱。
查詢 Tor 結束節點 IP 位址
以下範例規則會在NETWORK_CONNECTION事件包含儲存在 target.ip 欄位中的 IP 位址,且該位址也出現在 GCTI Tor Exit Nodes 資料來源中時,傳回偵測結果。請務必在規則中加入 <variable_name>.graph.metadata.threat.threat_feed_name、<variable_name>.graph.metadata.vendor_name 和 <variable_name>.graph.metadata.product_name 欄位。
這是時間軸資料來源。事件會與當時的資料來源快照相符。
rule gcti_tor_exit_nodes {
  meta:
    author = "Google Cloud Threat Intelligence"
    description = "Alert on known Tor exit nodes."
    severity = "High"
  events:
    // Event
    $e.metadata.event_type = "NETWORK_CONNECTION"
    $e.target.ip = $tor_ip
    // Tor IP search in GCTI Feed
    $tor.graph.entity.artifact.ip = $tor_ip
    $tor.graph.metadata.entity_type = "IP_ADDRESS"
    $tor.graph.metadata.threat.threat_feed_name = "Tor Exit Nodes"
    $tor.graph.metadata.source_type = "GLOBAL_CONTEXT"
    $tor.graph.metadata.vendor_name = "Google Cloud Threat Intelligence"
    $tor.graph.metadata.product_name = "GCTI Feed"
  match:
    $tor_ip over 1h
  outcome:
    $tor_ips = array_distinct($tor_ip)
    $tor_geoip_country = array_distinct($e.target.ip_geo_artifact.location.country_or_region)
    $tor_geoip_state = array_distinct($e.target.ip_geo_artifact.location.state)
  condition:
    $e and $tor
}
查詢良性作業系統檔案
以下範例規則會結合 Benign Binaries 和 Tor Exit Nodes 資料來源,在良性二進位檔連線至 Tor 結束節點時傳回快訊。這項規則會使用 Google SecOps 透過目標 IP 位址擴增的地理位置資料,計算風險分數。請務必在規則中,為 Benign Binaries 和 Tor Exit Nodes 資料來源加入 <variable_name>.graph.metadata.vendor_name、<variable_name>.graph.metadata.product_name 和 <variable_name>.graph.metadata.threat.threat_feed_name。
這是無時間限制的資料來源。無論時間為何,事件一律會與資料來源的最新快照相符。
rule gcti_benign_binaries_contacts_tor_exit_node {
 meta:
   author = "Google Cloud Threat Intelligence"
   description = "Alert on Benign Binary contacting a Tor IP address."
   severity = "High"
 events:
   // Event
   $e.metadata.event_type = "NETWORK_CONNECTION"
   $e.principal.process.file.sha256 = $benign_hash
   $e.target.ip = $ip
   $e.principal.hostname = $hostname
   // Benign File search in GCTI Feed
   $benign.graph.entity.file.sha256 = $benign_hash
   $benign.graph.metadata.entity_type = "FILE"
   $benign.graph.metadata.threat.threat_feed_name = "Benign Binaries"
   $benign.graph.metadata.source_type = "GLOBAL_CONTEXT"
   $benign.graph.metadata.vendor_name = "Google Cloud Threat Intelligence"
   $benign.graph.metadata.product_name = "GCTI Feed"
   // Tor IP search in GCTI Feed
   $tor.graph.entity.artifact.ip = $ip
   $tor.graph.metadata.entity_type = "IP_ADDRESS"
   $tor.graph.metadata.threat.threat_feed_name = "Tor Exit Nodes"
   $tor.graph.metadata.source_type = "GLOBAL_CONTEXT"
   $tor.graph.metadata.vendor_name = "Google Cloud Threat Intelligence"
   $tor.graph.metadata.product_name = "GCTI Feed"
 match:
   $hostname over 1h
 outcome:
   $risk_score = max(
       if($tor.graph.metadata.threat.confidence = "HIGH_CONFIDENCE", 70) +
       // Unauthorized target geographies
       if($e.target.ip_geo_artifact.location.country_or_region = "Cuba", 20) +
       if($e.target.ip_geo_artifact.location.country_or_region = "Iran", 20) +
       if($e.target.ip_geo_artifact.location.country_or_region = "North Korea", 20) +
       if($e.target.ip_geo_artifact.location.country_or_region = "Russia", 20) +
       if($e.target.ip_geo_artifact.location.country_or_region = "Syria", 20)
   )
   $benign_hashes = array_distinct($benign_hash)
   $benign_files = array_distinct($e.principal.process.file.full_path)
   $tor_ips = array_distinct($ip)
   $tor_geoip_country = array_distinct($e.target.ip_geo_artifact.location.country_or_region)
   $tor_geoip_state = array_distinct($e.target.ip_geo_artifact.location.state)
 condition:
   $e and $benign and $tor
}
查詢遠端存取工具的資料
以下範例規則會在 PROCESS_LAUNCH 事件類型包含的雜湊也出現在「威脅情報遠端存取工具」 Google Cloud 資料來源中時,傳回偵測結果。
這是無時間限制的資料來源。無論時間為何,事件一律會與資料來源的最新快照相符。
rule gcti_remote_access_tools {
 meta:
   author = "Google Cloud Threat Intelligence"
   description = "Alert on Remote Access Tools."
   severity = "High"
 events:
    // find a process launch event
    $e.metadata.event_type = "PROCESS_LAUNCH"
    $e.target.process.file.sha256 != ""
    $rat_hash = $e.target.process.file.sha256
    // join graph and event hashes
    $gcti.graph.entity.file.sha256 = $rat_hash
    // look for files identified as likely remote access tools
    $gcti.graph.metadata.entity_type = "FILE"
    $gcti.graph.metadata.vendor_name = "Google Cloud Threat Intelligence"
    $gcti.graph.metadata.product_name = "GCTI Feed"
    $gcti.graph.metadata.threat.threat_feed_name = "Remote Access Tools"
  match:
    $rat_hash over 5m
 outcome:
   $remote_hash = array_distinct($e.target.process.file.sha256)
  condition:
    $e and $gcti
}
在規則中使用 VirusTotal 充實中繼資料欄位
下列規則會偵測特定檔案類型的檔案建立或程序啟動作業,指出系統中存在某些監控清單中的雜湊值。當檔案使用 VirusTotal 檔案中繼資料擴充功能標記為 exploit 時,系統會設定風險分數。
如要查看所有已填入的 UDM 欄位清單,請參閱「使用 VirusTotal 檔案中繼資料擴充事件」。
rule vt_filemetadata_hash_match_ioc {
 meta:
   author = "Google Cloud Threat Intelligence"
   description = "Detect file/process events that indicate watchlisted hashes are on a system"
   severity = "High"
 events:
   // Process launch or file creation events
   $process.metadata.event_type = "PROCESS_LAUNCH" or $process.metadata.event_type ="FILE_CREATION"
   $process.principal.hostname = $hostname
   $process.target.file.sha256 != ""
   $process.target.file.sha256 = $sha256
   $process.target.file.file_type = "FILE_TYPE_DOCX"
   // IOC matching
   $ioc.graph.metadata.product_name = "MISP"
   $ioc.graph.metadata.entity_type = "FILE"
   $ioc.graph.metadata.source_type = "ENTITY_CONTEXT"
   $ioc.graph.entity.file.sha256 = $sha256
 match:
   $hostname over 15m
 outcome:
   $risk_score = max(
       // Tag enrichment from VirusTotal file metadata
       if($process.target.file.tags = "exploit", 90)
   )
   $file_sha256 = array($process.target.file.sha256)
   $host = array($process.principal.hostname)
 condition:
   $process and $ioc
}
在規則中使用 VirusTotal 關係資料
Google SecOps 會從 VirusTotal 相關連線擷取資料。這項資料提供檔案雜湊值與檔案、網域、IP 位址和網址之間的關係資訊。這些豐富的資訊會以實體形式儲存在 Google SecOps 中。
您可以建立 Detection Engine 規則,找出與從 VirusTotal 擷取的實體相符的項目。下列規則會在從已知 IP 位址下載已知檔案雜湊時,透過 VirusTotal 關係傳送快訊。風險評分依據是檔案類型,以及 VirusTotal 檔案中繼資料中的標記。
這項資料僅適用於特定 VirusTotal 和 Google SecOps 授權。請與客戶經理聯絡,確認您的權利。如要查看所有已填入的 UDM 欄位清單,請參閱「使用 VirusTotal 關係資料擴充實體」。
rule virustotal_file_downloaded_from_url {
  meta:
    author = "Google Cloud Threat Intelligence"
    description = "Alerts on downloading a known file hash from a known IP with VirusTotal relationships. The risk score is based on file type and tags from VirusTotal file metadata."
    severity = "High"
  events:
    // Filter network HTTP events
    $e1.metadata.event_type = "NETWORK_HTTP"
    $e1.principal.user.userid = $userid
    $e1.target.url = $url
    // Filter file creation events
    $e2.metadata.event_type = "FILE_CREATION"
    $e2.target.user.userid = $userid
    $e2.target.file.sha256 = $file_hash
    // The file creation event timestamp should be equal or greater than the network http event timestamp
    $e1.metadata.event_timestamp.seconds <= $e2.metadata.event_timestamp.seconds
    // Join event file hash with VirusTotal relationships entity graph
    $vt.graph.metadata.entity_type = "FILE"
    $vt.graph.metadata.source_type = "GLOBAL_CONTEXT"
    $vt.graph.metadata.vendor_name = "VirusTotal"
    $vt.graph.metadata.product_name = "VirusTotal Relationships"
    $vt.graph.entity.file.sha256 = $file_hash
    // Join network HTTP target URL with VirusTotal relationships entity graph
    $vt.graph.relations.entity_type = "URL"
    $vt.graph.relations.relationship = "DOWNLOADED_FROM"
    $vt.graph.relations.entity.url = $url
  match:
    $userid over 1m
  outcome:
      $risk_score = max(
        // Tag enrichment from VirusTotal file metadata
        if($e2.target.file.tags = "via-tor" or $e2.target.file.tags = "malware" or $e2.target.file.tags = "crypto", 50) +
        // File types enrichment from VirusTotal file metadata
        if($e2.target.file.file_type = "FILE_TYPE_HTML", 5) +
        if($e2.target.file.file_type = "FILE_TYPE_ELF", 10) +
        if($e2.target.file.file_type = "FILE_TYPE_PE_DLL",15) +
        if($e2.target.file.file_type = "FILE_TYPE_PE_EXE", 20)
    )
  condition:
    $e1 and $e2 and $vt and $risk_score >= 50
}
最終一致性
這類規則需要先處理額外資料,才能完成評估。一段時間後,系統會完成擴充程序,並使用最新的準確資料重新評估規則。這種最終一致性是預期會發生的情況,代表雖然一開始可能會有不一致的情況,但系統會確保所有事件最終都會完全經過擴充,且規則會準確評估。瞭解 Google SecOps 如何擴充事件和實體資料。
後續步驟
如要瞭解如何將強化資料與其他 Google SecOps 功能搭配使用,請參閱下列文章:
還有其他問題嗎?向社群成員和 Google SecOps 專業人員尋求答案。