mcpField
C
configuring-suricata-for-network-monitoring

configuring-suricata-for-network-monitoring

github.com/mukul975安全35.2k109 次安装8 周前更新
代码仓库

关于 configuring-suricata-for-network-monitoring

该技能指导配置 Suricata,用于多线程网络流量监测、入侵检测与防护。内容涵盖规则管理、EVE JSON 日志及 SIEM 集成,适合部署和运维网络安全监测的团队。

主要功能

  1. 01配置高性能流量捕获
  2. 02管理和调优检测规则
  3. 03生成 EVE JSON 事件日志
  4. 04启用协议检测与指纹识别
  5. 05集成 SIEM 分析告警

适用场景

  1. 01监测网络边界流量并检测威胁
  2. 02在内联 IPS 模式阻断恶意流量
  3. 03将结构化事件导入 SIEM
  4. 04分析 TLS 与 SSH 指纹

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill configuring-suricata-for-network-monitoring

安装后在 Claude Code 中输入/configuring-suricata-for-network-monitoring确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

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

详细介绍

为网络监控配置 Suricata

适用场景

  • 部署高性能 IDS/IPS,能够为 10+ Gbps 网络链路进行多线程数据包处理
  • 通过针对 HTTP、TLS、DNS、SMB 及其他协议的协议感知检测来监控网络流量
  • 生成结构化 EVE JSON 日志,无需自定义解析器即可直接接入 SIEM
  • 以串联(IPS)模式运行,在网络咽喉点主动阻断恶意流量
  • 将基于签名的检测与协议异常检测和文件提取相结合

请勿使用:在没有其他补充控制措施的情况下将其作为独立安全解决方案,在无法进行 TLS 解密的情况下检查加密流量,或在 CPU/内存不足以应对预期流量的系统上使用。

前置条件

  • 从 PPA 或源码安装 Suricata 7.0+(suricata --build-info)
  • 用于流量捕获的位于镜像端口、分路器或串联网桥上的网络接口
  • 用于高性能数据包捕获的 AF_PACKET 或 DPDK 支持
  • Emerging Threats Open 或 Pro 规则集订阅(或通过 oinkcode 使用 Snort Talos 规则)
  • 用于自动化规则管理的 suricata-update 工具
  • 用于日志分析和可视化的 Elasticsearch/Kibana 或 Splunk

工作流

步骤 1:安装 Suricata 及依赖项
# Install from PPA (Ubuntu/Debian)
sudo add-apt-repository ppa:oisf/suricata-stable
sudo apt update
sudo apt install -y suricata suricata-update jq

# Verify installation
suricata --build-info | grep -E "Version|AF_PACKET|NFQueue"

# Or install from source for latest features
sudo apt install -y libpcre2-dev build-essential autoconf automake libtool \
  libpcap-dev libnet1-dev libyaml-dev libjansson-dev libcap-ng-dev \
  libmagic-dev libnetfilter-queue-dev libhiredis-dev rustc cargo cbindgen
git clone https://github.com/OISF/suricata.git
cd suricata && git clone https://github.com/OISF/libhtp.git -b 0.5.x
./autogen.sh && ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var \
  --enable-nfqueue --enable-af-packet
make -j$(nproc) && sudo make install install-conf
步骤 2:配置网络接口
# Disable NIC offloading features
sudo ethtool -K eth1 gro off lro off tso off gso off rx off tx off sg off

# Set interface to promiscuous mode
sudo ip link set eth1 promisc on

# For high-performance deployments, configure AF_PACKET with multiple threads
# Edit /etc/suricata/suricata.yaml
步骤 3:配置 suricata.yaml
# /etc/suricata/suricata.yaml (key sections)

# Network variables
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: "$HOME_NET"
    SMTP_SERVERS: "$HOME_NET"

# Default rule path
default-rule-path: /var/lib/suricata/rules
rule-files:
  - suricata.rules

# AF_PACKET configuration for high performance
af-packet:
  - interface: eth1
    threads: auto
    cluster-id: 99
    cluster-type: cluster_flow
    defrag: yes
    use-mmap: yes
    ring-size: 200000
    buffer-size: 262144

# EVE JSON logging (primary output format)
outputs:
  - eve-log:
      enabled: yes
      filetype: regular
      filename: eve.json
      pcap-file: false
      community-id: true
      types:
        - alert:
            tagged-packets: yes
            payload: yes
            payload-printable: yes
            http-body: yes
            http-body-printable: yes
        - http:
            extended: yes
        - dns:
            query: yes
            answer: yes
        - tls:
            extended: yes
        - files:
            force-magic: yes
            force-hash: [md5, sha256]
        - smtp:
            extended: yes
        - flow
        - netflow
        - anomaly:
            enabled: yes
        - stats:
            totals: yes
            threads: yes

  # PCAP logging for captured packets that trigger alerts
  - pcap-log:
      enabled: yes
      filename: alert-%n.pcap
      limit: 100mb
      max-files: 50
      mode: normal
      use-stream-depth: no
      honor-pass-rules: no

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

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

# Protocol detection and parsing
app-layer:
  protocols:
    http:
      enabled: yes
      memcap: 64mb
    tls:
      enabled: yes
      detection-ports:
        dp: 443, 8443
      ja3-fingerprints: yes
    dns:
      enabled: yes
      tcp:
        enabled: yes
      udp:
        enabled: yes
    smb:
      enabled: yes
      detection-ports:
        dp: 139, 445
    ssh:
      enabled: yes
      hassh: yes
步骤 4:下载和管理规则集
# Update Suricata rules using suricata-update
sudo suricata-update

# Enable additional rule sources
sudo suricata-update list-sources
sudo suricata-update enable-source et/open
sudo suricata-update enable-source oisf/trafficid
sudo suricata-update enable-source ptresearch/attackdetection

# Update with all enabled sources
sudo suricata-update

# Check rule statistics
sudo suricata-update list-sources --enabled
wc -l /var/lib/suricata/rules/suricata.rules

# Disable noisy rules
sudo tee /etc/suricata/disable.conf << 'EOF'
# Disable overly broad rules
2100498
2013028
2210000-2210050
group:emerging-policy.rules
EOF

# Create custom local rules
sudo tee /etc/suricata/rules/local.rules << 'EOF'
# Detect reverse shell connections
alert tcp $HOME_NET any -> $EXTERNAL_NET 4444 (msg:"LOCAL Reverse Shell Port 4444"; flow:established,to_server; content:"|2f 62 69 6e 2f|"; sid:9000001; rev:1; classtype:trojan-activity; priority:1;)

# Detect DNS tunneling by query length
alert dns $HOME_NET any -> any any (msg:"LOCAL DNS Tunneling Long Query"; dns.query; content:"."; offset:50; sid:9000002; rev:1; classtype:policy-violation; priority:2;)

# Detect TLS to suspicious JA3 hash (Cobalt Strike default)
alert tls $HOME_NET any -> $EXTERNAL_NET any (msg:"LOCAL Cobalt Strike JA3 Hash"; ja3.hash; content:"72a589da586844d7f0818ce684948eea"; sid:9000003; rev:1; classtype:trojan-activity; priority:1;)

# Detect SSH brute force
alert ssh $EXTERNAL_NET any -> $HOME_NET 22 (msg:"LOCAL SSH Brute Force Attempt"; flow:to_server; threshold:type both, track by_src, count 10, seconds 60; sid:9000004; rev:1; classtype:attempted-admin; priority:2;)

# Detect data exfiltration via HTTP POST (large uploads)
alert http $HOME_NET any -> $EXTERNAL_NET any (msg:"LOCAL Large HTTP POST Upload"; flow:to_server,established; http.method; content:"POST"; http.content_len; content:">"; byte_test:8,>,10000000,0,string; sid:9000005; rev:1; classtype:policy-violation; priority:2;)
EOF

# Add local rules to configuration
echo "  - local.rules" | sudo tee -a /etc/suricata/suricata.yaml
步骤 5:部署并验证
# Validate configuration
sudo suricata -T -c /etc/suricata/suricata.yaml -v

# Run Suricata in IDS mode
sudo suricata -c /etc/suricata/suricata.yaml --af-packet=eth1 -D

# Or run in IPS mode (inline with NFQueue)
# First configure iptables to send traffic to NFQueue
# sudo iptables -I FORWARD -j NFQUEUE --queue-num 0
# sudo suricata -c /etc/suricata/suricata.yaml -q 0 -D

# Create systemd service
sudo tee /etc/systemd/system/suricata.service << 'EOF'
[Unit]
Description=Suricata IDS/IPS
After=network.target
Requires=network.target

[Service]
Type=simple
ExecStartPre=/usr/bin/suricata -T -c /etc/suricata/suricata.yaml
ExecStart=/usr/bin/suricata -c /etc/suricata/suricata.yaml --af-packet=eth1 --pidfile /var/run/suricata.pid
ExecReload=/bin/kill -USR2 $MAINPID
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl enable --now suricata

# Test with a known signature
curl http://testmynids.org/uid/index.html
# Should trigger ET GPL rule for uid.

# Verify alerts are generated
sudo tail -f /var/log/suricata/eve.json | jq 'select(.event_type=="alert")'
步骤 6:与 SIEM 集成并监控
# Parse EVE JSON with jq for quick analysis
# Top 10 alerts
cat /var/log/suricata/eve.json | jq -r 'select(.event_type=="alert") | .alert.signature' | sort | uniq -c | sort -rn | head -10

# Extract IOCs from alerts
cat /var/log/suricata/eve.json | jq -r 'select(.event_type=="alert") | [.timestamp, .src_ip, .dest_ip, .alert.signature, .alert.severity] | @csv' > alert_summary.csv

# JA3 fingerprint analysis
cat /var/log/suricata/eve.json | jq -r 'select(.event_type=="tls") | [.src_ip, .tls.ja3.hash, .tls.sni] | @csv' | sort | uniq -c | sort -rn

# DNS query analysis
cat /var/log/suricata/eve.json | jq -r 'select(.event_type=="dns" and .dns.type=="query") | [.src_ip, .dns.rrname, .dns.rrtype] | @csv' | sort | uniq -c | sort -rn | head -20

# Configure Filebeat for Elastic integration
sudo tee /etc/filebeat/modules.d/suricata.yml << 'EOF'
- module: suricata
  eve:
    enabled: true
    var.paths: ["/var/log/suricata/eve.json"]
EOF

sudo filebeat modules enable suricata
sudo systemctl restart filebeat

# Monitor Suricata performance
cat /var/log/suricata/eve.json | jq 'select(.event_type=="stats") | .stats.capture' | tail -1
# Check for packet drops: kernel_drops should be 0

关键概念

术语定义
EVE JSONSuricata 的主要日志格式,为告警、协议元数据、流记录和统计信息生成结构化 JSON 事件
AF_PACKETLinux 内核数据包捕获机制,Suricata 使用它实现具备内核旁路能力的高性能流量捕获
JA3/JA3STLS 指纹识别方法,根据 TLS Client Hello 和 Server Hello 参数生成哈希值,用于识别应用程序和恶意软件
HASSH类似于 JA3 的 SSH 指纹识别方法,根据 SSH 密钥交换参数生成哈希值,以识别 SSH 客户端和服务端实现
Community ID标准化流标识符哈希,支持在不同监控工具(Suricata、Zeek、Wireshark)之间关联同一网络流
suricata-update官方规则管理工具,可下载、合并和管理多个规则集,并支持启用/禁用控制

工具与系统

  • Suricata 7.0+:开源多线程 IDS/IPS/NSM 引擎,具备协议检测、文件提取和 JA3/HASSH 指纹识别功能
  • suricata-update:支持 ET Open、ET Pro、Snort 规则和自定义规则源的规则集管理工具
  • Elastic Stack (ELK):日志聚合与可视化平台,Filebeat 中内置 Suricata 模块,可提供仪表板和告警功能
  • Scirius:基于 Web 的 Suricata 规则管理界面,用于编辑、启用/禁用和监控规则性能
  • Evebox:用于 Suricata EVE JSON 日志的轻量级事件查看器,具备告警管理和升级能力

常见场景

场景:在 10 Gbps 企业网络边界部署 Suricata IDS

背景:一家科技公司需要在其处理 10 Gbps 流量的互联网出口点部署 IDS。他们需要用于威胁狩猎的协议级元数据日志记录、针对已知威胁的基于签名的告警,以及用于检测恶意软件 C2 通信的 JA3 指纹识别。告警必须接入他们的 Elastic SIEM。

方法:

  1. 在一台配备 16 个 CPU 核心、64 GB RAM 和双 10G 网卡的服务器上部署 Suricata,使用 AF_PACKET 并配置 14 个工作线程
  2. 通过 suricata-update 启用 ET Open 和 ptresearch/attackdetection 规则集,总计约 35,000 条活动规则
  3. 配置 EVE JSON 日志记录,启用 community-id、扩展 HTTP/TLS/DNS 元数据和文件哈希(MD5 + SHA256)
  4. 启用 JA3 和 HASSH 指纹识别,用于 TLS 和 SSH 流量分析
  5. 为组织特定威胁编写自定义规则:已知的恶意 JA3 哈希、对 DGA 域名的 DNS 查询、向不常见目的地的大规模数据上传
  6. 通过 Filebeat 的 Suricata 模块与 Elastic 集成,部署预构建的 Kibana 仪表板以实现实时可见性
  7. 在 2 周基线期内调整规则,禁用误报生成规则并调整阈值

注意事项:

  • 未分配足够的 CPU 线程,导致在流量高峰时出现数据包丢失
  • 在未调整的情况下启用所有可用规则,导致分析师被误报淹没
  • 忘记禁用网卡卸载,导致校验和不正确并错过检测
  • 未启用 community-id,导致难以将 Suricata 事件与 Zeek 或其他工具关联

输出格式

## Suricata IDS Deployment Report

**Sensor**: suricata-gw-01 (10.10.1.251)
**Interface**: eth1 (span from border router)
**Configuration**: /etc/suricata/suricata.yaml
**Worker Threads**: 14 AF_PACKET threads
**Active Rules**: 35,247 (ET Open + Custom)

### Performance Metrics (24-hour)

| Metric | Value |
|--------|-------|
| Packets Processed | 847,293,421 |
| Kernel Drops | 0 (0.000%) |
| Alerts Generated | 1,247 |
| Unique Signatures Fired | 89 |
| JA3 Fingerprints Observed | 342 unique |
| Files Extracted | 2,847 |

### Top 10 Alert Signatures

| Count | SID | Signature | Severity |
|-------|-----|-----------|----------|
| 312 | 2024897 | ET POLICY curl User-Agent Outbound | 3 |
| 189 | 9000003 | LOCAL Cobalt Strike JA3 Hash | 1 |
| 145 | 2028765 | ET SCAN Nmap SYN Scan | 2 |
| 98 | 9000002 | LOCAL DNS Tunneling Long Query | 2 |

### Critical Alerts Requiring Immediate Triage
1. SID 9000003: Cobalt Strike JA3 from 10.10.5.12 to 203.0.113.50 (189 alerts)
2. SID 9000002: DNS tunneling from 10.10.3.45 to suspect-domain.xyz (98 alerts)

评论

支持 Markdown