
悪意のあるドキュメントからYARAルールを自動生成します。

Halogen は、悪意のあるドキュメントに埋め込まれた画像ファイルに基づいて YARA ルールの作成を自動化するツールです。これは、サイバーセキュリティの専門家が悪意のある脅威に対する検出ルールを作成する際や、対応者が特定の脅威を識別する際に役立ちます。現在、Halogen は JPG および PNG ファイルに基づくルールを作成できます。

python3 halogen.py -h
usage: halogen.py [-h] [-f FILE] [-d DIR] [-n NAME] [--png-idat] [--jpg-sos] [--jpg-sof2sos] [--jpg-jump] [-c CONTAINER] [--clam] [--rprefix RPREFIX]
Halogen: Automatically create yara rules based on images embedded in office documents.
optional arguments:
-h, --help show this help message and exit
-f FILE, --file FILE File to parse
-d DIR, --directory DIR
directory to scan for image files.
-n NAME, --rule-name NAME
specify a custom name for the rule file
--png-idat For PNG matches, instead of starting with the PNG file header, start with the IDAT chunk.
--jpg-sos For JPG matches, skip over the header and look for the Start of Scan marker, and begin the match there.
--jpg-sof2sos for JPG matches, skip over the header and match the SOF all the way to the SOS + 45 bytes of the data within the SOS.
--jpg-jump for JPG matches, skip over the header and identify the sof, the sos and then read the actual image data take that data and look for repeated bytes. Skip those bytes and then
create 45 bytes of raw image data.
-c CONTAINER, --container CONTAINER
specify a clamav container type defaults to CL_TYPE_MSOLE2, CL_TYPE_OOXML_WORD, CL_TYPE_OOXML_XL, CL_TYPE_OOXML_PPT
--clam generate a clam rule instead of a yara rule
--rprefix RPREFIX specify a clamav ruleset prefix
テスト用に、画像が埋め込まれたテストドキュメントファイルをいくつか含めています。python3 halogen/halogen.py -d tests/ > /tmp/halogen_test.yara を実行すると、tests/ ディレクトリ内のファイルに含まれるすべての画像を含むテスト YARA ファイルが生成されます。
その後、yara -d /tmp/halogen_test.yara tests/ を実行して、どの画像がどのファイルに一致するかを確認できます。
--png-idat を使用して PNG ファイル内の IDAT チャンクから開始することもできます。IDAT チャンクでマッチングする場合、返されるバイト数も減らしています。--jpg-sos フラグを使用して、JPG マッチングをスキャン開始 (Start of Scan) マーカーから開始できます。--jpg-sof2sos フラグも用意しています。これは、フレーム開始 (SOF) マーカーから SOS が見つかるまで読み取り、さらに 45 バイトを読み取ります。これは、標準の --jpg-sos で誤検出が発生する場合に便利です。--jpg-jump フラグを追加しました。これは、圧縮された画像データを読み取り、YARA 出力内で繰り返し画像バイトが見つかった場合に 16 進数ジャンプを作成します。これにより、ファイルの SOF と SOS、および画像内のよりユニークなデータの一部にマッチングできます。プルリクエストは Python3 で送信してください。また、見つけたバグは Issue として報告してください。