14.1. Suricata.yaml

Suricata 使用 Yaml 格式进行配置。源代码中包含的 Suricata.yaml 文件是 Suricata 的示例配置文件。本文将解释每个选项。

在 YAML 文件的顶部,你会看到 % YAML 1.1。Suricata 读取文件并将其识别为 YAML 格式。

14.1.1. 最大待处理数据包数

通过 max-pending-packets 设置,你可以设定 Suricata 允许同时处理的数据包数量。这个值可以从一个数据包到数万/数十万个数据包不等。这是在高性能和更多内存(RAM)使用之间的权衡。处理大量数据包会提高性能但消耗更多内存。处理少量数据包会降低性能但减少内存使用。在处理数据包数量较少的情况下,如果拥有多个 CPU/CPU 核心,可能会导致无法充分利用计算机的全部能力。(例如:使用一个核心而其他三个核心在等待处理数据包。)

max-pending-packets: 1024

14.1.2. 运行模式

默认情况下,runmode 选项是禁用的。通过 runmodes 设置,你可以设定想要使用的运行模式。要查看所有可用的运行模式,请在命令行输入 --list-runmodes。更多信息请参阅 运行模式

runmode: autofp

14.1.3. 默认数据包大小

对于 max-pending-packets 选项,Suricata 需要在内存中保存数据包。通过 default-packet-size 选项,你可以设置网络中数据包的大小。有时可能需要处理更大的数据包。引擎仍然可以处理这些更大的数据包,但处理它们会降低性能。

default-packet-size: 1514

14.1.4. 用户和组

可以设置运行 Suricata 的用户和组:

run-as:
  user: suri
  group: suri

14.1.5. PID 文件

此选项设置 Suricata 在守护进程模式下运行时 PID 文件的名称。该文件记录 Suricata 的进程 ID。

pid-file: /var/run/suricata.pid

Note

此配置文件选项仅在守护进程模式下运行时设置 PID 文件。要在非守护进程模式下强制创建 PID 文件,请使用 --pidfile 命令行选项。

此外,如果运行多个 Suricata 进程,每个进程需要指定不同的 pid-file 位置。

14.1.6. 动作顺序

所有签名都有不同的属性。其中之一是 Action 属性,它决定了签名匹配时会发生什么。有四种类型的 Action。以下是签名匹配并包含其中一种 Action 时的行为摘要:

  1. 通过 (Pass)

如果签名匹配且包含 pass,Suricata 停止扫描该数据包并跳过所有规则的末尾(仅针对当前数据包)。如果签名在 TCP 连接上匹配,整个流将被通过,但流的详细信息仍会被记录。

  1. 丢弃 (Drop)

这仅涉及 IPS/内联模式。如果程序找到匹配的签名且包含 drop,它会立即停止。数据包不会被进一步发送。缺点:接收方不会收到任何关于发生了什么的提示,导致超时(特别是 TCP 协议)。Suricata 会为此数据包生成警报。

  1. 拒绝 (Reject)

这是对数据包的主动拒绝。接收方和发送方都会收到一个拒绝数据包。有两种类型的拒绝数据包会自动选择。如果违规数据包涉及 TCP,将发送一个 Reset 数据包。对于所有其他协议,将发送一个 ICMP 错误数据包。Suricata 也会生成警报。在内联/IPS 模式下,违规数据包也会像 'drop' 动作一样被丢弃。

  1. 警报 (Alert)

如果签名匹配且包含 alert,数据包将像任何其他非威胁数据包一样被处理,但 Suricata 会为此生成一个警报。只有系统管理员可以注意到此警报。

内联/IPS 可以通过两种方式阻止网络流量。一种是通过 drop,另一种是通过 reject。

规则将按照它们在文件中出现的顺序加载。但它们将以不同的顺序进行处理。签名有不同的优先级。最重要的签名将首先被扫描。可以更改优先级顺序。默认顺序是:pass, drop, reject, alert。

action-order:
 - pass
 - drop
 - reject
 - alert

这意味着 pass 规则在 drop 规则之前被考虑,drop 规则在 reject 规则之前被考虑,依此类推。

14.1.7. 数据包警报队列设置

可以配置用于附加由每个数据包触发的警报队列的大小。

这将影响感知到针对给定数据包匹配的警报数量。默认值为 15。如果提供无效设置或未提供值,引擎将回退到默认值。

#定义可以针对同一数据包触发的最大可能警报数。默认为 15
packet-alert-max: 15

我们建议你使用此设置的默认值,除非你看到大量被丢弃的警报(alert_queue_overflow)—— 更多详情请参阅 丢弃和抑制的警报统计 部分。

14.1.7.1. 对引擎行为的影响

在内部,Suricata 引擎用具有自己的警报队列的数据结构表示每个数据包。队列的最大大小由 packet-alert-max 定义。同一规则可以被同一数据包多次触发。只要警报队列中还有空间,这些警报就会被附加。

具有 noalert 关键字的规则将被检查 —— 如果它们的签名有必须应用于数据包或流的动作,则会被抑制。它们对最终的警报队列没有影响。

规则按优先级排队:如果 Suricata 达到给定数据包的 ``packet-alert-max``(即数据包警报队列溢出),高优先级规则可能会被保留,而低优先级规则可能会被替换。

14.1.7.1.1. 数据包警报队列溢出

一旦警报队列达到最大大小,我们可能面临数据包警报队列溢出,因此新警报只有在它们的规则具有更高的优先级 ID(这是引擎分配的内部 ID,不是签名 ID)时才会被附加。

这可能在两种不同的情况下发生:

  • 高优先级规则在低优先级规则之后触发:低优先级规则在队列中被替换;

  • 低优先级规则触发:规则直接被丢弃。

Note

这种行为并不意味着在 IPS 模式下触发的 drop 规则的动作会被忽略。

14.1.7.2. 丢弃和抑制的警报统计

上述两种场景都将被记录为 detect.alert_queue_overflow 在统计日志中(stats.log 和 eve-log 的 stats 事件)。

noalert 规则匹配时,它们会以 detect.alerts_suppressed 的形式出现在统计日志中。

Date: 4/6/2022 -- 17:18:08 (uptime: 0d, 00h 00m 00s)
------------------------------------------------------------------------------------
Counter                                       | TM Name                   | Value
------------------------------------------------------------------------------------
detect.alert                                  | Total                     | 3
detect.alert_queue_overflow                   | Total                     | 4
detect.alerts_suppressed                      | Total                     | 1

在这个来自 stats.log 的示例中,我们读到生成了 8 个警报:3 个被保留在数据包队列中,4 个由于数据包达到警报队列的最大大小而被丢弃,1 个由于来自 noalert 规则而被抑制。

14.1.8. 将配置拆分为多个文件

一些用户可能希望将他们的 suricata.yaml 文件拆分为多个单独的文件,这可以通过 'include' 和 '!include' 关键字实现。第一个示例是将 outputs 部分的内容存储到 outputs.yaml 中。

# outputs.yaml
- fast
    enabled: yes
    filename: fast.log
    append: yes

...
# suricata.yaml
...

outputs: !include outputs.yaml

...

第二种场景是将多个部分迁移到不同的 YAML 文件中。

# host_1.yaml

max-pending-packets: 2048

outputs:
    - fast
        enabled: yes
        filename: fast.log
        append: yes
# suricata.yaml

include: host_1.yaml

...

如果在 include 语句之后重新定义了相同的部分(例如 outputs),它将覆盖包含的文件。因此,文档末尾的任何 include 语句都将覆盖已配置的部分。

14.1.9. 事件输出

14.1.9.1. 默认日志目录

在 /var/log/suricata 目录中,将存储 Suricata 的所有输出(警报和事件)。

default-log-dir: /var/log/suricata

可以通过输入 -l 命令行参数或直接在 Yaml 中更改目录来覆盖此目录。要使用 -l 命令行参数更改它,请输入以下内容:

suricata -c suricata.yaml -i eth0 -l /var/log/suricata-logs/

14.1.9.2. 统计

引擎统计信息(如数据包计数器、内存使用计数器等)可以通过多种方式记录。默认情况下启用单独的文本日志 'stats.log' 和 EVE 记录类型 'stats'。

统计信息有全局配置和每个记录器的配置。这里记录的是全局配置。

# 全局统计配置
stats:
  enabled: yes
  # interval 字段(以秒为单位)控制记录器被调用的间隔。
  interval: 8
  # 将解码事件添加为统计信息。
  #decoder-events: true
  # 统计信息中的解码事件前缀。之前是 'decoder',但这会导致 eve.stats 记录中缺少事件。参见 issue #2225。
  #decoder-events-prefix: "decoder.event"
  # 将流事件添加为统计信息。
  #stream-events: false
  # 异常策略统计计数器选项
  # (注意:如果异常策略为 ignore,则不记录计数器)
  exception-policy:
    #per-app-proto-errors: false  # 默认:false。True 将为每个应用协议记录错误。警告:非常详细

可以在此处启用或禁用统计信息。

统计信息以 interval 为间隔进行转储。将此值设置为低于 3 或 4 秒没有意义,因为线程在内部是如何同步的。

解码层生成的解码事件可以创建每种事件类型的计数器。默认情况下启用此行为。可以将 decoder-events 选项设置为 false 来禁用。

在 4.1.x 版本中,常规解码计数器和解码事件计数器之间存在命名冲突。这导致相当数量的解码事件计数器未显示在 EVE.stats 记录中。为了解决这个问题而不破坏现有设置,添加了一个配置选项 decoder-events-prefix,将解码事件的名称从 decoder.<proto>.<event> 更改为 decoder.event.<proto>.<event>。在 5.0 版本中,这成为默认设置。参见 issue 2225

类似于 decoder-events 选项,stream-events 选项控制是否也将流事件添加为计数器。默认情况下禁用。

如果启用了任何异常策略,则会记录统计计数器。要控制应用层协议错误的详细程度,请将 per-app-proto-errors 保持为 false。

14.1.9.3. 输出

有几种类型的输出。一般结构如下:

outputs:
  - fast:
    enabled: yes
    filename: fast.log
    append: yes/no

启用所有日志会显著降低性能并占用更多磁盘空间,因此只启用你需要的输出。

14.1.9.4. 基于行的警报日志(fast.log)

此日志包含由单行组成的警报。以下是 fast.log 文件中一行的示例:

10/05/10-10:08:59.667372  [**] [1:2009187:4] ET WEB_CLIENT ACTIVEX iDefense
  COMRaider ActiveX Control Arbitrary File Deletion [**] [Classification: Web
  Application Attack] [Priority: 3] {TCP} xx.xx.232.144:80 -> 192.168.1.4:56068
-fast:                    #日志名称。
   enabled:yes            #此日志已启用。设置为 'no' 以禁用。
   filename: fast.log     #默认日志目录中的文件名。
   append: yes/no         #如果此选项设置为 yes,则在重新启动 Suricata 时不会覆盖最后一个填充的 fast.log 文件。

14.1.9.5. Eve(可扩展事件格式)

这是警报和事件的 JSON 输出。它便于与第三方工具(如 logstash)集成。

outputs:
  # Extensible Event Format (nicknamed EVE) event log in JSON format
  - eve-log:
      enabled: yes
      filetype: regular #regular|syslog|unix_dgram|unix_stream|redis
      filename: eve.json
      # Enable for multi-threaded eve.json output; output files are amended with
      # an identifier, e.g., eve.9.json
      #threaded: false
      # Specify the amount of buffering, in bytes, for
      # this output type. The default value 0 means "no
      # buffering".
      #buffer-size: 0
      #prefix: "@cee: " # prefix to prepend to each log entry
      # the following are valid when type: syslog above
      #identity: "suricata"
      #facility: local5
      #level: Info ## possible levels: Emergency, Alert, Critical,
                   ## Error, Warning, Notice, Info, Debug
      #ethernet: no  # log ethernet header in events when available
      #redis:
      #  server: 127.0.0.1
      #  port: 6379
      #  async: true ## if redis replies are read asynchronously
      #  mode: list ## possible values: list|lpush (default), rpush, channel|publish, xadd|stream
      #             ## lpush and rpush are using a Redis list. "list" is an alias for lpush
      #             ## publish is using a Redis channel. "channel" is an alias for publish
      #             ## xadd is using a Redis stream. "stream" is an alias for xadd
      #  key: suricata ## string denoting the key/channel/stream to use (default to suricata)
      #  stream-maxlen: 100000        ## Automatically trims the stream length to at most
                                      ## this number of events. Set to 0 to disable trimming.
                                      ## Only used when mode is set to xadd/stream.
      #  stream-trim-exact: false     ## Trim exactly to the maximum stream length above.
                                      ## Default: use inexact trimming (inexact by a few
                                      ## tens of items)
                                      ## Only used when mode is set to xadd/stream.
      # Redis pipelining set up. This will enable to only do a query every
      # 'batch-size' events. This should lower the latency induced by network
      # connection at the cost of some memory. There is no flushing implemented
      # so this setting should be reserved to high traffic Suricata deployments.
      #  pipelining:
      #    enabled: yes ## set enable to yes to enable query pipelining
      #    batch-size: 10 ## number of entries to keep in buffer

      # Include top level metadata. Default yes.
      #metadata: no

      # include the name of the input pcap file in pcap file processing mode
      pcap-file: false

      # Community Flow ID
      # Adds a 'community-id' field to EVE records. These are meant to give
      # records a predictable flow ID that can be used to match records to
      # output of other tools such as Zeek (Bro).
      #
      # Takes a 'seed' that needs to be same across sensors and tools
      # to make the id less predictable.

      # enable/disable the community id feature.
      community-id: false
      # Seed value for the ID output. Valid values are 0-65535.
      community-id-seed: 0

      # HTTP X-Forwarded-For support by adding an extra field or overwriting
      # the source or destination IP address (depending on flow direction)
      # with the one reported in the X-Forwarded-For HTTP header. This is
      # helpful when reviewing alerts for traffic that is being reverse
      # or forward proxied.
      xff:
        enabled: no
        # Two operation modes are available: "extra-data" and "overwrite".
        mode: extra-data
        # Two proxy deployments are supported: "reverse" and "forward". In
        # a "reverse" deployment the IP address used is the last one, in a
        # "forward" deployment the first IP address is used.
        deployment: reverse
        # Header name where the actual IP address will be reported. If more
        # than one IP address is present, the last IP address will be the
        # one taken into consideration.
        header: X-Forwarded-For

      types:
        - alert:
            # payload: yes             # enable dumping payload in Base64
            # payload-buffer-size: 4kb # max size of payload buffer to output in eve-log
            # payload-printable: yes   # enable dumping payload in printable (lossy) format
            # payload-length: yes      # enable dumping payload length, including the gaps
            # packet: yes              # enable dumping of packet (without stream segments)
            # metadata: no             # enable inclusion of app layer metadata with alert. Default yes
            # If you want metadata, use:
            # metadata:
              # Include the decoded application layer (ie. http, dns)
              #app-layer: true
              # Log the current state of the flow record.
              #flow: true
              #rule:
                # Log the metadata field from the rule in a structured
                # format.
                #metadata: true
                # Log the raw rule text.
                #raw: false
                #reference: false      # include reference information from the rule
            # http-body: yes           # Requires metadata; enable dumping of HTTP body in Base64
            # http-body-printable: yes # Requires metadata; enable dumping of HTTP body in printable format
            # websocket-payload: yes   # Requires metadata; enable dumping of WebSocket Payload in Base64
            # websocket-payload-printable: yes # Requires metadata; enable dumping of WebSocket Payload in printable format

            # Enable the logging of tagged packets for rules using the
            # "tag" keyword.
            tagged-packets: yes
            # Enable logging the final action taken on a packet by the engine
            # (e.g: the alert may have action 'allowed' but the verdict be
            # 'drop' due to another alert. That's the engine's verdict)
            # verdict: yes
        # app layer frames
        - frame:
            # disabled by default as this is very verbose.
            enabled: no
            # payload-buffer-size: 4kb # max size of frame payload buffer to output in eve-log
        - anomaly:
            # Anomaly log records describe unexpected conditions such
            # as truncated packets, packets with invalid IP/UDP/TCP
            # length values, and other events that render the packet
            # invalid for further processing or describe unexpected
            # behavior on an established stream. Networks which
            # experience high occurrences of anomalies may experience
            # packet processing degradation.
            #
            # Anomalies are reported for the following:
            # 1. Decode: Values and conditions that are detected while
            # decoding individual packets. This includes invalid or
            # unexpected values for low-level protocol lengths as well
            # as stream related events (TCP 3-way handshake issues,
            # unexpected sequence number, etc).
            # 2. Stream: This includes stream related events (TCP
            # 3-way handshake issues, unexpected sequence number,
            # etc).
            # 3. Application layer: These denote application layer
            # specific conditions that are unexpected, invalid or are
            # unexpected given the application monitoring state.
            #
            # By default, anomaly logging is enabled. When anomaly
            # logging is enabled, applayer anomaly reporting is
            # also enabled.
            enabled: yes
            #
            # Choose one or more types of anomaly logging and whether to enable
            # logging of the packet header for packet anomalies.
            types:
              # decode: no
              # stream: no
              # applayer: yes
            #packethdr: no
        - http:
            extended: yes     # enable this for extended logging information
            # custom allows additional HTTP fields to be included in eve-log.
            # the example below adds three additional fields when uncommented
            #custom: [Accept-Encoding, Accept-Language, Authorization]
            # set this value to one and only one from {both, request, response}
            # to dump all HTTP headers for every HTTP request and/or response
            # dump-all-headers: none
        - dns:
            # This configuration uses the new DNS logging format,
            # the old configuration is still available:
            # https://docs.suricata.io/en/latest/output/eve/eve-json-output.html#dns-v1-format

            # As of Suricata 5.0, version 2 of the eve dns output
            # format is the default.
            #version: 2

            # Enable/disable this logger. Default: enabled.
            #enabled: yes

            # Control logging of requests and responses:
            # - requests: enable logging of DNS queries
            # - responses: enable logging of DNS answers
            # By default both requests and responses are logged.
            #requests: no
            #responses: no

            # Format of answer logging:
            # - detailed: array item per answer
            # - grouped: answers aggregated by type
            # Default: all
            #formats: [detailed, grouped]

            # DNS record types to log, based on the query type.
            # Default: all.
            #types: [a, aaaa, cname, mx, ns, ptr, txt]
        - tls:
            extended: yes     # enable this for extended logging information
            # output TLS transaction where the session is resumed using a
            # session id
            #session-resumption: no
            # custom controls which TLS fields that are included in eve-log
            # WARNING: enabling custom disables extended logging.
            #custom: [subject, issuer, session_resumed, serial, fingerprint, sni, version, not_before, not_after, certificate, chain, ja3, ja3s, ja4, subjectaltname, client, client_certificate, client_chain, client_alpns, server_alpns]
        - files:
            force-magic: no   # force logging magic on all logged files
            # force logging of checksums, available hash functions are md5,
            # sha1 and sha256
            #force-hash: [md5]
        #- drop:
        #    alerts: yes      # log alerts that caused drops
        #    flows: all       # start or all: 'start' logs only a single drop
        #                     # per flow direction. All logs each dropped pkt.
            # Enable logging the final action taken on a packet by the engine
            # (will show more information in case of a drop caused by 'reject')
            # verdict: yes
        - smtp:
            #extended: yes # enable this for extended logging information
            # this includes: bcc, message-id, subject, x_mailer, user-agent
            # custom fields logging from the list:
            #  reply-to, bcc, message-id, subject, x-mailer, user-agent, received,
            #  x-originating-ip, in-reply-to, references, importance, priority,
            #  sensitivity, organization, content-md5, date
            #custom: [received, x-mailer, x-originating-ip, relays, reply-to, bcc]
            # output md5 of fields: body, subject
            # for the body you need to set app-layer.protocols.smtp.mime.body-md5
            # to yes
            #md5: [body, subject]

        #- dnp3
        - websocket
        - ftp
        - ftp-data
        - rdp
        - nfs
        - smb
        - tftp
        - ike
        - dcerpc
        - krb5
        - bittorrent-dht
        - ssh
        - arp:
            enabled: no
        - snmp
        - rfb
        - sip
        - quic
        - dhcp:
            enabled: yes
            # When extended mode is on, all DHCP messages are logged
            # with full detail. When extended mode is off (the
            # default), just enough information to map a MAC address
            # to an IP address is logged.
            extended: no
        - mqtt:
            # passwords: yes           # enable output of passwords
            # string-log-limit: 1kb    # limit size of logged strings in bytes.
                                       # Can be specified in kb, mb, gb. Just a number
                                       # is parsed as bytes. Default is 1KB.
                                       # Use a value of 0 to disable limiting.
                                       # Note that the size is also bounded by
                                       # the maximum parsed message size (see
                                       # app-layer configuration)
        - http2
        - pgsql:
            enabled: no
            # passwords: yes           # enable output of passwords. Disabled by default
        - stats:
            totals: yes       # stats for all threads merged together
            threads: no       # per thread stats
            deltas: no        # include delta values
            # Don't log stats counters that are zero. Default: true
            #null-values: false    # False will NOT log stats counters: 0
        # bi-directional flows
        - flow
        # uni-directional flows
        #- netflow

        # Metadata event type. Triggered whenever a pktvar is saved
        # and will include the pktvars, flowvars, flowbits and
        # flowints.
        #- metadata

        # EXPERIMENTAL per packet output giving TCP state tracking details
        # including internal state, flags, etc.
        # This output is experimental, meant for debugging and subject to
        # change in both config and output without any notice.
        #- stream:
        #   all: false                      # log all TCP packets
        #   event-set: false                # log packets that have a decoder/stream event
        #   state-update: false             # log packets triggering a TCP state update
        #   spurious-retransmission: false  # log spurious retransmission packets
        #
heartbeat:
  # The output-flush-interval value governs how often Suricata will instruct the
  # detection threads to flush their EVE output. Specify the value in seconds [1-60]
  # and Suricata will initiate EVE log output flushes at that interval. A value
  # of 0 means no EVE log output flushes are initiated. When the EVE output
  # buffer-size value is non-zero, some EVE output that was written may remain
  # buffered. The output-flush-interval governs how much buffered data exists.
  #
  # The default value is: 0 (never instruct detection threads to flush output)
  #output-flush-interval: 0

更多高级配置选项,请参阅 Eve JSON 输出

格式记录在 Eve JSON 格式 中。

14.1.9.6. TLS 参数和证书日志(tls.log)

Attention

tls-log 在 Suricata 8.0 中已弃用,将在 Suricata 9.0 中移除。

TLS 握手参数也可以记录在基于行的日志中。默认情况下,日志文件是 suricata 日志目录中的 tls.log。有关日志格式的配置和自定义的详细信息,请参阅 自定义 TLS 日志

此外,还有一个输出模块用于将 TLS 证书文件存储到磁盘。这与 文件存储(文件提取) 类似,但针对的是 TLS 证书。

示例:

# 输出模块,用于将证书链存储到磁盘
- tls-store:
    enabled: yes
    #certs-log-dir: certs # 存储证书文件的目录

14.1.9.7. 基于行的 HTTP 请求日志(http.log)

Attention

http-log 在 Suricata 8.0 中已弃用,将在 Suricata 9.0 中移除。

此日志跟踪所有 HTTP 流量事件。它包含 HTTP 请求、主机名、URI 和 User-Agent。这些信息将存储在 http.log(默认名称,位于 suricata 日志目录中)。也可以通过使用 Eve-log 功能 进行此日志记录。

非扩展日志记录的 HTTP 日志行示例:

07/01/2014-04:20:14.338309 vg.no [**] / [**] Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36 [**]
192.168.1.6:64685 -> 195.88.54.16:80

扩展日志记录的 HTTP 日志行示例:

07/01/2014-04:21:06.994705 vg.no [**] / [**] Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36 [**] <no referer> [**]
GET [**] HTTP/1.1 [**] 301 => http://www.vg.no/ [**] 239 bytes [**] 192.168.1.6:64726 -> 195.88.54.16:80
- http-log:                     #日志名称。
    enabled: yes                #此日志已启用。设置为 'no' 以禁用。
    filename: http.log          #默认日志目录中的文件名。
    append: yes/no              #如果此选项设置为 yes,则在重新启动 Suricata 时不会覆盖最后一个填充的 http.log 文件。
    extended: yes               #如果设置为 yes,将写入关于事件的更多信息。

14.1.9.8. 数据包日志(pcap-log)

通过 pcap-log 选项,你可以将所有由 Suricata 注册的数据包保存到名为 _log.pcap_ 的日志文件中。这样,你可以随时查看所有数据包。在正常模式下,pcap 文件会在 default-log-dir 中创建。如果 yaml 文件中设置了绝对路径,也可以在其他地方创建。

保存在 default-log-dir /var/log/suricata 中的文件可以用任何支持 pcap 文件格式的程序打开。这可以是 Wireshark、TCPdump、Suricata、Snort 等。

pcap-log 选项可以启用和禁用。

可以设置 pcap-log 文件的大小限制。默认限制是 32 MB。如果日志文件达到此限制,文件将被轮换并创建一个新文件。 记住,在 'normal' 模式下,文件将保存在 default-log-dir 或绝对路径中(如果设置)。

通过将 compression 选项设置为 lz4,可以在写入磁盘之前压缩 pcap 文件。 注意:在 Windows 上,此选项会增加磁盘 I/O 而不是减少它。当使用 lz4 压缩时,可以使用 lz4-checksum 选项启用校验和,并且可以将压缩级别 lz4-level 设置为 0 到 16 之间的值,其中更高的级别会导致更高的压缩率。

默认情况下,所有数据包都会被记录,除了:

  • 超过 stream.reassembly.depth 的 TCP 流

  • 密钥交换后的加密流

  • 如果设置了 bpf-filter,不匹配过滤器的数据包将不会被记录

可以通过在 pcap-log 部分使用 conditional 选项进行条件性 pcap 日志记录。默认情况下,变量设置为 all,因此所有数据包都会被记录。如果变量设置为 alerts,则只有带有警报的流会被记录。如果变量设置为 tag,则只有被签名使用 tag 关键字标记的数据包会被记录到 pcap 文件中。请注意,如果使用 alertstag,则在 TCP 会话的情况下,Suricata 将使用流引擎中的可用信息记录触发警报的数据。

- pcap-log:
    enabled:  yes
    filename: log.pcap

    # 限制大小(MB)。
    limit: 32

    mode: normal # "normal" 或 multi
    conditional: alerts

    # 应用于所有被记录的数据包的 BPF 过滤器。如果设置,数据包必须匹配此过滤器,否则不会被记录。
    #bpf-filter:

normal 模式下,pcap 文件 "filename" 会在 default-log-dir 或由 "dir" 指定的位置创建。normal 模式通常不如 multi 模式性能好。

在 multi 模式下,会创建多个 pcap 文件(每个线程一个),