mcpField
I
implementing-network-intrusion-prevention-with-suricata

implementing-network-intrusion-prevention-with-suricata

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

implementing-network-intrusion-prevention-with-suricata について

ネットワークIDS、IPS、監視エンジンとしてのSuricata運用を扱うスキルです。セキュリティチーム向けに、インライン遮断、ルール管理、カスタムルール、性能確認、アラート調整を説明します。

主な機能

  1. 01インラインIPSモードの設定
  2. 02suricata-updateによるルール管理
  3. 03カスタム検知ルールの作成
  4. 04アラートとパケットドロップの監視
  5. 05誤検知の調整

活用シーン

  1. 01インラインのトラフィック遮断の導入
  2. 02検知シグネチャの保守
  3. 03アラート調査とノイズの多いルールの削減

インストール

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

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill implementing-network-intrusion-prevention-with-suricata

インストール後、Claude Code で/implementing-network-intrusion-prevention-with-suricataを入力して読み込まれたか確認します。

同梱ファイル

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

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

詳細

Suricata によるネットワーク侵入防止の実装

概要

Suricata は、Open Information Security Foundation(OISF)が開発した、高性能なオープンソースのネットワーク脅威検知エンジンです。IDS(侵入検知システム)、IPS(侵入防止システム)、ネットワークセキュリティ監視ツールとして機能します。Suricata は、豊富なルールセット、プロトコル解析、ファイル抽出機能を使用して、パケットを詳細に検査します。IPS モードでは、Suricata はインラインでパケットを検査し、悪意のあるトラフィックを積極的にブロックできます。このスキルでは、Suricata を IPS モードで導入する方法、ルールセットの設定、カスタムルールの作成、パフォーマンスのチューニング、ログ基盤との統合について説明します。

使用する場面

  • 環境に Suricata のネットワーク侵入防止機能を導入または設定する場合
  • コンプライアンス要件に沿ったセキュリティ制御を確立する場合
  • この分野のセキュリティアーキテクチャを構築または改善する場合
  • この実装が必要なセキュリティ評価を実施する場合

前提条件

  • CPU コア数が 4 以上、RAM が 8GB 以上の Linux サーバー(Ubuntu 22.04 以降または CentOS 8 以降)
  • Suricata 7.0 以降がインストールされていること
  • インライン導入のためのネットワーク上の位置(ブリッジモードまたは NFQUEUE)
  • Emerging Threats Open または ET Pro ルールセットのサブスクリプション
  • ルール管理用の Suricata-update ツール
  • ログ基盤(ELK Stack、Splunk、または Wazuh)

主な概念

動作モード
モード機能ネットワーク上の位置
IDS(AF_PACKET)パッシブ監視、アラートのみTAP/SPAN ミラー
IPS(NFQUEUE)netfilter によるインラインブロックトラフィック経路上
IPS(AF_PACKET)AF_PACKET によるインラインブロックインターフェース間のブリッジ
オフライン(PCAP)キャプチャしたトラフィックファイルを解析該当なし
ルールの構造

Suricata のルールは、構造化された形式に従います。

action protocol src_ip src_port -> dst_ip dst_port (rule_options;)
  • アクション:alert、pass、drop、reject、rejectsrc、rejectdst、rejectboth
  • プロトコル:tcp、udp、icmp、ip、http、tls、dns、smtp、ftp
  • 方向:->(単方向)、<>(双方向)
ルールのカテゴリ
  • Emerging Threats Open — コミュニティが管理する、幅広い範囲をカバーする無料のルールセット
  • ET Pro — Proofpoint が提供する、カバー範囲を強化した商用ルールセット
  • Suricata Traffic ID — アプリケーション識別ルール
  • カスタムルール — 組織固有の検知ルール

ワークフロー

ステップ 1:Suricata をインストールする
# Add Suricata PPA (Ubuntu)
sudo add-apt-repository ppa:oisf/suricata-stable
sudo apt-get update
sudo apt-get install -y suricata suricata-update

# Verify installation
suricata --build-info
suricata -V
ステップ 2:IPS モード用に Suricata を設定する

/etc/suricata/suricata.yaml を編集します。

%YAML 1.1
---

vars:
  address-groups:
    HOME_NET: "[10.0.0.0/8,172.16.0.0/12,192.168.0.0/16]"
    EXTERNAL_NET: "!$HOME_NET"
    HTTP_SERVERS: "$HOME_NET"
    DNS_SERVERS: "[10.0.1.10/32,10.0.1.11/32]"
    SMTP_SERVERS: "$HOME_NET"

  port-groups:
    HTTP_PORTS: "80"
    SHELLCODE_PORTS: "!80"
    SSH_PORTS: "22"
    DNS_PORTS: "53"

# IPS mode with NFQUEUE
nfq:
  mode: accept
  repeat-mark: 1
  repeat-mask: 1
  route-queue: 2
  fail-open: yes

# Threading configuration
threading:
  set-cpu-affinity: yes
  cpu-affinity:
    - management-cpu-set:
        cpu: [0]
    - receive-cpu-set:
        cpu: [1,2]
    - worker-cpu-set:
        cpu: [3,4,5,6,7]
        mode: exclusive

# Detection engine
detect-engine:
  - profile: high
  - custom-values:
      toclient-groups: 50
      toserver-groups: 50
  - sgh-mpm-context: auto
  - inspection-recursion-limit: 3000

# Stream engine
stream:
  memcap: 512mb
  checksum-validation: yes
  inline: auto
  reassembly:
    memcap: 1gb
    depth: 1mb
    toserver-chunk-size: 2560
    toclient-chunk-size: 2560

# Logging configuration
outputs:
  - eve-log:
      enabled: yes
      filetype: regular
      filename: /var/log/suricata/eve.json
      types:
        - alert:
            payload: yes
            payload-buffer-size: 4kb
            payload-printable: yes
            packet: yes
            metadata: yes
            tagged-packets: yes
        - http:
            extended: yes
        - dns:
            query: yes
            answer: yes
        - tls:
            extended: yes
        - files:
            force-magic: yes
            force-hash: [md5, sha256]
        - flow
        - netflow
        - stats:
            totals: yes
            threads: no
            deltas: yes

  - fast:
      enabled: yes
      filename: /var/log/suricata/fast.log

  - stats:
      enabled: yes
      filename: /var/log/suricata/stats.log
      interval: 30

# Rule files
default-rule-path: /var/lib/suricata/rules
rule-files:
  - suricata.rules
ステップ 3:インライン IPS 用に NFQUEUE を設定する

Suricata 経由でトラフィックをリダイレクトするよう iptables を設定します。

# Enable IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

# Redirect FORWARD chain to NFQUEUE
sudo iptables -I FORWARD -j NFQUEUE --queue-num 0 --queue-bypass

# For multi-queue (better performance)
sudo iptables -I FORWARD -j NFQUEUE --queue-balance 0:3 --queue-bypass

# Save iptables rules
sudo iptables-save > /etc/iptables/rules.v4

別の方法:2 つのインターフェース間で AF_PACKET インラインモードを使用します。

# In suricata.yaml
af-packet:
  - interface: eth0
    cluster-id: 98
    cluster-type: cluster_flow
    defrag: yes
    use-mmap: yes
    copy-mode: ips
    copy-iface: eth1
  - interface: eth1
    cluster-id: 97
    cluster-type: cluster_flow
    defrag: yes
    use-mmap: yes
    copy-mode: ips
    copy-iface: eth0
ステップ 4:Suricata-Update でルールを管理する
# Update rules from default sources (ET Open)
sudo suricata-update

# List available rule sources
sudo suricata-update list-sources

# Enable ET Pro (requires license key)
sudo suricata-update enable-source et/pro secret-code=YOUR_OINKCODE

# Enable additional sources
sudo suricata-update enable-source oisf/trafficid
sudo suricata-update enable-source ptresearch/attackdetection
sudo suricata-update enable-source sslbl/ssl-fp-blacklist

# Disable specific rules that generate false positives
echo "2100498" >> /etc/suricata/disable.conf
echo "group:emerging-policy.rules" >> /etc/suricata/disable.conf

# Modify rule actions (change alert to drop)
echo 're:ET MALWARE' >> /etc/suricata/modify.conf

# Apply updates
sudo suricata-update --reload-command="suricatasc -c reload-rules"
ステップ 5:カスタムルールを作成する

/var/lib/suricata/rules/local.rules を作成します。

# Detect potential reverse shell over TCP
drop tcp $HOME_NET any -> $EXTERNAL_NET any (msg:"LOCAL Potential Reverse Shell - /bin/bash in payload"; flow:to_server,established; content:"/bin/bash"; content:"-i"; within:20; classtype:trojan-activity; sid:1000001; rev:1;)

# Block known malicious user agent
drop http $HOME_NET any -> $EXTERNAL_NET any (msg:"LOCAL Malicious User-Agent - Cobalt Strike"; http.user_agent; content:"Mozilla/5.0 (compatible|3b| MSIE 9.0|3b| Windows NT 6.1|3b| WOW64|3b| Trident/5.0)"; classtype:trojan-activity; sid:1000002; rev:1;)

# Detect DNS query for known DGA domain pattern
alert dns $HOME_NET any -> any 53 (msg:"LOCAL Suspicious DGA Domain Query"; dns.query; content:".top"; pcre:"/^[a-z0-9]{12,30}\.(top|xyz|club|online|site)$/"; classtype:bad-unknown; sid:1000003; rev:1;)

# Detect large DNS TXT response (potential C2)
alert dns any 53 -> $HOME_NET any (msg:"LOCAL Large DNS TXT Response - Potential C2"; dns.opcode:0; content:"|00 10|"; byte_test:2,>,500,0,relative; classtype:bad-unknown; sid:1000004; rev:1;)

# Block outbound traffic to Tor exit nodes
drop tcp $HOME_NET any -> [100.2.18.10,104.244.76.13,109.70.100.1] any (msg:"LOCAL Outbound Connection to Known Tor Exit Node"; classtype:policy-violation; sid:1000005; rev:1;)

# Detect SMB lateral movement attempts
alert tcp $HOME_NET any -> $HOME_NET 445 (msg:"LOCAL Internal SMB Connection - Possible Lateral Movement"; flow:to_server,established; content:"|ff|SMB"; offset:4; depth:4; threshold:type both,track by_src,count 5,seconds 60; classtype:attempted-admin; sid:1000006; rev:1;)

# Detect PowerShell download cradle
drop http $HOME_NET any -> $EXTERNAL_NET any (msg:"LOCAL PowerShell Download Cradle Detected"; http.user_agent; content:"PowerShell"; nocase; http.method; content:"GET"; classtype:trojan-activity; sid:1000007; rev:1;)

# Detect ICMP tunneling (large ICMP packets)
alert icmp $HOME_NET any -> $EXTERNAL_NET any (msg:"LOCAL Oversized ICMP Packet - Possible Tunneling"; dsize:>800; threshold:type both,track by_src,count 10,seconds 60; classtype:bad-unknown; sid:1000008; rev:1;)
ステップ 6:Suricata を IPS モードで起動する
# Test configuration
sudo suricata -T -c /etc/suricata/suricata.yaml

# Start in NFQUEUE IPS mode
sudo suricata -c /etc/suricata/suricata.yaml -q 0

# Start with AF_PACKET inline mode
sudo suricata -c /etc/suricata/suricata.yaml --af-packet

# Start as systemd service
sudo systemctl enable suricata
sudo systemctl start suricata

# Monitor performance stats
tail -f /var/log/suricata/stats.log

# Reload rules without restart
sudo suricatasc -c reload-rules

監視とチューニング

パフォーマンス指標
# Check kernel drops
sudo suricatasc -c dump-counters | grep -E "capture.kernel_drops|decoder.pkts"

# Monitor EVE JSON alerts
tail -f /var/log/suricata/eve.json | jq 'select(.event_type=="alert")'

# Check rule loading
grep -c "rules loaded" /var/log/suricata/suricata.log

# Memory usage
sudo suricatasc -c dump-counters | grep memuse
誤検知を減らすためのチューニング
# Identify noisy rules
cat /var/log/suricata/eve.json | jq -r 'select(.event_type=="alert") | .alert.signature_id' | sort | uniq -c | sort -rn | head -20

# Suppress specific rules per source
echo "suppress gen_id 1, sig_id 2100498, track by_src, ip 10.0.5.0/24" >> /etc/suricata/threshold.config

# Rate-limit alerts
echo "rate_filter gen_id 1, sig_id 2100366, track by_src, count 10, seconds 60, new_action alert, timeout 300" >> /etc/suricata/threshold.config

ベストプラクティス

  • まず IDS モードから開始する — まず IDS(アラートのみ)モードで導入し、2~4 週間チューニングしてから IPS に切り替えます
  • フェイルオープン — Suricata がクラッシュしてもネットワークトラフィックが継続するよう、フェイルオープンモードを設定します
  • ルールのチューニング — drop アクションを有効にする前に、threshold と suppress のディレクティブを使用して誤検知を減らします
  • CPU アフィニティ — 安定したパフォーマンスを得るため、Suricata のワーカースレッドを専用の CPU コアに割り当てます
  • 信頼できるトラフィックをバイパスする — 既知の正常なトラフィックに pass ルールを使用して、処理負荷を軽減します
  • 定期的な更新 — シグネチャを最新の状態に保つため、cron で毎日 suricata-update を実行します
  • ドロップを監視する — カーネルによるパケットドロップを追跡し、必要に応じてリングバッファーのサイズを増やします

References

コメント