building-detection-rule-with-splunk-spl について
セキュリティアナリストや Splunk 管理者向けに、Splunk SPL で相関検索を作成するスキルです。検知パターン、コンテキストの付加、性能改善、テスト、MITRE ATT&CK への対応付けを扱います。
主な機能
- 01しきい値とイベント系列の検知
- 02異常および横展開の検索
- 03データ持ち出しと PowerShell の検知
- 04ルックアップによる情報の付加
- 05検索パフォーマンスの最適化
- 06テストと検知指標の算出
活用シーン
- 01ブルートフォースの相関検索作成
- 02不審な PowerShell 実行の検知
- 03データ持ち出しの可能性の監視
- 04アラートの適合率と誤検知の測定
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ mukul975/ anthropic-cybersecurity-skills --skill building-detection-rule-with-splunk-splインストール後、Claude Code で/building-detection-rule-with-splunk-splを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
LICENSEassets/template.mdreferences/api-reference.mdstandards.mdworkflows.mdscripts/agent.pyprocess.py詳細
Splunk SPL を使用した検知ルールの構築
概要
Splunk Search Processing Language(SPL)は、Splunk Enterprise Security で疑わしいイベントやパターンを検知する相関検索を構築するために使用される主要なクエリ言語です。適切に作成された検知ルールは、セキュリティイベントを集約、相関、エンリッチメントし、SOC アナリストが対応できる重要イベントを生成します。平均すると、エンタープライズ SIEM がカバーする MITRE ATT&CK のテクニックはわずか 21%であるため、検知のギャップを埋めるには、熟練した SPL ルールの作成が不可欠です。
使用する場面
- お使いの環境で Splunk SPL 機能を使用して検知ルールを構築、導入、または設定する場合
- コンプライアンス要件に沿ったセキュリティ制御を確立する場合
- この分野のセキュリティアーキテクチャを構築または改善する場合
- この実装が必要なセキュリティ評価を実施する場合
前提条件
- Splunk Enterprise Security(ES)が導入され、設定されていること
- 適切なロールで Splunk Search & Reporting アプリにアクセスできること
- Common Information Model(CIM)データモデルを理解していること
- MITRE ATT&CK フレームワークのテクニックに精通していること
- 組織のログソースとデータフローを把握していること
SPL 検知ルールの基本パターン
1. しきい値ベースの検知
指定した時間枠内に定義済みの件数を超えたイベントを検知します。
index=wineventlog sourcetype=WinEventLog:Security EventCode=4625
| stats count as failed_logins dc(TargetUserName) as unique_users by src_ip
| where failed_logins > 10 AND unique_users > 3
| eval severity="high"
| eval description="Brute force attack detected from ".src_ip." with ".failed_logins." failed logins across ".unique_users." accounts"
2. シーケンスベースの検知(ログイン失敗後の成功)
ブルートフォース攻撃が成功したことを示す一連のイベントを相関付けます。
index=wineventlog sourcetype=WinEventLog:Security (EventCode=4625 OR EventCode=4624)
| eval login_status=case(EventCode=4625, "failure", EventCode=4624, "success")
| stats count(eval(login_status="failure")) as failures count(eval(login_status="success")) as successes latest(_time) as last_event by src_ip, TargetUserName
| where failures > 5 AND successes > 0
| eval description="Account ".TargetUserName." compromised via brute force from ".src_ip
| eval urgency="critical"
3. ベースラインとの比較による異常検知
現在のアクティビティをベースライン期間と比較し、急増を検知します。
index=proxy sourcetype=squid
| bin _time span=1h
| stats count as current_count by src_ip, _time
| join src_ip type=left [
search index=proxy sourcetype=squid earliest=-7d@d latest=-1d@d
| stats avg(count) as avg_count stdev(count) as stdev_count by src_ip
]
| eval threshold=avg_count + (3 * stdev_count)
| where current_count > threshold
| eval deviation=round((current_count - avg_count) / stdev_count, 2)
| eval description="Anomalous web traffic from ".src_ip." - ".deviation." standard deviations above baseline"
4. ラテラルムーブメントの検知
Windows のログオンイベントを使用して、ラテラルムーブメントの可能性を特定します。
index=wineventlog sourcetype=WinEventLog:Security EventCode=4624 Logon_Type=3
| where NOT match(TargetUserName, ".*\$$")
| stats dc(dest) as unique_hosts values(dest) as hosts by src_ip, TargetUserName
| where unique_hosts > 5
| eval severity=case(unique_hosts > 20, "critical", unique_hosts > 10, "high", true(), "medium")
| eval description=TargetUserName." accessed ".unique_hosts." unique hosts from ".src_ip." via network logon"
5. データ流出の検知
大量のアウトバウンドデータ転送を監視します。
index=firewall sourcetype=pan:traffic action=allowed direction=outbound
| stats sum(bytes_out) as total_bytes_out dc(dest_ip) as unique_destinations by src_ip, user
| eval total_mb=round(total_bytes_out/1048576, 2)
| where total_mb > 500 OR unique_destinations > 50
| lookup asset_lookup ip as src_ip OUTPUT asset_category, asset_owner
| eval severity=case(total_mb > 2000, "critical", total_mb > 1000, "high", true(), "medium")
| eval description=user." transferred ".total_mb."MB to ".unique_destinations." unique destinations"
6. PowerShell の不審な実行の検知
エンコードまたは難読化された PowerShell コマンドを検知します。
index=wineventlog sourcetype=WinEventLog:Security EventCode=4104
| where match(ScriptBlockText, "(?i)(encodedcommand|invoke-expression|iex|downloadstring|frombase64string|net\.webclient|invoke-webrequest|bitstransfer|invoke-mimikatz|invoke-shellcode)")
| eval decoded_length=len(ScriptBlockText)
| stats count values(ScriptBlockText) as commands by Computer, UserName
| where count > 0
| eval severity="high"
| eval mitre_technique="T1059.001"
| eval description="Suspicious PowerShell execution on ".Computer." by ".UserName
Splunk ES での相関検索の構築
手順
- ユースケースを定義する:MITRE ATT&CK のテクニックに対応付け、検知する挙動を定義します
- データソースを特定する:関連イベントを含むインデックスと sourcetype を特定します
- ベース検索を記述する:関連イベントを抽出する SPL を構築します
- 集約を追加する:
stats、eventstats、またはstreamstatsを使って要約します - しきい値を適用する:通常と異常を区別する条件を
where句で設定します - コンテキストをエンリッチメントする:アセット情報、ID データ、脅威インテリジェンスのルックアップを追加します
- 重要イベントを設定する:重要度、緊急度、説明の各フィールドを設定します
- スケジュールを設定してテストする:過去のデータに対して実行し、検知精度を検証します
相関検索の設定テンプレート
| tstats summariesonly=true count from datamodel=Authentication
where Authentication.action=failure
by Authentication.src, Authentication.user, _time span=5m
| rename "Authentication.*" as *
| stats count as total_failures dc(user) as unique_users values(user) as targeted_users by src
| where total_failures > 20 AND unique_users > 5
| lookup dnslookup clientip as src OUTPUT clienthost as src_dns
| lookup asset_lookup ip as src OUTPUT priority as asset_priority, category as asset_category
| eval urgency=case(asset_priority=="critical", "critical", asset_priority=="high", "high", true(), "medium")
| eval rule_name="Brute Force Against Multiple Accounts"
| eval rule_description="Multiple authentication failures from ".src." targeting ".unique_users." unique accounts"
| eval mitre_attack="T1110.001 - Password Guessing"
エンリッチメントのベストプラクティス
| lookup identity_lookup identity as user OUTPUT department, manager, risk_score as user_risk
| lookup asset_lookup ip as src_ip OUTPUT asset_name, asset_category, asset_priority, asset_owner
| lookup threatintel_lookup ip as src_ip OUTPUT threat_type, threat_confidence, threat_source
| eval context=case(
isnotnull(threat_type), "Known threat: ".threat_type,
user_risk > 80, "High-risk user: risk score ".user_risk,
asset_priority=="critical", "Critical asset: ".asset_name,
true(), "Standard context"
)
パフォーマンスの最適化
tstats でデータモデルを使用する
| tstats summariesonly=true count from datamodel=Network_Traffic
where All_Traffic.action=allowed
by All_Traffic.src_ip, All_Traffic.dest_ip, All_Traffic.dest_port, _time span=1h
| rename "All_Traffic.*" as *
時間範囲を制限し、インデックス済みフィールドを使用する
index=wineventlog source="WinEventLog:Security" EventCode=4688
earliest=-15m latest=now()
| where NOT match(New_Process_Name, "(?i)(svchost|csrss|lsass|services)")
過去のベースラインにはサマリーインデックスを使用する
| tstats count from datamodel=Authentication where Authentication.action=failure by Authentication.src, _time span=1h
| collect index=summary source="auth_failure_baseline" marker="report_name=auth_failure_hourly"
テストと検証
既知の攻撃パターンに対してテストする
| makeresults count=1
| eval src_ip="10.0.0.50", failed_logins=25, unique_users=8, severity="high"
| eval description="Test brute force detection"
| append [
search index=wineventlog sourcetype=WinEventLog:Security EventCode=4625
earliest=-24h latest=now()
| stats count as failed_logins dc(TargetUserName) as unique_users by src_ip
| where failed_logins > 10 AND unique_users > 3
| eval severity="high"
]
検知メトリクスを算出する
index=notable
| search rule_name="Brute Force*"
| stats count as total_alerts count(eval(status_label="Closed - True Positive")) as true_positives count(eval(status_label="Closed - False Positive")) as false_positives by rule_name
| eval precision=round(true_positives / (true_positives + false_positives) * 100, 2)
| eval fpr=round(false_positives / total_alerts * 100, 2)
MITRE ATT&CK への対応付け
| テクニック ID | テクニック名 | SPL による検知アプローチ |
|---|---|---|
| T1110.001 | パスワード推測 | src_ip ごとの EventCode 4625 をしきい値で検知 |
| T1059.001 | PowerShell | EventCode 4104 の ScriptBlockText に対するパターンマッチ |
| T1021.002 | SMB/Windows 管理共有 | dc(dest)のしきい値を使ったログオンタイプ 3 |
| T1048 | C2 経由の情報流出 | 時間枠内の bytes_out を集約 |
| T1053.005 | スケジュールされたタスク | 不審なコマンドパターンを含む EventCode 4698 |
| T1003.001 | LSASS メモリ | Sysmon EventCode 10 による lsass.exe へのプロセスアクセス |
参考資料
コメント
Markdown 対応