阈值设置关键词 ===================== 阈值可以针对单条规则进行配置,也可以全局配置,详见 :doc:`../configuration/global-thresholds`。 阈值数据存储在根据配置调整大小的哈希表中,参见::ref:`suricata-yaml-thresholds`。 **重要提示**(适用于 ``threshold`` 和 ``detection_filter`` 关键词) .. note:: 包含 ``flowbits``、``flowints`` 等动作的规则在使用了 ``threshold`` 关键词时仍会执行这些动作。这些动作不受阈值限制影响。 规则动作 ``drop``(IPS模式)和 ``reject`` 会应用于每个数据包(不仅限于达到阈值条件的数据包)。 threshold --------- ``threshold`` 关键词用于控制规则告警频率,支持四种模式: #. threshold(阈值) #. limit(限制) #. both(混合) #. backoff(退避) 语法:: threshold: type , track , count , |multiplier > 使用 ``seconds`` 可控制单位时间内的告警数量。 type "threshold" ~~~~~~~~~~~~~~~~ 此类型设定规则触发告警的最低阈值。 当 ``count`` 值为 ``C`` 时,规则匹配到第 ``C`` 次才会生成告警。若指定 ``seconds``,则表示在 ``N`` 秒内匹配达到 ``count`` 次时触发告警。 语法:: threshold: type threshold, track by_flow, count , seconds ; 示例: .. container:: example-rule alert tcp !$HOME_NET any -> $HOME_NET 25 (msg:"ET POLICY 入站频繁邮件 - 疑似垃圾邮件机器人"; flow:established; content:"mail from|3a|"; nocase; :example-rule-emphasis:`threshold: type threshold, track by_src, count 10, seconds 60;` reference:url,doc.emergingthreats.net/2002087; classtype:misc-activity; sid:2002087; rev:10;) 此规则在1分钟内检测到同一服务器发送10封以上入站邮件时触发告警。 type "limit" ~~~~~~~~~~~~ ``limit`` 类型通过限制告警数量来防止告警洪泛。设置 ``count`` 为 ``N`` 时,最多生成 ``N`` 次告警。 结合 ``seconds`` 可限制单位时间内的告警数量。 语法:: threshold: type limit, track by_dst, count , seconds ; 示例: .. container:: example-rule alert http $HOME_NET any -> any any (msg:"ET INFO 检测到IE6使用 - 重大安全风险"; flow:established,to_server; http.user_agent; content:"Mozilla/4.0 (compatible|3b| MSIE 6.0|3b|"; :example-rule-emphasis:`threshold: type limit, track by_src, seconds 180, count 1;` classtype:policy-violation; sid:2010706; rev:10; metadata:created_at 2010_07_30, updated_at 2024_03_16;) 此例中,每台主机在3分钟内检测到"MSIE 6.0"时最多生成1次告警。 type "both" ~~~~~~~~~~~ 此类型结合 ``threshold`` 和 ``limit`` 双重控制告警生成。 语法:: threshold: type both, track by_flow, count , multiplier ; 示例: .. container:: example-rule alert tcp $HOME_NET 5060 -> $EXTERNAL_NET any (msg:"ET VOIP 多例未授权SIP响应(TCP)"; flow:established,from_server; content:"SIP/2.0 401 Unauthorized"; depth:24; :example-rule-emphasis:`threshold: type both, track by_src, count 5, seconds 360;` reference:url,doc.emergingthreats.net/2003194; classtype:attempted-dos; sid:2003194; rev:6;) 当检测到5次以上"SIP2.0 401 Unauthorized"响应时,此规则每6分钟最多生成1次告警。 ``type backoff`` 章节会说明 ``multiplier`` 关键词。 type "backoff" ~~~~~~~~~~~~~~ 此类型通过退避算法限制告警输出。 .. note:: ``backoff`` 仅支持 ``track by_flow`` 语法:: threshold: type backoff, track by_flow, count , multiplier ; ``track``: 仅支持 ``by_flow`` ``count``: 首次告警前的匹配次数 ``multiplier``: 每次达到阈值后与 ``count`` 相乘的系数 当count=1,multiplier=10时,会在以下匹配次数触发告警:: 1, 10, 100, 1000, 10000, 100000, 等 当count=1,multiplier=2时:: 1, 2, 4, 8, 16, 32, 64, 等 当count=5,multiplier=5时:: 5, 25, 125, 625, 3125, 15625, 等 下例中,``pkt_invalid_ack`` 仅在第1、10、100...次匹配时触发告警: .. container:: example-rule alert tcp any any -> any any (stream-event:pkt_invalid_ack; :example-rule-emphasis:`threshold:type backoff, track by_flow, count 1, multiplier 10;` sid:2210045; rev:2;) track ~~~~~ .. table:: +------------------+--------------------------+ |选项 |追踪依据 | +==================+==========================+ |by_src |源IP | +------------------+--------------------------+ |by_dst |目的IP | +------------------+--------------------------+ |by_both |源IP与目的IP组合 | +------------------+--------------------------+ |by_rule |规则ID | +------------------+--------------------------+ |by_flow |流量 | +------------------+--------------------------+ detection_filter ---------------- ``detection_filter`` 关键词用于在达到初始阈值后对每次匹配都生成告警。与 ``threshold`` 类型不同之处在于:前者达到阈值后会持续告警,而后者会重置计数器并在每次达到阈值时告警。 语法:: detection_filter: track , count , seconds 示例: .. container:: example-rule alert http $EXTERNAL_NET any -> $HOME_NET any (msg:"ET WEB_SERVER 访问无t参数的WebResource.axd - 可能为ASP填充预言攻击"; flow:established,to_server; content:"GET"; http_method; content:"WebResource.axd"; http_uri; nocase; content:!"&t="; http_uri; nocase; content:!"&|3b|t="; http_uri; nocase; :example-rule-emphasis:`detection_filter:track by_src,count 15,seconds 2;` reference:url,netifera.com/research/; reference:url,www.microsoft.com/technet/security/advisory/2416728.mspx; classtype:web-application-attack; sid:2011807; rev:5;) 此规则在2秒内匹配达到15次后,后续每次匹配都会触发告警。