[Mac] 撰寫 Yara 規則,用 Yara 掃瞄含有特定字串的檔案

[Mac] 撰寫 Yara 規則,用 Yara 掃瞄含有特定字串的檔案

今天要測試專案裡用到 Yara 的一個問題,

就順便簡單記錄一下 Yara 的使用吧~

 

假設我想要寫一個 Yara 規則,用它來找出 GoogleUpdate.exe,

因為我事前已經知道 GoogleUpdate.exe 裡,

會有個叫 “GoogleUpdate_unsigned.pdb” 的字串,

因此我可以寫出下面的 Yara 規則檔:

rule MatchGoogleUpdateExe
{
    strings:
        $my_text_string = "GoogleUpdate_unsigned.pdb"

    condition:
        $my_text_string
}

 

這個規則十分簡單,就是如果條件 (condition) 符合時

(也就是檔案裡可以搜尋到指定的字串) ,這條 Yara 規則就算是中了~

(可以參考 Write YARA Rules 寫出更複雜的規則檔)

 

將剛寫好的規則檔儲存成 rule_MatchGoogleUpdateExe.yar

(副檔名應該是沒有規定要 .yar, 只是常見的是用這個副檔名),

接著執行 yara <rule file> <file to scan> 就行了,

如果還沒安裝 Yara 的話,在 Mac 上可以直接用 Homebrew 安裝:

brew install yara

 

例如下面就用 yara 掃瞄當前目錄,

發現 GoogleUpdate.exe 和 GoogleUpdate.tar 都有中 MatchGoogleUpdateExe 這個規則:

testuser@localhost $ yara ../yara/rule_MatchGoogleUpdateExe.yar  .

MatchGoogleUpdateExe ./GoogleUpdate.exe
MatchGoogleUpdateExe ./GoogleUpdate.tar

 

加上 -s 選項的話,還可以看到符合的字串內容:

testuser@localhost $ yara -s ../yara/rule_MatchGoogleUpdateExe.yar  .

MatchGoogleUpdateExe ./GoogleUpdate.tar
0x10748:$my_text_string: GoogleUpdate_unsigned.pdb
MatchGoogleUpdateExe ./GoogleUpdate.exe
0x10548:$my_text_string: GoogleUpdate_unsigned.pdb

 

今天的這個任務其實用 grep 也可以完成,

不過 Yara 規則可以寫得更加複雜,加上各種邏輯組合,就看如何運用囉~^^

(本頁面已被瀏覽過 2,438 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料