ハニーポット運用(Yaraルールを学ぶ}
最近は自宅でのリモートワークが増えたため運動量がめっきりと減った。 少しでもカロリー消費を思い、ランニングしたが足が釣ってしまい家にいる時間が増え更に体重がました。 デブ活待ったなしである。
仕事の空き時間にYaraルールについて学ぶことにした。Honeypotもあるのでより実態に近い攻撃の観測ができるだろう。
Yaraルールとは
・ YARAは、マルウェア研究者がマルウェアサンプルを識別し分類するのを支援することを目的としたツール。
・ YARAを使うと、テキストパターンやバイナリパターンに基づいて、マルウェアファミリーの説明文を作成することができる。
・ OpenSourceで構成されたPythonベースのツールでありマルウェア解析に有益である。
Yaraルールのフォーマット
1 rule silent_banker : banker 2 { 3 meta: 4 description = "This is just an example" 5 threat_level = 3 6 in_the_wild = true 7 strings: 8 $a = {6A 40 68 00 30 00 00 6A 14 8D 91} 9 $b = {8D 4D B0 2B C1 83 C0 27 99 6A 4E 59 F7 F9} 10 $c = "UVODFRYSIHLNWPEJXQZAKCBGMT" 11 condition: 12 $a or $b or $c 13 } 1 rule句 Yaraルールで設定するルール名を指定する 3 meta句 Yaraルールの説明内容を指定する 7 strings句 検索条件を指定する。文字列、バイナリ 11 condition句 検索条件に対する論理条件(or , and)を指定する。
Yaraルールの検知例
最近のT-Potの活動状況からYaraルールで攻撃状況を確認してみる。
※使用するのは以下のGithubのデータを利用する。
github.com
まずはheraldingから。
# yara rules-master/index.yar /data/heralding/session.csv.14.gz rules-master/./crypto/crypto_signatures.yar(11): warning: $c0 in rule Big_Numbers0 is slowing down scanning <中略> CRC32c_poly_Constant /data/heralding/log/session.csv.14.gz possible_includes_base64_packed_functions /data/heralding/log/auth.csv.14.gz
cowireには目ぼしいデータが無かった。
(´・ω・`)ショボーン
dionaeaはwanacryばかりかと思い確認すると嬉しい発見があった。
# ls -al /data/dionaea/binaries/ /data/dionaea/binaries/: total 920436 drwxrwx--- 2 tpot tpot 12288 May 1 06:53 . drwxrwx--- 8 tpot tpot 4096 May 1 06:52 .. -rw------- 1 tpot tpot 5267459 May 1 04:01 01bdc6fb077098f4a3b60f4b0e479a7f <サイズ5267459のこのへんはwanacry関連のため中略> -rw------- 1 tpot tpot 5267459 May 1 03:55 af26cb0a1db5f669ded0944f6e939a55 -rw-r--r-- 1 tpot tpot 1952 May 1 06:25 AV.lnk -rw-r--r-- 1 tpot tpot 1952 May 1 05:10 AV.lnk.~1~ -rw-r--r-- 1 tpot tpot 1952 May 1 05:38 AV.lnk.~2~ -rw-r--r-- 1 tpot tpot 1952 May 1 05:47 AV.lnk.~3~ -rw-r--r-- 1 tpot tpot 1952 May 1 06:02 AV.lnk.~4~ -rw-r--r-- 1 tpot tpot 116416 May 1 06:52 AV.scr -rw-r--r-- 1 tpot tpot 6165527 May 1 04:53 AV.scr.~1~ -rw-r--r-- 1 tpot tpot 3637004 May 1 06:11 AV.scr.~10~ -rw-r--r-- 1 tpot tpot 785358 May 1 06:17 AV.scr.~11~ -rw-r--r-- 1 tpot tpot 6183325 May 1 06:25 AV.scr.~12~ -rw-r--r-- 1 tpot tpot 580895 May 1 06:38 AV.scr.~13~ -rw-r--r-- 1 tpot tpot 1899407 May 1 06:46 AV.scr.~14~ -rw-r--r-- 1 tpot tpot 722030 May 1 05:00 AV.scr.~2~ -rw-r--r-- 1 tpot tpot 5249784 May 1 05:10 AV.scr.~3~ -rw-r--r-- 1 tpot tpot 6184265 May 1 05:18 AV.scr.~4~ -rw-r--r-- 1 tpot tpot 6185614 May 1 05:29 AV.scr.~5~ -rw-r--r-- 1 tpot tpot 6170342 May 1 05:38 AV.scr.~6~ -rw-r--r-- 1 tpot tpot 6183999 May 1 05:47 AV.scr.~7~ -rw-r--r-- 1 tpot tpot 6185540 May 1 05:54 AV.scr.~8~ -rw-r--r-- 1 tpot tpot 6217504 May 1 06:02 AV.scr.~9~ -rw------- 1 tpot tpot 5267459 May 1 05:45 b91b5718554c4112a004de392d608c5b <サイズ5267459のこのへんはwanacry関連のため中略> -rw------- 1 tpot tpot 5267459 May 1 05:40 ffafe05991d988d69f994b0b863b32b9 -rw-r--r-- 1 tpot tpot 1952 May 1 06:52 Photo.lnk -rw-r--r-- 1 tpot tpot 1952 May 1 04:53 Photo.lnk.~1~ -rw-r--r-- 1 tpot tpot 1952 May 1 06:25 Photo.lnk.~10~ -rw-r--r-- 1 tpot tpot 1952 May 1 06:39 Photo.lnk.~11~ -rw-r--r-- 1 tpot tpot 1952 May 1 06:46 Photo.lnk.~12~ -rw-r--r-- 1 tpot tpot 1952 May 1 05:00 Photo.lnk.~2~ -rw-r--r-- 1 tpot tpot 1952 May 1 05:10 Photo.lnk.~3~ -rw-r--r-- 1 tpot tpot 1952 May 1 05:35 Photo.lnk.~4~ -rw-r--r-- 1 tpot tpot 1952 May 1 05:38 Photo.lnk.~5~ -rw-r--r-- 1 tpot tpot 1952 May 1 05:47 Photo.lnk.~6~ -rw-r--r-- 1 tpot tpot 1952 May 1 05:54 Photo.lnk.~7~ -rw-r--r-- 1 tpot tpot 1952 May 1 06:02 Photo.lnk.~8~ -rw-r--r-- 1 tpot tpot 1952 May 1 06:11 Photo.lnk.~9~ -rw-r--r-- 1 tpot tpot 259894 May 1 06:52 Photo.scr -rw-r--r-- 1 tpot tpot 6206815 May 1 05:36 Photo.scr.~1~ -rw-r--r-- 1 tpot tpot 6186014 May 1 05:49 Photo.scr.~10~ -rw-r--r-- 1 tpot tpot 6192379 May 1 05:56 Photo.scr.~11~ -rw-r--r-- 1 tpot tpot 6196807 May 1 06:05 Photo.scr.~12~ -rw-r--r-- 1 tpot tpot 29712 May 1 06:11 Photo.scr.~13~ -rw-r--r-- 1 tpot tpot 461070 May 1 06:20 Photo.scr.~14~ -rw-r--r-- 1 tpot tpot 6171194 May 1 06:29 Photo.scr.~15~ -rw-r--r-- 1 tpot tpot 6202331 May 1 06:33 Photo.scr.~16~ -rw-r--r-- 1 tpot tpot 233660 May 1 06:40 Photo.scr.~17~ -rw-r--r-- 1 tpot tpot 1085456 May 1 06:48 Photo.scr.~18~ -rw-r--r-- 1 tpot tpot 6186733 May 1 05:36 Photo.scr.~2~ -rw-r--r-- 1 tpot tpot 59210 May 1 05:02 Photo.scr.~3~ -rw-r--r-- 1 tpot tpot 236740 May 1 05:13 Photo.scr.~4~ -rw-r--r-- 1 tpot tpot 6191361 May 1 05:20 Photo.scr.~5~ -rw-r--r-- 1 tpot tpot 6200562 May 1 05:24 Photo.scr.~6~ -rw-r--r-- 1 tpot tpot 6197144 May 1 05:31 Photo.scr.~7~ -rw-r--r-- 1 tpot tpot 6190216 May 1 05:35 Photo.scr.~8~ -rw-r--r-- 1 tpot tpot 6181605 May 1 05:41 Photo.scr.~9~ -rw-r--r-- 1 tpot tpot 1952 May 1 06:46 Video.lnk -rw-r--r-- 1 tpot tpot 1952 May 1 04:53 Video.lnk.~1~ -rw-r--r-- 1 tpot tpot 1952 May 1 05:00 Video.lnk.~2~ -rw-r--r-- 1 tpot tpot 1952 May 1 05:10 Video.lnk.~3~ -rw-r--r-- 1 tpot tpot 1952 May 1 05:38 Video.lnk.~4~ -rw-r--r-- 1 tpot tpot 1952 May 1 05:47 Video.lnk.~5~ -rw-r--r-- 1 tpot tpot 1952 May 1 06:02 Video.lnk.~6~ -rw-r--r-- 1 tpot tpot 1952 May 1 06:25 Video.lnk.~7~ -rw-r--r-- 1 tpot tpot 69629 May 1 06:50 Video.scr -rw-r--r-- 1 tpot tpot 6181128 May 1 05:40 Video.scr.~1~ -rw-r--r-- 1 tpot tpot 6179167 May 1 05:59 Video.scr.~10~ -rw-r--r-- 1 tpot tpot 6203518 May 1 06:07 Video.scr.~11~ -rw-r--r-- 1 tpot tpot 1033832 May 1 06:16 Video.scr.~12~ -rw-r--r-- 1 tpot tpot 266838 May 1 06:22 Video.scr.~13~ -rw-r--r-- 1 tpot tpot 4958610 May 1 06:37 Video.scr.~14~ -rw-r--r-- 1 tpot tpot 270741 May 1 06:43 Video.scr.~15~ -rw-r--r-- 1 tpot tpot 6189680 May 1 05:40 Video.scr.~2~ -rw-r--r-- 1 tpot tpot 1157787 May 1 05:40 Video.scr.~3~ -rw-r--r-- 1 tpot tpot 6181557 May 1 05:40 Video.scr.~4~ -rw-r--r-- 1 tpot tpot 6179896 May 1 05:40 Video.scr.~5~ -rw-r--r-- 1 tpot tpot 6193504 May 1 05:40 Video.scr.~6~ -rw-r--r-- 1 tpot tpot 6194120 May 1 05:40 Video.scr.~7~ -rw-r--r-- 1 tpot tpot 6183906 May 1 05:45 Video.scr.~8~ -rw-r--r-- 1 tpot tpot 6166708 May 1 05:52 Video.scr.~9~
Photo.lnk、Photo.scr、Video.lnk.、Video.scr.から始まる見慣れないファイルがある。 Yaraスキャンで確認してみる。
# yara rules-master/index.yar /data/dionaea/binaries/Video.scr rules-master/./crypto/crypto_signatures.yar(11): warning: $c0 in rule Big_Numbers0 is slowing down scanning <中略> rules-master/./packers/peid.yar(68951): warning: $a in rule StarForce_V1X_V5X_StarForce_Copy_Protection_System_20090906 is slowing down scanning SEH_Save /data/dionaea/binaries/Video.scr SEH_Init /data/dionaea/binaries/Video.scr maldoc_find_kernel32_base_method_1 /data/dionaea/binaries/Video.scr IsPE32 /data/dionaea/binaries/Video.scr IsWindowsGUI /data/dionaea/binaries/Video.scr HasDebugData /data/dionaea/binaries/Video.scr IsBeyondImageSize /data/dionaea/binaries/Video.scr HasRichSignature /data/dionaea/binaries/Video.scr VC8_Microsoft_Corporation /data/dionaea/binaries/Video.scr Microsoft_Visual_Cpp_8 /data/dionaea/binaries/Video.scr
なんか色々出ている。
SEH_Save・・・アンチデバッキング(Tactic_DefensiveEvasion Technique_AntiDebugging SubTechnique_SEH) SEH_Init・・・アンチデバッキング(Tactic_DefensiveEvasion Technique_AntiDebugging SubTechnique_SEH) maldoc_find_kernel32_base_method_1 IsPE32・・・PE32ファイルの確認 IsWindowsGUI・・・WindowsGUIファイルの確認 HasDebugData・・・アンチデバッキング IsBeyondImageSize・・・画像サイズを超えたデータチェック HasRichSignature・・・Rich Signatureの確認 VC8_Microsoft_Corporation・・・Microsoft Visual C++ 8のファイル Microsoft_Visual_Cpp_8・・・Microsoft Visual C++ 8のファイル
よりサイズの少ないファイルも確認してみる。
# ls -alR /data/dionaea/binaries/yara rules-master/index.yar /data/dionaea/binaries/Video.scr.~3~ rules-master/./crypto/crypto_signatures.yar(11): warning: $c0 in rule Big_Numbers0 is slowing down scanning <中略> rules-master/./packers/peid.yar(68951): warning: $a in rule StarForce_V1X_V5X_StarForce_Copy_Protection_System_20090906 is slowing down scanning DebuggerException__SetConsoleCtrl /data/dionaea/binaries/Video.scr.~3~ SEH_Save /data/dionaea/binaries/Video.scr.~3~ SEH_Init /data/dionaea/binaries/Video.scr.~3~ anti_dbg /data/dionaea/binaries/Video.scr.~3~ win_files_operation /data/dionaea/binaries/Video.scr.~3~ Str_Win32_Winsock2_Library /data/dionaea/binaries/Video.scr.~3~ CRC32_poly_Constant /data/dionaea/binaries/Video.scr.~3~ CRC32_table /data/dionaea/binaries/Video.scr.~3~ maldoc_find_kernel32_base_method_1 /data/dionaea/binaries/Video.scr.~3~ PE_File_pyinstaller /data/dionaea/binaries/Video.scr.~3~ IsPE32 /data/dionaea/binaries/Video.scr.~3~ IsWindowsGUI /data/dionaea/binaries/Video.scr.~3~ IsPacked /data/dionaea/binaries/Video.scr.~3~ HasOverlay /data/dionaea/binaries/Video.scr.~3~ HasDebugData /data/dionaea/binaries/Video.scr.~3~ HasRichSignature /data/dionaea/binaries/Video.scr.~3~ VC8_Microsoft_Corporation /data/dionaea/binaries/Video.scr.~3~ Microsoft_Visual_Cpp_8 /data/dionaea/binaries/Video.scr.~3~
Packerによる圧縮処理などが追加されていた。
DebuggerException__SetConsoleCtrl・・・アンチデバッキング SEH_Save・・・アンチデバッキング(Tactic_DefensiveEvasion Technique_AntiDebugging SubTechnique_SEH) SEH_Init・・・アンチデバッキング(Tactic_DefensiveEvasion Technique_AntiDebugging SubTechnique_SEH) anti_dbg・・・アンチデバッキング win_files_operation・・・Windowsの実行形式ファイル Str_Win32_Winsock2_Library・・・Win32_Winsock2_Libraryの使用 CRC32_poly_Constant CRC32_table・・・CRC32 Tablesの確認 maldoc_find_kernel32_base_method_1 PE_File_pyinstaller・・・Windows形式のpythonインストーラ IsPE32・・・PE32ファイルの確認 IsWindowsGUI・・・WindowsGUIファイルの確認 IsPacked・・・Packerによる圧縮確認 HasOverlay・・・overlay planeの確認 HasDebugData・・・アンチデバッキング HasRichSignature・・・Rich Signatureの確認 VC8_Microsoft_Corporation・・・Microsoft Visual C++ 8のファイル Microsoft_Visual_Cpp_8・・・Microsoft Visual C++ 8のファイル
VirusTotalで確認してみる。
PE32形式のCoinMinerマルウェアだった。
こちらはダウンローダだった。
VirusTotalでは何も検出されないがこのリンクを踏ませてから動くようだ。 AV.linkの下のtester1234.exeが本体だろうか。
世界的にリモートワークが増えているので攻撃の傾向も変わっているようにみえる。
ルールとSnortルールの違いについて
Yaraルールを勉強すると類似のルールとしてSuricataなどでも利用されるSnortルールがある。 Suricataを学ぶにあたってYaraルールとの差異を疑問に思っていたが、Googleドキュメントでその比較について分かりやすく解説されていた。
Snortルールはかなり複雑です。 Yaraルールは非常にシンプルです。
Snort ルールは、検出/予防/パケットキャプチャにも有効にできます。 Yara ルールは主にマルウェアの分類に使用され、これを利用して IDS ルールを作成することができます。
Yara は文字列、正規表現、16進数を受け付けます。
主な違いは、Yaraがマルウェアの分類に役立つのに対し、snortはIDSアラートを有効にするための実際のルールを構築するのに役立ちます。
マルウェアの解析にはYaraルールの方が便利ということか。
Yaraルールの書き方は以下のURLが参考になる。
最後に
調査で利用したmalwareは安全にスタッフがすべて削除しました。