# Configuring Suricata For Network Monitoring

> 部署和配置 Suricata IDS/IPS，使用 Emerging Threats 规则集、EVE JSON 日志记录和自定义规则， 进行实时网络流量检测（intrusion detection）、威胁检测，并与 SIEM 平台集成实现集中化安全监控。

- Skill: `killvxk/configuring-suricata-for-network-monitoring` (Agent Skill, multi-file: 4 files)
- Install (CLI): `npx skillmds@latest add killvxk/configuring-suricata-for-network-monitoring`
- Raw SKILL.md: https://api.skillmd.com/api/skills/killvxk/configuring-suricata-for-network-monitoring/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- License: Apache-2.0
- Author: killvxk (https://skillmd.com/u/killvxk)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/killvxk/configuring-suricata-for-network-monitoring

---

# 配置 Suricata 进行网络监控

## 适用场景

- 部署支持多线程数据包处理的高性能 IDS/IPS，用于 10 Gbps 以上的网络链路
- 使用对 HTTP、TLS、DNS、SMB 等协议感知的检测进行网络流量监控
- 生成结构化 EVE JSON 日志，无需自定义解析器即可直接接入 SIEM
- 以内联（IPS）模式运行，在网络关键节点主动阻断恶意流量
- 将基于签名的检测与协议异常检测和文件提取相结合

**不适用于**：作为无配套控制措施的独立安全解决方案、在没有 TLS 解密能力的情况下检测加密流量，或在 CPU/内存不足以处理预期流量量的系统上运行。

## 前置条件

- 通过 PPA 或源码安装 Suricata 7.0+（`suricata --build-info` 验证）
- 网络接口接入 SPAN 端口、分路器或内联网桥进行流量捕获
- 支持 AF_PACKET 或 DPDK 进行高性能数据包捕获
- Emerging Threats Open 或 Pro 规则集订阅（或通过 oinkcode 使用 Snort Talos 规则）
- suricata-update 工具进行自动化规则管理
- Elasticsearch/Kibana 或 Splunk 用于日志分析和可视化

## 工作流程

### 步骤 1：安装 Suricata 及依赖项

```bash
# 从 PPA 安装（Ubuntu/Debian）
sudo add-apt-repository ppa:oisf/suricata-stable
sudo apt update
sudo apt install -y suricata suricata-update jq

# 验证安装
suricata --build-info | grep -E "Version|AF_PACKET|NFQueue"

# 或从源码安装以获取最新功能
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：配置网络接口

```bash
# 禁用网卡卸载功能
sudo ethtool -K eth1 gro off lro off tso off gso off rx off tx off sg off

# 将接口设置为混杂模式
sudo ip link set eth1 promisc on

# 对于高性能部署，配置多线程的 AF_PACKET
# 编辑 /etc/suricata/suricata.yaml
```

### 步骤 3：配置 suricata.yaml

```yaml
# /etc/suricata/suricata.yaml（关键部分）

# 网络变量
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: /var/lib/suricata/rules
rule-files:
  - suricata.rules

# 高性能 AF_PACKET 配置
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 日志（主要输出格式）
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 日志
  - pcap-log:
      enabled: yes
      filename: alert-%n.pcap
      limit: 100mb
      max-files: 50
      mode: normal
      use-stream-depth: no
      honor-pass-rules: no

# 流引擎设置
stream:
  memcap: 512mb
  checksum-validation: no
  reassembly:
    memcap: 1gb
    depth: 1mb
    toserver-chunk-size: 2560
    toclient-chunk-size: 2560

# 检测引擎
detect:
  profile: high
  custom-values:
    toclient-groups: 200
    toserver-groups: 200
  sgh-mpm-context: auto
  inspection-recursion-limit: 3000

# 协议检测和解析
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：下载和管理规则集

```bash
# 使用 suricata-update 更新 Suricata 规则
sudo suricata-update

# 启用额外的规则源
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

# 更新所有已启用的源
sudo suricata-update

# 检查规则统计
sudo suricata-update list-sources --enabled
wc -l /var/lib/suricata/rules/suricata.rules

# 禁用嘈杂的规则
sudo tee /etc/suricata/disable.conf << 'EOF'
# 禁用过于宽泛的规则
2100498
2013028
2210000-2210050
group:emerging-policy.rules
EOF

# 创建自定义本地规则
sudo tee /etc/suricata/rules/local.rules << 'EOF'
# 检测反向 Shell 连接
alert tcp $HOME_NET any -> $EXTERNAL_NET 4444 (msg:"LOCAL 反向 Shell 端口 4444"; flow:established,to_server; content:"|2f 62 69 6e 2f|"; sid:9000001; rev:1; classtype:trojan-activity; priority:1;)

# 通过查询长度检测 DNS 隧道
alert dns $HOME_NET any -> any any (msg:"LOCAL DNS 隧道长查询"; dns.query; content:"."; offset:50; sid:9000002; rev:1; classtype:policy-violation; priority:2;)

# 通过可疑 JA3 哈希检测 TLS（Cobalt Strike 默认值）
alert tls $HOME_NET any -> $EXTERNAL_NET any (msg:"LOCAL Cobalt Strike JA3 哈希"; ja3.hash; content:"72a589da586844d7f0818ce684948eea"; sid:9000003; rev:1; classtype:trojan-activity; priority:1;)

# 检测 SSH 暴力破解
alert ssh $EXTERNAL_NET any -> $HOME_NET 22 (msg:"LOCAL SSH 暴力破解尝试"; flow:to_server; threshold:type both, track by_src, count 10, seconds 60; sid:9000004; rev:1; classtype:attempted-admin; priority:2;)

# 检测通过 HTTP POST 的数据外泄（大型上传）
alert http $HOME_NET any -> $EXTERNAL_NET any (msg:"LOCAL 大型 HTTP POST 上传"; 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

# 将本地规则添加到配置
echo "  - local.rules" | sudo tee -a /etc/suricata/suricata.yaml
```

### 步骤 5：部署和验证

```bash
# 验证配置
sudo suricata -T -c /etc/suricata/suricata.yaml -v

# 以 IDS 模式运行 Suricata
sudo suricata -c /etc/suricata/suricata.yaml --af-packet=eth1 -D

# 或以 IPS 模式运行（使用 NFQueue 内联）
# 首先配置 iptables 将流量发送到 NFQueue
# sudo iptables -I FORWARD -j NFQUEUE --queue-num 0
# sudo suricata -c /etc/suricata/suricata.yaml -q 0 -D

# 创建 systemd 服务
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

# 使用已知签名进行测试
curl http://testmynids.org/uid/index.html
# 应触发 ET GPL 规则

# 验证生成了告警
sudo tail -f /var/log/suricata/eve.json | jq 'select(.event_type=="alert")'
```

### 步骤 6：与 SIEM 集成并监控

```bash
# 使用 jq 解析 EVE JSON 进行快速分析
# 前 10 个告警
cat /var/log/suricata/eve.json | jq -r 'select(.event_type=="alert") | .alert.signature' | sort | uniq -c | sort -rn | head -10

# 从告警中提取 IOC
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 指纹分析
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 查询分析
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

# 配置 Filebeat 进行 Elastic 集成
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

# 监控 Suricata 性能
cat /var/log/suricata/eve.json | jq 'select(.event_type=="stats") | .stats.capture' | tail -1
# 检查丢包：kernel_drops 应为 0
```

## 核心概念

| 术语 | 定义 |
|------|------------|
| **EVE JSON** | Suricata 的主要日志格式，为告警、协议元数据、流记录和统计信息生成结构化 JSON 事件 |
| **AF_PACKET** | Suricata 用于高性能流量捕获的 Linux 内核数据包捕获机制，支持内核旁路 |
| **JA3/JA3S** | 从 TLS Client Hello 和 Server Hello 参数创建哈希值的 TLS 指纹方法，用于识别应用程序和恶意软件 |
| **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。他们需要协议级元数据日志用于威胁狩猎（threat hunting）、基于签名的已知威胁告警，以及用于检测恶意软件 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. 配置带有 community-id、扩展 HTTP/TLS/DNS 元数据和文件哈希（MD5 + SHA256）的 EVE JSON 日志
4. 为 TLS 和 SSH 流量分析启用 JA3 和 HASSH 指纹
5. 为特定于组织的威胁编写自定义规则：已知恶意 JA3 哈希、对 DGA 域名的 DNS 查询、向不常见目标的大型数据上传
6. 通过 Filebeat 的 Suricata 模块与 Elastic 集成，部署预构建的 Kibana 仪表板实现实时可见性
7. 在 2 周基线期内调优规则，禁用误报生成器并调整阈值

**常见陷阱**：
- 未分配足够的 CPU 线程，导致峰值流量时丢包
- 在不调优的情况下启用所有可用规则，使分析师被误报淹没
- 忘记禁用网卡卸载功能，导致校验和错误和漏检
- 未启用 community-id，导致难以将 Suricata 事件与 Zeek 或其他工具关联

## 输出格式

```
## Suricata IDS 部署报告

**传感器**: suricata-gw-01 (10.10.1.251)
**接口**: eth1（来自边界路由器的 SPAN）
**配置**: /etc/suricata/suricata.yaml
**工作线程**: 14 个 AF_PACKET 线程
**活跃规则**: 35,247 条（ET Open + 自定义）

### 性能指标（24 小时）

| 指标 | 值 |
|--------|-------|
| 已处理数据包 | 847,293,421 |
| 内核丢包 | 0（0.000%） |
| 生成告警 | 1,247 |
| 触发的唯一签名 | 89 |
| 观察到的 JA3 指纹 | 342 个唯一值 |
| 已提取文件 | 2,847 |

### 前 10 个告警签名

| 数量 | SID | 签名 | 严重性 |
|-------|-----|-----------|----------|
| 312 | 2024897 | ET POLICY curl User-Agent 出站 | 3 |
| 189 | 9000003 | LOCAL Cobalt Strike JA3 哈希 | 1 |
| 145 | 2028765 | ET SCAN Nmap SYN 扫描 | 2 |
| 98 | 9000002 | LOCAL DNS 隧道长查询 | 2 |

### 需要立即分诊的严重告警
1. SID 9000003：10.10.5.12 到 203.0.113.50 的 Cobalt Strike JA3（189 个告警）
2. SID 9000002：10.10.3.45 到 suspect-domain.xyz 的 DNS 隧道（98 个告警）
```

