
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 という名前にし、引数はハッシュ化する値を表すバイト文字列1つとし、戻り値は16進数形式にします(examples/custom_algo.txt を参照)
--search: 検索対象のファイルは JSON 形式にします(examples/searchme.txt を参照)
--hashes: ハッシュ値は改行で区切り、16進数形式にします(examples/myhashes.txt を参照)
詳細は examples フォルダを参照してください。
実際のマルウェアファミリーを例に取ります。ここでは BuerLoader を扱います。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
このコマンドにより2つのファイルが生成されます。1つ目は "output/search_hashmap.txt" で、ハッシュ値と対応する API 名を以下のようにマッピングします。
{
"0x8a8b468c": "LoadLibraryW",
"0x302ebe1c": "VirtualAlloc",
"0x1803b7e3": "VirtualProtect",
"0xe183277b": "VirtualFree",
"0x24e2968d": "GetComputerNameW",
"0xab489125": "GetNativeSystemInfo",
.......
}
2つ目は "output/idapython_script.py" で、IDAPython スクリプトです。IDAPython を IDA Pro で実行すると、以下のように IDB にハッシュコメントが追加されます。
