Uchihash 是一款小工具,可帮助恶意软件分析师节省处理各种嵌入式哈希值的时间,这些哈希值用于多种用途,例如:
$ git clone https://github.com/N1ght-W0lf/Uchihash.git
$ pip install -r requirements.txt
usage: uchihash.py [-h] [--algo ALGO] [--apis] [--keywords] [--list LIST] [--script SCRIPT] [--search SEARCH]
[--hashes HASHES] [--idaidc] [--idapython]
options:
-h, --help show this help message and exit
--algo ALGO Hashing algorithm
--apis Calculate hashes of APIs
--keywords Calculate hashes of keywords
--list LIST Calculate hashes of your own word list
--script SCRIPT Script file containing your custom hashing algorithm
--search SEARCH Search a JSON File containing hashes mapped to words
--hashes HASHES File containing list of hashes to search for
--idaidc Generate an IDC script to annotate hash values in IDA Pro
--idapython Generate an IDAPython script to annotate hash values in IDA Pro
--ghidra Generate a python script to annotate hash values in Ghidra
Examples:
* python uchihash.py --algo crc32 --apis
* python uchihash.py --algo murmur3 --list mywords.txt
* python uchihash.py --script myalgo.py --apis --idapython
* python uchihash.py --search hashmap.txt --hashes myhashes.txt
--algo:可选哈希算法之一
--apis:对大量 Windows API 列表进行哈希计算(参见 data/apis_list.txt)
--keywords:对恶意软件家族常用的关键字列表进行哈希计算,例如分析工具和 VM/反病毒/EDR 的产品标识(参见 data/keywords_list.txt)
--list:单词以换行符分隔(参见 examples/mywords.txt)
--script:哈希函数必须命名为 hashme,并接受一个参数,该参数是表示要计算哈希值的字节字符串,返回值必须为十六进制格式(参见 examples/custom_algo.txt)
--search:要搜索的文件必须为 JSON 格式(参见 examples/searchme.txt)
--hashes:哈希值以换行符分隔,且必须为十六进制格式(参见 examples/myhashes.txt)
更多详情请查看 examples 文件夹
我们以一个真实的恶意软件家族为例,这里使用的是 BuerLoader,它使用哈希值来动态导入 API,并且使用了自定义哈希算法。
首先,我们需要在 Python 中实现该哈希算法:
def ROR4(val, bits, bit_size=32):
return ((val & (2 ** bit_size - 1)) >> bits % bit_size) | \
(val << (bit_size - (bits % bit_size)) & (2 ** bit_size - 1))
def hashme(s):
res = 0
for c in s:
v3 = ROR4(res, 13)
v4 = c - 32
if c < 97:
v4 = c
res = v4 + v3
return hex(res)
然后,使用以下命令计算所有 API 的哈希值:
$ python uchihash.py --script custom_algo.py --apis --idapython
该命令将生成两个文件。第一个文件 "output/search_hashmap.txt" 将哈希值映射到相应的 API 名称,内容如下:
{
"0x8a8b468c": "LoadLibraryW",
"0x302ebe1c": "VirtualAlloc",
"0x1803b7e3": "VirtualProtect",
"0xe183277b": "VirtualFree",
"0x24e2968d": "GetComputerNameW",
"0xab489125": "GetNativeSystemInfo",
.......
}
第二个文件是 "output/idapython_script.py",你可以在 IDA Pro 中运行此脚本,脚本会向 IDB 中添加哈希注释,如下所示:
