Suricata配置之YAML
目录
- Suricata配置详解(一)
- 引言
- 基本配置
- 1. 最大待处理数据包(max-pending-packets)
- 2. 运行模式(runmodes)
- 3. 默认数据包大小(default-packet-size)
- 4. 用户和组(User and group)
- 5. PID文件(PID File)
- 6. 动作顺序(Action-order)
- 7. 数据包警报队列设置(Packet alert queue settings)
- 高级配置
- 1. 分割配置(Splitting configuration in multiple files)
- 2. 事件输出(Event output)
- 默认日志目录(Default logging directory)
- 统计信息(Stats)
- 3. 数据包日志(Packet log)
- 4. 详细警报日志(Verbose Alerts Log)
- 5. 文件存储(File-store)
- 检测引擎配置
- 1. 检测配置(Inspection configuration)
- 2. 预过滤引擎(Prefilter Engines)
- 3. 阈值化设置(Thresholding Settings)
- 4. 模式匹配器设置(Pattern matcher settings)
- 线程配置
- IP碎片重组
- 流和流处理
- 1. 流设置(Flow Settings)
- 2. 流超时(Flow Time-Outs)
- 3. 流引擎(Stream-engine)
- 主机跟踪
- 应用层解析器
- 1. ASN.1最大帧数(Asn1_max_frames)
- 2. FTP
- 3. HTTP(libhtp)
- 4. SMB
- 5. HTTP2
- 6. SSL/TLS
- 引擎日志记录
- 数据包获取
- 1. DPDK
- 2. Pf-ring
- 3. NFQ
- 4. Ipfw
- 规则
- 1. 规则文件(Rule Files)
- 2. 阈值文件(Threshold-file)
- 3. 分类文件(Classifications)
- 4. 规则变量(Rule-vars)
- 5. 主机操作系统策略(Host-os-policy)
- 引擎分析和性能分析
- 1. 引擎分析(Engine analysis)
- 2. 规则性能分析(Rule and Packet Profiling settings)
- 3. 数据包性能分析(Packet Profiling)
- 解码器
- 1. Teredo
- 2. 递归层级(Recursion Level)
- 高级选项
- 1. 堆栈跟踪(stacktrace)
Suricata配置详解(一)
引言
Suricata是一款开源的网络入侵检测系统(IDS)和入侵防御系统(IPS)。本文档将详细介绍Suricata的配置文件suricata.yaml
,帮助读者更好地理解和配置Suricata。
基本配置
1. 最大待处理数据包(max-pending-packets)
max-pending-packets
设置确定了Suricata同时处理的数据包数量。取值范围从1个数据包到数万或数十万个数据包不等。
max-pending-packets: 1024
2. 运行模式(runmodes)
Suricata支持多种运行模式,包括single
、workers
和autofp
。workers
模式性能最佳,autofp
模式适用于某些入侵防御系统(IPS)设置。
runmode: autofp
3. 默认数据包大小(default-packet-size)
default-packet-size
选项用于设置网络上数据包的大小。处理大数据包时,性能会有所下降。
default-packet-size: 1514
4. 用户和组(User and group)
可以将运行Suricata的用户和组设置为suri
。
run-as:
user: suri
group: suri
5. PID文件(PID File)
当Suricata运行在daemon模式时,此选项设置PID文件的名称。
pid-file: /var/run/suricata.pid
6. 动作顺序(Action-order)
Suricata中签名的动作属性包括Pass、Drop、Reject、Alert四种动作类型。默认处理顺序为Pass、Drop、Reject、Alert。
action-order:
- pass
- drop
- reject
- alert
7. 数据包警报队列设置(Packet alert queue settings)
可以配置用于追加每个数据包触发的警报的警报队列大小。默认值为15。
packet-alert-max: 15
高级配置
1. 分割配置(Splitting configuration in multiple files)
Suricata配置文件suricata.yaml
可以拆分成多个单独文件,通过include
和!include
关键字实现。
# outputs.yaml
outputs:
- fast:
enabled: yes
filename: fast.log
append: yes
# suricata.yaml
outputs: !include outputs.yaml
2. 事件输出(Event output)
默认日志目录(Default logging directory)
在/var/log/suricata
目录中,将存储Suricata的所有输出。
default-log-dir: /var/log/suricata
统计信息(Stats)
引擎统计信息(如数据包计数器、内存使用计数器等)的记录方式多样,默认启用单独的文本日志stats.log
和EVE记录类型stats
。
stats:
enabled: yes
interval: 8
3. 数据包日志(Packet log)
利用pcap-log
选项,Suricata能将接收的数据包存于名为log.pcap
的日志文件,方便随时查看。
pcap-log:
enabled: yes
filename: log.pcap
4. 详细警报日志(Verbose Alerts Log)
这是一种日志类型,提供有关警报的补充信息。
alert-debug:
enabled: no
filename: alert-debug.log
append: yes
5. 文件存储(File-store)
file-store
关键字可以设置将日志信息存储到磁盘上。
file-store:
version: 2
enabled: no
dir: filestore
write-fileinfo: yes
force-filestore: yes
stream-depth: 0
max-open-files: 1000
force-hash: [sha1, md5]
检测引擎配置
1. 检测配置(Inspection configuration)
检测引擎会构建内部签名组,Suricata加载的签名用于与网络流量进行对比。
detect:
profile: medium
custom-values:
toclient-groups: 2
toserver-groups: 25
sgh-mpm-context: auto
inspection-recursion-limit: 3000
stream-tx-log-limit: 4
guess-applayer-tx: no
2. 预过滤引擎(Prefilter Engines)
预过滤是从每条规则中提取一个条件添加到预过滤器中,然后统一进行检查。
detect:
prefilter:
default: mpm
3. 阈值化设置(Thresholding Settings)
通过一个中央哈希表来跟踪不同类型的阈值。
detect:
thresholds:
hash-size: 16384
memcap: 16mb
4. 模式匹配器设置(Pattern matcher settings)
多模式匹配器(MPM)是Suricata检测引擎的一部分,能够同时搜索多个模式。
detect:
mpm-algo: hs
线程配置
Suricata是多线程的,使用多个CPU/CPU内核,因此可以同时处理大量网络数据包。
threading:
cpu-affinity:
- management-cpu-set:
cpu: [0]
- receive-cpu-set:
cpu: [0]
- worker-cpu-set:
cpu: ["all"]
mode: exclusive
prio:
low: [0]
medium: [1-2]
high: [3]
default: medium
- verdict-cpu-set:
cpu: [0]
prio: default: high
IP碎片重组
偶尔,网络数据包会出现碎片化的情况。Suricata的碎片重组引擎会将重组后的数据包发送给Suricata的其他部分进行处理。
defrag:
memcap: 32mb
memcap-policy: ignore
hash-size: 65536
trackers: 65535
max-frags: 65535
prealloc: yes
timeout: 60
流和流处理
1. 流设置(Flow Settings)
在Suricata中,流(Flows)非常重要。它们在Suricata内部组织数据的方式中起着关键作用。
flow:
memcap: 33554432
memcap-policy: bypass
hash-size: 65536
prealloc: 10000
2. 流超时(Flow Time-Outs)
Suricata将流保存在内存中的时长由流超时时间决定。
flow-timeouts:
default:
new: 30
established: 300
emergency-new: 10
emergency-established: 100
tcp:
new: 60
established: 3600
closed: 120
emergency-new: 10
emergency-established: 300
emergency-closed: 20
udp:
new: 30
established: 300
emergency-new: 10
emergency-established: 100
icmp:
new: 30
established: 300
emergency-new: 10
emergency-established: 100
3. 流引擎(Stream-engine)
流引擎用于跟踪TCP连接,它由两部分组成:流跟踪引擎和重组引擎。
stream:
memcap: 64mb
memcap-policy: ignore
checksum-validation: yes
prealloc-sessions: 32768
midstream: false
midstream-policy: drop-flow
async-oneside: false
inline: no
drop-invalid: yes
主机跟踪
Host表用于跟踪每个IP地址。
host:
hash-size: 4096
prealloc: 1000
memcap: 32mb
应用层解析器
1. ASN.1最大帧数(Asn1_max_frames)
Suricata最多会检查256个ASN.1帧。
asn1-max-frames: 256
2. FTP
FTP应用层解析器默认处于启用状态,且采用动态协议检测机制。
ftp:
enabled: yes
max-line-length: 4kb
3. HTTP(libhtp)
Suricata使用Libhtp库来解析HTTP会话。
libhtp:
default-config:
personality: IDS
request-body-limit: 3072
response-body-limit: 3072
server-config:
- apache:
address: [192.168.1.0/24, 127.0.0.0/8, "::1"]
personality: Apache_2_2
request-body-limit: 0
response-body-limit: 0
- iis7:
address:
- 192.168.0.0/24
- 192.168.10.0/24
personality: IIS_7_0
request-body-limit: 4096
response-body-limit: 8192
4. SMB
SMB解析器将解析通过TCP传输的SMB协议的第1、2和3版本。
smb:
enabled: yes
detection-ports:
dp: 139, 445
max-read-size: 8mb
max-write-size: 1mb
max-read-queue-size: 16mb
max-read-queue-cnt: 16
max-write-queue-size: 16mb
max-write-queue-cnt: 16
5. HTTP2
HTTP2有两个可以自定义的参数。
http2:
max-table-size: 4096
max-streams: 1000
6. SSL/TLS
SSL/TLS解析器跟踪加密的SSLv2、SSLv3、TLSv1、TLSv1.1和TLSv1.2的会话。
tls:
enabled: yes
detection-ports:
dp: 443
encryption-handling: default
引擎日志记录
引擎日志记录系统会记录有关Suricata引擎在启动、运行时以及关闭期间的应用程序信息。
logging:
default-log-level: notice
default-log-format: "[%i] %t - (%f:%l) <%d> (%n) -"
outputs:
- console:
enabled: yes
level: notice
- file:
enabled: no
filename: suricata.log
level: info
format: "[%i - %m] %z %d: %S: %M"
- syslog:
enabled: no
facility: local5
format: "[%i] <%d> -- "
level: notice
数据包获取
1. DPDK
数据平面开发套件(DPDK)是一个用于在多种不同CPU架构上运行的数据平面应用程序中实现快速数据包处理的框架。
dpdk:
eal-params:
proc-type: primary
allow: ["0000:3b:00.0", "0000:3b:00.1"]
interfaces:
- interface: 0000:3b:00.0
threads: auto
promisc: true
multicast: true
checksum-checks: true
checksum-checks-offload: true
mtu: 1500
mempool-size: 65535
mempool-cache-size: 257
rx-descriptors: 1024
tx-descriptors: 1024
copy-mode: none
copy-iface: none
2. Pf-ring
Pf_ring是一个旨在提高数据包捕获性能的库。
pfring:
interface: eth0
cluster-id: 99
cluster-type: cluster_inner_flow_5_tuple
3. NFQ
在iptables规则中使用NFQUEUE,会将数据包发送到Suricata。
nfq:
mode: accept
repeat-mark: 1
repeat-mask: 1
route-queue: 2
4. Ipfw
Suricata支持FreeBSD操作系统上的ipfw。
ipfw:
ipfw-reinjection-rule-number: 5500
规则
1. 规则文件(Rule Files)
Suricata默认设置为由Suricata-Update管理的规则。
default-rule-path: /var/lib/suricata/rules
rule-files:
- suricata.rules
- /etc/suricata/rules/custom.rules
2. 阈值文件(Threshold-file)
在这个选项中,你可以指定阈值文件的存储目录。
threshold-file: /etc/suricata/threshold.config
3. 分类文件(Classifications)
分类文件是一种能明确规则目的的文件。
classification-file: /etc/suricata/classification.config
4. 规则变量(Rule-vars)
有一些变量可以在规则里使用。
vars:
address-groups:
HOME_NET: "[192.168.0.0/16,10.0.0.0/8,172.16.0.0/12]"
EXTERNAL_NET: any
HTTP_SERVERS: "$HOME_NET"
SMTP_SERVERS: "$HOME_NET"
SQL_SERVERS: "$HOME_NET"
DNS_SERVERS: "$HOME_NET"
TELNET_SERVERS: "$HOME_NET"
AIM_SERVERS: any
5. 主机操作系统策略(Host-os-policy)
操作系统处理分片数据包和数据流的方式各有不同。
host-os-policy:
windows: [0.0.0.0/0]
bsd: []
bsd-right: []
old-linux: []
linux: [10.0.0.0/8, 192.168.1.100, "8762:2352:6241:7245:E000:0000:0000:0000"]
old-solaris: []
solaris: ["::1"]
hpux10: []
hpux11: []
irix: []
macos: []
vista: []
windows2k3: []
引擎分析和性能分析
1. 引擎分析(Engine analysis)
“引擎分析”选项为签名编写者提供了有关Suricata在内部如何组织签名的信息。
engine-analysis:
rules-fast-pattern: yes
2. 规则性能分析(Rule and Packet Profiling settings)
规则性能分析是Suricata的一部分功能,用于确定规则在执行时的资源耗费程度。
profiling:
rules:
enabled: yes
3. 数据包性能分析(Packet Profiling)
数据包性能分析信息将存储在名为packet-stats.log
的文件中。
packets:
enabled: yes
filename: packet_stats.log
append: yes
csv:
enabled: no
filename: packet_stats.csv
解码器
1. Teredo
可以禁用Teredo解码器。
decoder:
teredo:
enabled: true
ports: $TEREDO_PORTS
2. 递归层级(Recursion Level)
通过递归层级进行的流匹配功能是可以被禁用的。
decoder:
recursion-level:
use-for-tracking: true
高级选项
1. 堆栈跟踪(stacktrace)
当有信号意外终止Suricata时,会显示诊断性的堆栈跟踪信息。
logging:
# Requires libunwind to be available when Suricata is configured and built.
# If a signal unexpectedly terminates Suricata, displays a brief diagnostic
# message with the offending stacktrace if enabled.
#stacktrace-on-signal: on