mcpField
B
building-detection-rules-with-sigma

building-detection-rules-with-sigma

github.com/mukul975セキュリティ35.2k196 回インストール8 週間前に更新
リポジトリ

building-detection-rules-with-sigma について

SOCエンジニア向けに、Sigma検知ルールの作成、検証、SIEMクエリへの変換、テスト、展開を支援するスキルです。脅威インテリジェンスやハンティングの結果を移植可能な検知ルールにできます。

主な機能

  1. 01YAML形式のSigmaルール作成
  2. 02ルール構文の検証
  3. 03SIEMクエリへの変換
  4. 04MITRE ATT&CK技術へのマッピング
  5. 05ルールのテストと誤検知の評価
  6. 06バージョン管理とCI/CDでの運用

活用シーン

  1. 01脅威インテリジェンスを検知ルールに変換
  2. 02一時的なハンティングを継続検知に昇格
  3. 03SIEM移行に向けたルールの標準化
  4. 04レッドチームの知見を防御に反映

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill building-detection-rules-with-sigma

インストール後、Claude Code で/building-detection-rules-with-sigmaを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

LICENSE
references/
api-reference.md
scripts/
agent.py

詳細

Sigma による検知ルールの作成

使用する場面

次のような場合にこのスキルを使用します。

  • SOC エンジニアが、複数の SIEM プラットフォームで利用できる検知ルールを作成する必要がある場合
  • 脅威インテリジェンスレポートに、新たな検知範囲が必要となる TTP が記載されている場合
  • 既存のベンダー固有ルールを、共有可能な形式に標準化する必要がある場合
  • チームが CI/CD パイプラインで、検知をコードとして管理する標準に Sigma を採用する場合

リアルタイムのストリーミング検知には使用しないでください(Sigma はバッチ検索またはスケジュール検索向けです)。また、対象の SIEM に Sigma では表現できないネイティブの検知機能がある場合にも使用しないでください(例:Splunk RBA のリスクスコアリング)。

前提条件

  • pySigma と適切なバックエンド(pySigma-backend-splunk、pySigma-backend-elasticsearch、pySigma-backend-microsoft365defender)をインストールした Python 3.8+
  • Sigma ルールリポジトリのクローン:git clone https://github.com/SigmaHQ/sigma.git
  • 手法のマッピングに必要な MITRE ATT&CK フレームワークの知識
  • 対象 SIEM のログソースのフィールドマッピングに関する理解

ワークフロー

ステップ 1:脅威インテリジェンスから検知ロジックを定義する

脅威レポートまたは ATT&CK の手法から始めます。例:Mimikatz による認証情報のダンプ(T1003.001 — LSASS メモリ)を検知します。

title: Mimikatz Credential Dumping via LSASS Access
id: 0d894093-71bc-43c3-8d63-bf520e73a7c5
status: stable
level: high
description: Detects process accessing lsass.exe memory, indicative of credential dumping tools like Mimikatz
references:
    - https://attack.mitre.org/techniques/T1003/001/
    - https://github.com/gentilkiwi/mimikatz
author: mahipal
date: 2024/03/15
modified: 2024/03/15
tags:
    - attack.credential_access
    - attack.t1003.001
logsource:
    category: process_access
    product: windows
detection:
    selection:
        TargetImage|endswith: '\lsass.exe'
        GrantedAccess|contains:
            - '0x1010'
            - '0x1038'
            - '0x1fffff'
            - '0x40'
    filter_main_svchost:
        SourceImage|endswith: '\svchost.exe'
    filter_main_csrss:
        SourceImage|endswith: '\csrss.exe'
    filter_main_wininit:
        SourceImage|endswith: '\wininit.exe'
    condition: selection and not 1 of filter_main_*
falsepositives:
    - Legitimate security tools accessing LSASS
    - Windows Defender scanning
    - CrowdStrike Falcon sensor
ステップ 2:Sigma ルールの構文を検証する

sigma check を使用してルールを検証します。

# Install pySigma and validators
pip install pySigma pySigma-validators-sigmaHQ

# Validate rule
sigma check rule.yml

または、Python で検証します。

from sigma.rule import SigmaRule
from sigma.validators.core import SigmaValidator

rule = SigmaRule.from_yaml(open("rule.yml").read())
validator = SigmaValidator()
issues = validator.validate_rule(rule)
for issue in issues:
    print(f"{issue.severity}: {issue.message}")
ステップ 3:対象 SIEM のクエリに変換する

Splunk SPL に変換:

from sigma.rule import SigmaRule
from sigma.backends.splunk import SplunkBackend
from sigma.pipelines.splunk import splunk_windows_pipeline

pipeline = splunk_windows_pipeline()
backend = SplunkBackend(pipeline)

rule = SigmaRule.from_yaml(open("rule.yml").read())
splunk_query = backend.convert_rule(rule)
print(splunk_query[0])

出力:

TargetImage="*\\lsass.exe" (GrantedAccess="*0x1010*" OR GrantedAccess="*0x1038*"
OR GrantedAccess="*0x1fffff*" OR GrantedAccess="*0x40*")
NOT (SourceImage="*\\svchost.exe") NOT (SourceImage="*\\csrss.exe")
NOT (SourceImage="*\\wininit.exe")

Elastic クエリ(Lucene)に変換:

from sigma.backends.elasticsearch import LuceneBackend
from sigma.pipelines.elasticsearch import ecs_windows_pipeline

pipeline = ecs_windows_pipeline()
backend = LuceneBackend(pipeline)
elastic_query = backend.convert_rule(rule)
print(elastic_query[0])

Microsoft Sentinel KQL に変換:

from sigma.backends.microsoft365defender import Microsoft365DefenderBackend

backend = Microsoft365DefenderBackend()
kql_query = backend.convert_rule(rule)
print(kql_query[0])
ステップ 4:MITRE ATT&CK にマッピングし、カバレッジのメタデータを追加する

すべてのルールに、tags フィールドで ATT&CK の手法 ID を付与します。

tags:
    - attack.credential_access        # Tactic
    - attack.t1003.001                # Sub-technique
    - attack.t1003                    # Parent technique

ATT&CK Navigator を使って検知カバレッジを追跡します。

import json

# Generate ATT&CK Navigator layer from Sigma rules
layer = {
    "name": "SOC Detection Coverage",
    "versions": {"attack": "14", "navigator": "4.9", "layer": "4.5"},
    "domain": "enterprise-attack",
    "techniques": []
}

# Parse Sigma rules directory for technique tags
import os
from sigma.rule import SigmaRule

for root, dirs, files in os.walk("sigma/rules/windows/"):
    for f in files:
        if f.endswith(".yml"):
            rule = SigmaRule.from_yaml(open(os.path.join(root, f)).read())
            for tag in rule.tags:
                if str(tag).startswith("attack.t"):
                    technique_id = str(tag).replace("attack.", "").upper()
                    layer["techniques"].append({
                        "techniqueID": technique_id,
                        "color": "#31a354",
                        "score": 1
                    })

with open("coverage_layer.json", "w") as f:
    json.dump(layer, f, indent=2)
ステップ 5:サンプルデータに対してルールをテストする

テストデータを作成し、想定されるイベントをルールが検知することを確認します。

# Use sigma test framework
sigma test rule.yml --target splunk --pipeline splunk_windows

# Or manually test in Splunk with sample data
# Upload Sysmon process_access log with known Mimikatz signature

アラートを発生させない保存済み検索で本番データの 7 日分を対象に実行し、誤検知率を検証します。

ステップ 6:本番 SIEM にデプロイする

変換したクエリを、スケジュール検索または相関ルールとしてデプロイします。

Splunk ES の相関検索:

| tstats summariesonly=true count from datamodel=Endpoint.Processes
  where Processes.process_name="*\\lsass.exe"
  by Processes.src, Processes.user, Processes.process_name, Processes.parent_process_name
| `drop_dm_object_name(Processes)`
| where count > 0

Elastic Security ルール(TOML 形式):

[rule]
name = "LSASS Memory Access - Credential Dumping"
description = "Detects suspicious access to LSASS process memory"
risk_score = 73
severity = "high"
type = "eql"
query = '''
process where event.action == "access" and
  process.name == "lsass.exe" and
  not process.executable : ("*\\svchost.exe", "*\\csrss.exe")
'''

[rule.threat]
framework = "MITRE ATT&CK"
[[rule.threat.technique]]
id = "T1003"
name = "OS Credential Dumping"
ステップ 7:バージョン管理と CI/CD の統合

自動テストを組み込んで、ルールを Git に保存します。

# .github/workflows/sigma-ci.yml
name: Sigma Rule CI
on: [push, pull_request]
jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      - run: pip install pySigma pySigma-validators-sigmaHQ
      - run: sigma check rules/
      - run: sigma convert -t splunk -p splunk_windows rules/ > /dev/null

主な概念

用語定義
Sigmaバックエンドを介して SIEM 固有のクエリにコンパイルできる、ベンダーに依存しない検知ルール形式(YAML ベース)
pySigmaルールの変換、検証、パイプライン処理において、従来の sigmac に代わる Python ライブラリ
バックエンドSigma の検知ロジックを対象プラットフォームのクエリ言語(SPL、KQL、Lucene)に変換する pySigma プラグイン
パイプライン汎用的な Sigma フィールド名を SIEM 固有のフィールド名に変換するフィールドマッピング設定
ログソース対象データのカテゴリ(process_creation、network_connection)と製品(windows、linux)を定義する Sigma ルールのセクション
検知のコード化CI/CD テストと自動デプロイを用い、検知ルールをバージョン管理で運用する実践

ツールとシステム

  • SigmaHQ:GitHub で 3,000 件以上のコミュニティ管理の検知ルールを公開する、Sigma の公式ルールリポジトリ
  • pySigma:モジュール式のバックエンドとパイプラインを備えた、Python ベースの Sigma ルール処理フレームワーク
  • ATT&CK Navigator:ATT&CK の手法にマッピングされた検知カバレッジを可視化する MITRE のツール
  • Uncoder.IO:30 以上の SIEM プラットフォームに対応した、迅速な変換に使える Web ベースの Sigma ルールコンバーター

一般的なシナリオ

  • 新たな CVE の検出:悪用の兆候(例:Web ログ内の Log4Shell JNDI ルックアップパターン)を検出する Sigma ルールを作成します
  • ハンティングルールの昇格:アドホックな Splunk ハンティングクエリを Sigma ルールに変換し、継続的な自動検出を実現します
  • 複数 SIEM 間の移行:Elastic Security への移行に向けて、500 件以上の Splunk 相関検索を Sigma に変換します
  • パープルチームの成果:レッドチームの調査結果を Sigma ルールに変換し、即時に防御範囲を強化します
  • 脅威インテリジェンスの運用化:IOC ベースの脅威レポートを、振る舞いに基づく Sigma ルールに変換します

出力形式

SIGMA RULE DEPLOYMENT REPORT
━━━━━━━━━━━━━━━━━━━━━━━━━━━
Rule ID:      0d894093-71bc-43c3-8d63-bf520e73a7c5
Title:        Mimikatz Credential Dumping via LSASS Access
ATT&CK:       T1003.001 - LSASS Memory
Severity:     High
Status:       Deployed to Production

Conversions:
  Splunk SPL:    PASS — Saved search "sigma_lsass_access" created
  Elastic EQL:   PASS — Detection rule ID elastic-0d894093 enabled
  Sentinel KQL:  PASS — Analytics rule deployed via ARM template

Testing:
  True Positives:    4/4 test cases matched
  False Positives:   2 in 7-day backtest (svchost edge case — filter added)
  Performance:       Avg execution 3.2s on 50M events/day

コメント