Deploys and configures Suricata IDS/IPS with Emerging Threats rules, EVE JSON logging, and custom rules for real-time network intrusion detection, threat monitoring, and SIEM integration on high-speed networks.
npx claudepluginhub killvxk/cybersecurity-skills-zhThis skill uses the workspace's default tool permissions.
- 部署支持多线程数据包处理的高性能 IDS/IPS,用于 10 Gbps 以上的网络链路
Deploys and configures Suricata IDS/IPS with Emerging Threats rulesets, EVE JSON logging, and custom rules for real-time network threat detection and SIEM integration on high-speed links.
Deploys and configures Suricata IDS/IPS on Linux with Emerging Threats rules, EVE JSON logging, and custom rules for real-time network threat detection and SIEM integration.
Deploys and configures Suricata as network IPS on Linux using custom rules, Emerging Threats sets, NFQUEUE inline mode, and rule management for real-time threat blocking.
Share bugs, ideas, or general feedback.
不适用于:作为无配套控制措施的独立安全解决方案、在没有 TLS 解密能力的情况下检测加密流量,或在 CPU/内存不足以处理预期流量量的系统上运行。
suricata --build-info 验证)# 从 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
# 禁用网卡卸载功能
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
# /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
# 使用 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
# 验证配置
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")'
# 使用 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 | 官方规则管理工具,下载、合并和管理多个规则集,支持启用/禁用控制 |
场景背景:一家技术公司需要在处理 10 Gbps 流量的互联网出口点部署 IDS。他们需要协议级元数据日志用于威胁狩猎(threat hunting)、基于签名的已知威胁告警,以及用于检测恶意软件 C2 通信的 JA3 指纹。告警必须接入其 Elastic SIEM。
方法:
常见陷阱:
## 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 个告警)