Skip to content
ブログに戻る

YARAルールによるマルウェア検出:実践ガイド

u
unJaena Team
2026年4月10日10 分で読めます
YARAルールによるマルウェア検出:実践ガイド

YARAルールによるマルウェア検出#

YARAは、マルウェア研究者が悪意あるサンプルを特定・分類するために使用するパターンマッチングツールです。「マルウェア研究者のスイスアーミーナイフ」とも呼ばれ、文字列パターンとバイナリパターンを組み合わせた複雑な検出ルールを記述することができます。

YARAの基本#

基本的なルール構造#

YARAルールは3つの主要セクションで構成されています。

yara
rule ExampleRule {
    meta:
        author = "unJaena Team"
        description = "Example YARA rule"
        date = "2026-04-10"
        severity = "high"

    strings:
        $str1 = "suspicious_string"
        $str2 = { 4D 5A 90 00 }  // MZ header
        $str3 = /https?:\/\/[a-z0-9\-\.]+\.xyz/

    condition:
        uint16(0) == 0x5A4D and
        filesize < 5MB and
        ($str1 or $str2) and
        #str3 > 2
}

コア要素の解説#

metaセクション: ルールに関するメタデータを定義します。検出には影響しませんが、管理とドキュメンテーションに不可欠です。

stringsセクション: 検出するパターンを定義します。

  • テキスト文字列: "suspicious_string"
  • 16進バイトパターン: { 4D 5A 90 00 }
  • 正規表現: /pattern/

conditionセクション: 論理演算子を使用して検出条件を組み合わせます。

実践的なYARAルールの作成#

1. RAT(Remote Access Trojan)の検出#

yara
rule Detect_RAT_Indicators {
    meta:
        description = "Detects common RAT behavior patterns"
        severity = "critical"

    strings:
        $cmd1 = "cmd.exe /c" nocase
        $cmd2 = "powershell -enc" nocase
        $cmd3 = "whoami" nocase
        $net1 = "CONNECT" ascii
        $net2 = "POST /gate" ascii
        $reg1 = "CurrentVersion\\Run" nocase
        $mutex = "Global\\" ascii

    condition:
        uint16(0) == 0x5A4D and
        filesize < 10MB and
        (2 of ($cmd*)) and
        (1 of ($net*)) and
        ($reg1 or $mutex)
}

2. 情報窃取マルウェアの検出#

yara
rule Detect_Stealer_Patterns {
    meta:
        description = "Detects info stealer behavior"
        severity = "high"

    strings:
        $browser1 = "\\Google\\Chrome\\User Data" nocase
        $browser2 = "\\Mozilla\\Firefox\\Profiles" nocase
        $browser3 = "\\Microsoft\\Edge\\User Data" nocase
        $wallet1 = "wallet.dat" nocase
        $wallet2 = "\\Ethereum\\keystore" nocase
        $grab1 = "passwords" nocase
        $grab2 = "cookies" nocase
        $grab3 = "autofill" nocase
        $exfil1 = "multipart/form-data" ascii
        $exfil2 = "Content-Disposition" ascii

    condition:
        uint16(0) == 0x5A4D and
        (2 of ($browser*)) and
        (1 of ($grab*)) and
        (1 of ($exfil*))
}

3. ランサムウェアの動作パターン検出#

yara
rule Detect_Ransomware_Behavior {
    meta:
        description = "Detects ransomware encryption patterns"
        severity = "critical"

    strings:
        $ext1 = ".locked" ascii
        $ext2 = ".crypt" ascii
        $ext3 = "DECRYPT" ascii nocase
        $ext4 = "RANSOM" ascii nocase
        $note1 = "Your files have been" ascii nocase
        $note2 = "bitcoin" ascii nocase
        $note3 = "payment" ascii nocase
        $shadow = "vssadmin delete shadows" nocase
        $bcdedit = "bcdedit /set" nocase

    condition:
        uint16(0) == 0x5A4D and
        filesize < 20MB and
        (2 of ($ext*)) and
        (1 of ($note*)) and
        ($shadow or $bcdedit)
}

高度な技術#

ワイルドカードとジャンプ#

特定のバイトが可変の場合、バイナリパターンでワイルドカードを使用します。

yara
strings:
    // ワイルドカード (?)
    $hex1 = { 4D 5A ?? ?? 00 }

    // ジャンプ(可変長)
    $hex2 = { E8 [4-8] 85 C0 }

    // 代替(OR)
    $hex3 = { (6A 40 | 6A 00) 68 }

モジュールの使用#

YARAは組み込みモジュールを通じて、PEファイルやELFファイルなどの構造分析機能を提供します。

yara
import "pe"
import "math"

rule Suspicious_PE_Characteristics {
    meta:
        description = "PE file with suspicious characteristics"

    condition:
        pe.is_pe and
        pe.number_of_sections > 6 and
        pe.timestamp < 1000000000 and
        math.entropy(0, filesize) > 7.5 and
        pe.imports("kernel32.dll", "VirtualAlloc") and
        pe.imports("kernel32.dll", "WriteProcessMemory")
}

パフォーマンスの最適化#

YARAルールのパフォーマンスを最適化するための主要な原則:

  1. 高速なチェックを条件の先頭に: uint16(0) == 0x5A4Dのようなマジックバイトチェックを最初に実行
  2. ファイルサイズの制限: 大きなファイルの不要なスキャンを防止
  3. 文字列数の最小化: 必要なパターンのみを定義
  4. 正規表現の使いすぎを避ける: 可能な限り固定文字列を使用
  5. ワイルドカード範囲の制限: [0-100]ではなく[4-8]のような狭い範囲を使用

AIとYARAの組み合わせ#

従来のYARAルールベースの検出とAI分析を組み合わせることで、より強力な脅威検出が可能になります。

検出パイプライン#

収集されたファイル ↓ YARAスキャン(160以上のルール) ├─ マッチしたルール情報 ├─ 重大度の分類 └─ マッチングパターンの詳細 ↓ CAPA分析(動作ベース) ├─ 悪意ある能力の特定 └─ MITRE ATT&CKマッピング ↓ AI統合分析 ├─ コンテキストに基づくリスク評価 ├─ 誤検知のフィルタリング └─ 自然言語による分析レポート

メリット#

  • YARAの強み: 高速なパターンマッチング、低い誤検知率、明確な検出根拠
  • AIの強み: コンテキストの理解、新しい脅威パターンの特定、包括的な分析
  • 相乗効果: YARAが疑わしいファイルをフィルタリングし、AIが深い分析を実施

コミュニティルールセット#

すべてのYARAルールを自分で書く必要はありません。実績のあるコミュニティルールセットを活用しましょう。

  • YARA-Rules: コミュニティによって維持されている包括的なルールコレクション
  • Signature-Base: Florian Roth(Neo23x0)が維持する高品質なルールセット
  • Malpedia: マルウェアファミリごとに分類されたYARAルール
  • ThreatFox: abuse.chの脅威インテリジェンスに基づくIOC

まとめ#

YARAはマルウェア検出の基盤であり、中核的なツールです。静的パターンマッチングというシンプルな原理に基づきながらも、適切に記述されたYARAルールは複雑な脅威でも効果的に検出することができます。

AIベースの分析と組み合わせることで、YARAの高速なフィルタリング能力とAIの深い分析能力が相乗効果を生み、より正確で効率的な脅威検出システムの構築が可能になります。

unJaenaプラットフォームは、160以上のYARAルールとCAPA動作分析をAIパイプラインに統合し、アップロードされたファイルに対する自動マルウェア分析を提供しています。

共有

最新フォレンジックインサイトを受け取る

デジタルフォレンジックとAI分析に関する月刊ニュースレターをお届けします。

ニュースレターを購読