113-1 師大資工「高等資安攻防演練」- 企業如何偵測並應對網路攻擊 Detection Engineering 輔助教材

總課程資訊

https://sites.google.com/gapps.ntnu.edu.tw/neokent/teaching/2024fall-information-security-industry-cooperation?authuser=0

課程主題

企業如何偵測並應對網路攻擊 Detection Engineering (此網頁只包含該主題的線上輔助教材)

課程介紹

隨著企業面臨的網路威脅日益複雜與多樣化,如何快速偵測並應對網路攻擊已成為現代企業資訊安全防護的核心挑戰。本課程在培養學生偵測工程 (Detection Engineering) 能力,結合惡意程式分析、機器學習技術,以及規則建模(如 YARA 與 Sigma Rules),打造高效的威脅偵測與應變系統。

上課時間

2024/11/22 14:20-16:20

講師資訊

課堂教材

有期限下載~~

實驗程式碼 https://github.com/stwater20/NTNU-AIS-YARA-Course

課堂簡報 https://dropover.cloud/7cbda2

期末簡報 https://dropover.cloud/f8c711

作業繳交格式

輔助教材

YARA Rule Cheet Sheet

1. 基本規則結構

rule <rule_name> {
meta:
<meta_key> = "<meta_value>"
strings:
$<name> = "<string>"
condition:
<logical_expression>
}

2. Meta Section

  • 用於描述規則的附加資訊,無影響規則執行的功能。
  • 常見格式:
meta: 
  description = "Description of the rule" 
  author = "Your Name" 
  date = "YYYY-MM-DD" 
  version = "1.0"

3. Strings Section(字串部分)

支援三種類型的字串:

  • Text String: 直接定義字符串。
strings: 
    $text1 = "malware" 
    $text2 = "example"
  • Hexadecimal String: 定義16進位模式。
strings: 
    strings: $hex1 = { E2 34 ?? 56 [4-6] 78 }
  • Regular Expression: 定義正則表達式。
strings: 
    $regex1 = /malware[0-9]+/

4. 修飾符

修飾符功能
xor對字串進行 XOR 解密匹配
fullword僅匹配完整字詞
ascii僅匹配 ASCII 字串
wide匹配寬字節(Unicode)
nocase忽略大小寫
strings:
    $s1 = "malware" nocase wide fullword

5. Conditions Section(條件部分)

定義規則匹配的邏輯表達式。

運算符/關鍵字描述
and邏輯與
or邏輯或
not邏輯非
any of任意匹配一個字串
all of所有字串均需匹配
#匹配的字串數量
for用於迴圈檢測邏輯
condition:
    $s1 and ($s2 or $s3)

6. 字串數量條件

可以基於匹配字串的數量進行條件判斷:

condition:
    #strings >= 2

7. 範圍匹配

定義條件範圍:

condition:
    for any i in (1..10): ($a[i] matches /abc/)

8. 文件屬性檢測

關鍵字描述
filesize文件大小
entrypoint可執行文件的入口點地址
pe用於檢測 PE 文件結構
condition:
    filesize < 1MB and entrypoint == 0x1000

9. 組合範例

以下是檢測惡意軟體樣本的規則範例:

rule ExampleRule {
    meta:
        description = "Detect malware samples"
        author = "Your Name"
        version = "1.0"
    strings:
        $str1 = "malware" nocase
        $str2 = { 4D 5A 90 00 }
        $str3 = /http[s]?:\/\/[a-zA-Z0-9\-\.]+/
    condition:
        filesize < 1MB and any of ($str1, $str2, $str3)
}

10. 使用方法

運行 YARA 規則

yara -r <rule_file.yar> <directory_or_file>

指定輸出

yara -r -f <rule_file.yar> <directory_or_file>