【逆向】使用yarGen自動生成yara規則


前言

yarGen是一款yara規則生成器,它可以從惡意軟件中獲取可疑字符串來創建yara規則,同時過濾掉正常的字符串。

下載安裝

yarGen是一個開源項目,源代碼以zip和tar.gz的形式提供,你可以在Github頁面中進行下載。

使用以下命令安裝所有依賴項

sudo pip install scandir lxml naiveBayesClassifier pefile
//如果出現錯誤請嘗試以下命令:
sudo pip install pefile
sudo pip install scandir lxml naiveBayesClassifier

使用以下命令下載內置數據庫,並保存到“./dbs”子文件夾中

python yarGen.py --update

也可以從百度雲下載,下載后解壓到“./dbs”子文件夾中即可

使用示例

安裝完成后可以使用“python yarGen.py -h”命令獲取更多命令行參數信息。

 1 usage: yarGen.py [-h] [-m M] [-y min-size] [-z min-score] [-x high-scoring]
 2                  [-w superrule-overlap] [-s max-size] [-rc maxstrings]
 3                  [--excludegood] [-o output_rule_file] [-e output_dir_strings]
 4                  [-a author] [-r ref] [-l lic] [-p prefix] [-b identifier]
 5                  [--score] [--strings] [--nosimple] [--nomagic] [--nofilesize]
 6                  [-fm FM] [--globalrule] [--nosuper] [--update] [-g G] [-u]
 7                  [-c] [-i I] [--dropzone] [--nr] [--oe] [-fs size-in-MB]
 8                  [--noextras] [--debug] [--trace] [--opcodes] [-n opcode-num]
 9 
10 yarGen
11 
12 optional arguments:
13   -h, --help            show this help message and exit
14 
15 Rule Creation:
16   -m M                  Path to scan for malware
17   -y min-size           Minimum string length to consider (default=8)
18   -z min-score          Minimum score to consider (default=0)
19   -x high-scoring       Score required to set string as 'highly specific
20                         string' (default: 30)
21   -w superrule-overlap  Minimum number of strings that overlap to create a
22                         super rule (default: 5)
23   -s max-size           Maximum length to consider (default=128)
24   -rc maxstrings        Maximum number of strings per rule (default=20,
25                         intelligent filtering will be applied)
26   --excludegood         Force the exclude all goodware strings
27 
28 Rule Output:
29   -o output_rule_file   Output rule file
30   -e output_dir_strings
31                         Output directory for string exports
32   -a author             Author Name
33   -r ref                Reference (can be string or text file)
34   -l lic                License
35   -p prefix             Prefix for the rule description
36   -b identifier         Text file from which the identifier is read (default:
37                         last folder name in the full path, e.g. "myRAT" if -m
38                         points to /mnt/mal/myRAT)
39   --score               Show the string scores as comments in the rules
40   --strings             Show the string scores as comments in the rules
41   --nosimple            Skip simple rule creation for files included in super
42                         rules
43   --nomagic             Don't include the magic header condition statement
44   --nofilesize          Don't include the filesize condition statement
45   -fm FM                Multiplier for the maximum 'filesize' condition value
46                         (default: 3)
47   --globalrule          Create global rules (improved rule set speed)
48   --nosuper             Don't try to create super rules that match against
49                         various files
50 
51 Database Operations:
52   --update              Update the local strings and opcodes dbs from the
53                         online repository
54   -g G                  Path to scan for goodware (dont use the database
55                         shipped with yaraGen)
56   -u                    Update local standard goodware database with a new
57                         analysis result (used with -g)
58   -c                    Create new local goodware database (use with -g and
59                         optionally -i "identifier")
60   -i I                  Specify an identifier for the newly created databases
61                         (good-strings-identifier.db, good-opcodes-
62                         identifier.db)
63 
64 General Options:
65   --dropzone            Dropzone mode - monitors a directory [-m] for new
66                         samples to processWARNING: Processed files will be
67                         deleted!
68   --nr                  Do not recursively scan directories
69   --oe                  Only scan executable extensions EXE, DLL, ASP, JSP,
70                         PHP, BIN, INFECTED
71   -fs size-in-MB        Max file size in MB to analyze (default=10)
72   --noextras            Don't use extras like Imphash or PE header specifics
73   --debug               Debug output
74   --trace               Trace output
75 
76 Other Features:
77   --opcodes             Do use the OpCode feature (use this if not enough high
78                         scoring strings can be found)
79   -n opcode-num         Number of opcodes to add if not enough high scoring
80                         string could be found (default=3)

使用“-m”參數對“vir”文件夾中的樣本自動生成yara規則

//在不使用其它參數的情況下,會在當前目錄下輸出一個名為“yarGen_rules.yar”的規則文件
python yarGen.py -m vir

規則解釋

yarGen會對規則中的每個字符串進行評分,並按得分高低進行分類,每個分類的字符串會以不同的前綴進行區分
以“$s”開頭的字符串,是“高度特定的字符串”,該類字符串不會出現在合法軟件中。
以“$x”開頭的字符串,是“特定的字符串”,該類字符串可能同時在惡意軟件與合法軟件中出現。
以“$z”開頭的字符串,是“普通字符串”,該類字符串可能很常見,但是還沒有被收集加入到合法字符串數據庫中。

總結

關於更多yarGen使用說明,可以查看“-h”參數,或者參考github中作者列出的博客文章,這里不再贅述。
對於yarGen自動生成的yara規則,我們需要在其基礎上根據不同的字符串前綴,結合實際分析情況進行修改完善后,才能將其應用到實際工作中。

參考資料

https://github.com/Neo23x0/yarGen
https://securityonline.info/yargen-generator-yara-rules/
https://medium.com/bugbountywriteup/diving-into-yargen-9e8c00e18b65


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM