10.45. 阈值设置关键词

阈值可以针对单条规则进行配置,也可以全局配置,详见 全局阈值

阈值数据存储在根据配置调整大小的哈希表中,参见:suricata-yaml-thresholds

**重要提示**(适用于 thresholddetection_filter 关键词)

Note

包含 flowbitsflowints 等动作的规则在使用了 threshold 关键词时仍会执行这些动作。这些动作不受阈值限制影响。

规则动作 drop``(IPS模式)和 ``reject 会应用于每个数据包(不仅限于达到阈值条件的数据包)。

10.45.1. threshold

threshold 关键词用于控制规则告警频率,支持四种模式:

  1. threshold(阈值)

  2. limit(限制)

  3. both(混合)

  4. backoff(退避)

语法:

threshold: type <threshold|limit|both|backoff>, track <by_src|by_dst|by_rule|by_both|by_flow>, count <N>, <seconds <T>|multiplier <M>>

使用 seconds 可控制单位时间内的告警数量。

10.45.1.1. type "threshold"

此类型设定规则触发告警的最低阈值。

count 值为 C 时,规则匹配到第 C 次才会生成告警。若指定 seconds,则表示在 N 秒内匹配达到 count 次时触发告警。

语法:

threshold: type threshold, track by_flow, count <C>, seconds <N>;

示例:

alert tcp !$HOME_NET any -> $HOME_NET 25 (msg:"ET POLICY 入站频繁邮件 - 疑似垃圾邮件机器人"; flow:established; content:"mail from|3a|"; nocase; 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封以上入站邮件时触发告警。

10.45.1.2. type "limit"

limit 类型通过限制告警数量来防止告警洪泛。设置 countN 时,最多生成 N 次告警。

结合 seconds 可限制单位时间内的告警数量。

语法:

threshold: type limit, track by_dst, count <C>, seconds <N>;

示例:

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|"; 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次告警。

10.45.1.3. type "both"

此类型结合 thresholdlimit 双重控制告警生成。

语法:

threshold: type both, track by_flow, count <C>, multiplier <M>;

示例:

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; 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 关键词。

10.45.1.4. type "backoff"

此类型通过退避算法限制告警输出。

Note

backoff 仅支持 track by_flow

语法:

threshold: type backoff, track by_flow, count <C>, multiplier <M>;

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...次匹配时触发告警:

alert tcp any any -> any any (stream-event:pkt_invalid_ack; threshold:type backoff, track by_flow, count 1, multiplier 10; sid:2210045; rev:2;)

10.45.1.5. track

选项

追踪依据

by_src

源IP

by_dst

目的IP

by_both

源IP与目的IP组合

by_rule

规则ID

by_flow

流量

10.45.2. detection_filter

detection_filter 关键词用于在达到初始阈值后对每次匹配都生成告警。与 threshold 类型不同之处在于:前者达到阈值后会持续告警,而后者会重置计数器并在每次达到阈值时告警。

语法:

detection_filter: track <by_src|by_dst|by_rule|by_both|by_flow>, count <N>, seconds <T>

示例:

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:!"&amp|3b|t="; http_uri; nocase; 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次后,后续每次匹配都会触发告警。