【Suricata】03-Suricata 7.0.x 规则管理

目录

1.规则库介绍

1.1 PT规则库

1.2 ET规则库

1.3 cobaltstrike-suricata-rules

2. 规则管理

2.1 更新suricata规则库

2.2 更新规则源

2.3 查看规则源

2.4 启用规则集

2.5 关闭某个规则源

2.6 删除某个规则源

2.7 禁用规则

2.8 启用规则

2.9 修改规则

2.10 删除规则

2.11 规则匹配

2.11.1 签名ID匹配

2.11.2 正则表达式匹配

2.11.3 规则组匹配

2.11.4 文件名匹配

2.12 Metadata 匹配

2.12.1 编写 Metadata

2.12.2 应用 Metadata Matching

2.13 配置文件的应用顺序

2.14 不重启suricata重新加载规则

2.14.1 原理

2.14.2 通过发送信号的方式来重新加载规则

2.14.3 阻塞式重新加载(Blocking reload)

2.14.4 非阻塞式重新加载(Non-blocking reload)

2.14.5 不同重新加载规则方法的使用场景

3. 给规则设置设置IP白名单


1.规则库介绍

1.1 PT规则库

PT的Suricata规则库,根据恶意软件、黑客的网络通讯协议以及漏洞的poc去编写

https://github.com/ptresearch/AttackDetection

于2022年停止维护

1.2 ET规则库

Emerging Threats维护的规则

https://rules.emergingthreats.net/open/suricata/rules/ http://rules.emergingthreats.net/open/suricata/emerging.rules.tar.gz

1.3 cobaltstrike-suricata-rules

https://github.com/ainrm/cobaltstrike-suricata-rules/tree/main

2. 规则管理

使用suricata自带的suricata-update规则管理工具

2.1 更新suricata规则库

suricata-update

2.2 更新规则源

suricata-update update-sources

2.3 查看规则源

root@test-pc:~# suricata-update list-sources
22/1/2024 -- 11:38:54 - <Info> -- Using data-directory /home/lib/suricata.
22/1/2024 -- 11:38:54 - <Info> -- Using Suricata configuration /etc/suricata/suricata.yaml
22/1/2024 -- 11:38:54 - <Info> -- Using /usr/share/suricata/rules for Suricata provided rules.
22/1/2024 -- 11:38:54 - <Info> -- Found Suricata version 7.0.2 at /usr/bin/suricata.
Name: et/open
  Vendor: Proofpoint
  Summary: Emerging Threats Open Ruleset
  License: MIT
Name: et/pro
  Vendor: Proofpoint
  Summary: Emerging Threats Pro Ruleset
  License: Commercial
  Replaces: et/open
  Parameters: secret-code
  Subscription: https://www.proofpoint.com/us/threat-insight/et-pro-ruleset
Name: oisf/trafficid
  Vendor: OISF
  Summary: Suricata Traffic ID ruleset
  License: MIT
Name: scwx/enhanced
  Vendor: Secureworks
  Summary: Secureworks suricata-enhanced ruleset
  License: Commercial
  Parameters: secret-code
  Subscription: https://www.secureworks.com/contact/ (Please reference CTU Countermeasures)
Name: scwx/malware
  Vendor: Secureworks
  Summary: Secureworks suricata-malware ruleset
  License: Commercial
  Parameters: secret-code
  Subscription: https://www.secureworks.com/contact/ (Please reference CTU Countermeasures)
Name: scwx/security
  Vendor: Secureworks
  Summary: Secureworks suricata-security ruleset
  License: Commercial
  Parameters: secret-code
  Subscription: https://www.secureworks.com/contact/ (Please reference CTU Countermeasures)
Name: sslbl/ssl-fp-blacklist
  Vendor: Abuse.ch
  Summary: Abuse.ch SSL Blacklist
  License: Non-Commercial
Name: sslbl/ja3-fingerprints
  Vendor: Abuse.ch
  Summary: Abuse.ch Suricata JA3 Fingerprint Ruleset
  License: Non-Commercial
Name: etnetera/aggressive
  Vendor: Etnetera a.s.
  Summary: Etnetera aggressive IP blacklist
  License: MIT
Name: tgreen/hunting
  Vendor: tgreen
  Summary: Threat hunting rules
  License: GPLv3
Name: malsilo/win-malware
  Vendor: malsilo
  Summary: Commodity malware rules
  License: MIT
Name: stamus/lateral
  Vendor: Stamus Networks
  Summary: Lateral movement rules
  License: GPL-3.0-only
root@ndr:~# 

2.4 启用规则集

启用 ptsearch/attackdetection 规则集

suricata-update enable-source ptresearch/attackdetection

再次更新我们的规则集

suricata-update

列出我们使用的规则源

suricata-update list-enabled-sources

或

suricata-update list-sources --enabled

2.5 关闭某个规则源

suricata-update disable-source et/pro

2.6 删除某个规则源

suricata-update remove-source et/pto

2.7 禁用规则

使用Suricata-update更新规则时,默认是将所有规则合并在一个规则文件中:/var/lib/suricata/rules/suricata.rules。

Suricata-update有个 --no-merge参数,使用这个参数更新规则,规则不会进行合并,是以独立的文件存在于文件夹下。但是在管理规则的时候很不方便,必须要自己管理Suricata引入的规则。但是在禁用规则的时候,也可以使用suricata-update去配置disable.conf禁用的规则。不推荐使用 --no-merge参数更新规则。

指定一个文件让suricata-update合并输出会更简单。在suricata.yaml中修改default-rule-path和rule-files。

要禁用规则,在/etc/suricata目录下新建disable.conf,配置文件中写入规则特征,每次更新会禁用该规则。

参考Suricata-update的官方文档,disable.conf中支持四种规则特征:

  • 签名ID
  • 正则表达式
  • 规则组匹配
  • 文件匹配

详情见:2.11 章节

disable.conf文件内容示例如下:

# suricata-update - disable.conf

# Example of disabling a rule by signature ID (gid is optional).
# 1:2019401
# 2019401

# Example of disabling a rule by regular expression.
# - All regular expression matches are case insensitive.
# re:heartbleed
# re:MS(0[7-9]|10)-\d+

# Examples of disabling a group of rules.
# group:emerging-icmp.rules
# group:emerging-dos
# group:emerging*

# Disable all rules with a metadata of "deployment perimeter". Note that metadata
# matches are case insensitive.
# metadata: deployment perimeter

 配置好disable.conf后,使用如下命令更新规则:

# 默认是输出suricata.rules文件到 /var/lib/suricata/rules/目录下
suricata-update --disable-conf /etc/suricata/disable.conf

# 指定输出suricata.rules到/etc/suricata/rules/目录下,使用-o参数
suricata-update --disable-conf /etc/suricata/disable.conf -o /etc/suricata/rules/

disable.conf来源:suricata-rules/disable.conf at master · al0ne/suricata-rules · GitHub

2.8 启用规则

要启用规则,在/etc/suricata目录下新建enable.conf,配置文件中写入规则特征,每次更新会启用该规则。

enable.conf中支持四种规则特征:

  • 签名ID
  • 正则表达式
  • 规则组匹配
  • 文件匹配

详情见:2.11 章节

enable.conf文件内容,示例如下:

# suricata-update - enable.conf

# Example of enabling a rule by signature ID (gid is optional).
# 1:2019401
# 2019401

# Example of enabling a rule by regular expression.
# - All regular expression matches are case insensitive.
# re:heartbleed
# re:MS(0[7-9]|10)-\d+

# Examples of enabling a group of rules.
# group:emerging-icmp.rules
# group:emerging-dos
# group:emerging*

# Enable all rules with a metadata of "deployment perimeter". Note that metadata
# matches are case insensitive.
# metadata: deployment perimeter

配置好enable.conf后,使用如下命令更新规则:

# 默认是输出suricata.rules文件到 /var/lib/suricata/rules/目录下
suricata-update --enable-conf /etc/suricata/enable.conf

# 指定输出suricata.rules到/etc/suricata/rules/目录下,使用-o参数
suricata-update --enable-conf /etc/suricata/enable.conf -o /etc/suricata/rules/

2.9 修改规则

要启用规则,在/etc/suricata目录下新建modify.conf文件,enable.conf中支持四种规则特征:

  • 签名ID
  • 正则表达式
  • 规则组匹配
  • 文件匹配

详情见:2.11 章节。

在 Suricata 中,规则修改通常是通过正则表达式搜索和替换来实现的。规则修改指定符的基本格式是:

<match> <from> <to>

其中 <match>  是2.11章节-规则匹配提到的规则匹配器之一, <from>是要被替换的文本,<to> 是替换文本。

例1:将所有 alert 规则的动作转换为 drop

re:. ^alert drop

这里的 re:. 表示使用正则表达式进行匹配,^alert 是正则表达式,匹配以 alert 开头的行,然后将其替换为 drop。

例2:将所有包含 drop 和 noalert 的规则动作从 drop 改回 alert

re:. "^drop(.*)noalert(.*)" "alert\\1noalert\\2"

这里 ^drop(.*)noalert(.*) 匹配以 drop 开头,后面跟着任意字符(由 (.*) 捕获),然后是 noalert 和任意字符的行。替换文本 

"alert\\1noalert\\2" 中的 \\1 和 \\2 分别代表两个捕获组的内容,确保替换后的规则仍然包含原始规则中 drop 和 noalert 之间的内容。

modify.conf文件内容示例如下:

# suricata-update - modify.conf

# Format: <sid> "<from>" "<to>"

# Example changing the seconds for rule 2019401 to 3600.
# 2019401 "seconds \d+" "seconds 3600"
#
# Example converting all alert rules to drop:
# re:. ^alert drop
#
# Example converting all drop rules with noalert back to alert:
# re:. "^drop(.*)noalert(.*)" "alert\\1noalert\\2"

# Change all trojan-activity rules to drop. Its better to setup a
# drop.conf for this, but this does show the use of back references.
# re:classtype:trojan-activity "(alert)(.*)" "drop\\2"

# For compatibility, most Oinkmaster modifysid lines should work as
# well.
# modifysid * "^drop(.*)noalert(.*)" | "alert${1}noalert${2}"

# Add metadata.
#metadata-add re:"SURICATA STREAM" "evebox-action" "archive"
#metadata-add 2010646 "evebox-action" "archive"

配置好modify.conf后,使用如下命令更新规则:

# 默认是输出suricata.rules文件到 /var/lib/suricata/rules/目录下
suricata-update --modify-conf /etc/suricata/modify.conf

# 指定输出suricata.rules到/etc/suricata/rules/目录下,使用-o参数
suricata-update --modify-conf /etc/suricata/modify.conf -o /etc/suricata/rules/

2.10 删除规则

drop.conf文件内容示例如下:

# suricata-update - drop.conf
#
# Rules matching specifiers in this file will be converted to drop rules.
#
# Examples:
#
# 1:2019401
# 2019401
#
# re:heartbleed
# re:MS(0[7-9]|10)-\d+

配置好drop.conf后,使用如下命令更新规则:

# 默认是输出suricata.rules文件到 /var/lib/suricata/rules/目录下
suricata-update --drop-conf /etc/suricata/drop.conf

# 指定输出suricata.rules到/etc/suricata/rules/目录下,使用-o参数
suricata-update --drop-conf /etc/suricata/drop.conf -o /etc/suricata/rules/

2.11 规则匹配

匹配禁用、启用、转换为删除或修改的规则可以通过以下方式完成:

  • 签名ID
  • 正则表达式
  • 规则组
  • 文件名

2.11.1 签名ID匹配

签名ID自身,就是规则里的sid,例如:

1034

或者,generator ID加上signature ID,例如:

1:1034

这里的 1 就是 generator ID,而 1034 是 signature ID。这个格式通常用于指定签名 ID 及其生成器的组合,以提供更详细的上下文信息。

Generator ID 的具体值取决于生成该签名的工具或组织。例如,一个特定的安全公司或项目可能使用其特定的 generator ID 来标识其创建的签名。这样,当管理员查看 Suricata 的日志或警报时,他们可以轻松地识别出哪些签名是由哪个组织或工具生成的。

需要注意的是,不同的系统和工具可能有不同的 generator ID 分配和命名约定,所以具体的值可能会有所不同。如果你正在使用一个特定的工具或库来生成 Suricata 签名,并希望了解其使用的 generator ID,你应该查阅该工具或库的文档或联系其开发者以获取更多信息。

2.11.2 正则表达式匹配

正则表达式匹配将在整个规则上匹配正则表达式。例如:

re:heartbleed re:MS(0[7-9]|10)-\d+

这里提到的正则表达式是Linux(以及很多其他系统和编程语言)通用的正则表达式。

2.11.3 规则组匹配

在 Suricata 的规则匹配中,group 匹配器用于匹配规则是从哪个组(或文件)加载的。基本上,这个组名就是文件名,但不包括前面的路径或文件扩展名。例如:

group:emerging-icmp.rules group:emerging-dos
  • group:emerging-icmp.rules 表示这个规则是从名为 emerging-icmp.rules 的文件中加载的。
  • group:emerging-dos 表示这个规则是从名为 emerging-dos 的文件中加载的。

Suricata 还支持使用类似于 Unix shell 中的通配符进行模式匹配。这允许你匹配多个组名,而不是只匹配一个特定的组名。例如:

group:*deleted*

这个匹配器会匹配任何包含 deleted 字符串的组名。例如,它会匹配 rules-deleted-today.conf、malware-signatures-deleted.rules 等文件名(假设这些文件名去掉路径和扩展名后就是它们的组名)。

使用通配符可以帮助管理员更灵活地应用规则,特别是在需要临时禁用或启用与特定主题或事件相关的多个规则组时。

2.11.4 文件名匹配

在 Suricata 的规则匹配中,filename 匹配器用于匹配规则是从哪个具有完整路径的文件名加载的。与 group 匹配器不同,filename 匹配器考虑了文件的完整路径。例如:

filename:rules/*deleted* 
filename:*/emerging-dos.rules
  • filename:rules/*deleted*
    • 这个匹配器会匹配任何在 rules 目录下文件名包含 deleted 字符串的文件。通配符 * 用于匹配任何字符序列(包括零个字符),因此这个模式可以匹配如 rules/signatures-deleted.rules 或 rules/today-deleted-malware.conf 等文件名。
  • filename:*/emerging-dos.rules

这个匹配器会匹配任何在任意目录(由 */ 表示)下名为 emerging-dos.rules 的文件。通配符 * 用于匹配任意目录名,因此这个模式可以匹配如 config/emerging-dos.rules、rules/emerging-dos.rules 或任何其他目录下名为 emerging-dos.rules 的文件。

使用 filename 匹配器可以使管理员更加精确地控制哪些规则是从特定的文件加载的,这在需要针对特定文件或目录进行规则启用、禁用或修改时特别有用。

2.12 Metadata 匹配

在 Suricata 规则匹配中,Metadata Matching 允许你根据规则中包含的元数据字段来启用或禁用规则。元数据字段是附加在规则上用于描述规则特性或适用场景的信息。

可以根据规则中包含的元数据字段启用或禁用规则,例如:

metadata: deployment perimeter

将元数据字段为“deployment”的规则与值为“perimeter”(不区分大小写)的规则进行匹配。

对于下面这个规则,由于其元数据包含了deployment Perimeter(注意这里大小写敏感性的说明可能因 Suricata 的版本或配置而异),因此它会匹配上面的匹配器:

metadata:affected_product Any, attack_target Any, deployment Perimeter

注:

元数据匹配只能用于启用、禁用或将规则转换为丢弃(drop)行为,它不能用于修改规则本身。也就是说,你不能通过元数据匹配来改变规则的动作(action)或其他属性,只能影响规则是否生效。

2.12.1 编写 Metadata

首先,你需要在 Suricata 规则文件中添加 metadata 字段。Metadata 通常位于规则的开头,并遵循 metadata: 关键字后接键值对的格式。例如:

alert tcp $HOME_NET any -> $EXTERNAL_NET $HTTP_PORTS (msg:"Example HTTP traffic"; flow:to_server,established; content:"GET"; metadata:deployment perimeter, affected_product WebServer, attack_target WebApplication;)

在这个例子中,

metadata: 关键字后面跟着三个键值对:

deployment perimeter、

affected_product WebServer 和 

attack_target WebApplication。每个键值对之间用逗号分隔。

2.12.2 应用 Metadata Matching

一旦规则中包含了 metadata,你就可以使用 metadata matching 来启用、禁用或转换这些规则了。这通常在 Suricata 的配置文件中完成,具体是在 classifier-config 部分使用 config 关键字来定义匹配和动作。

例如,要禁用所有部署在 perimeter 的规则,你可以这样写:

config classifier:metadata-disabled  
{  
    metadata:deployment perimeter;  
    action:disabled;  
}

在这个配置中,

classifier:metadata-disabled 定义了一个分类器,它使用 

metadata:deployment perimeter 来匹配所有包含 

deployment perimeter 元数据的规则,并将这些规则的动作设置为 disabled。

同样地,如果你想将所有针对 WebApplication 的攻击规则转换为丢弃(drop)动作,你可以这样配置:

config classifier:metadata-drop  
{  
    metadata:attack_target WebApplication;  
    action:drop;  
}

这个配置会将所有包含 attack_target WebApplication 元数据的规则的动作更改为 drop。

2.13 配置文件的应用顺序

disable.conf

enable.conf

drop.conf

modify.conf

2.14 不重启suricata重新加载规则

2.14.1 原理

Suricata 能够在不重启的情况下重新加载规则,这种方式可以最大程度地减少服务中断。这是通过向 Suricata 发送信号或使用 Unix 套接字来实现的。当 Suricata 收到重新加载规则的指令时,它会按照以下基本步骤进行操作:

1.加载新的配置:首先,Suricata 会加载新的配置文件,以更新规则变量和值。这包括任何可能影响规则执行行为的配置更改。

2.加载新的规则:接下来,Suricata 会加载新的规则集。这些规则可能包括新添加的规则、已修改的规则或已删除的规则。

3.构建新的检测引擎:Suricata 会使用新的规则集来构建一个新的检测引擎。这个引擎将负责根据新的规则来检测和分析网络流量。

4.交换新旧检测引擎:一旦新的检测引擎构建完成,Suricata 会进行一个原子性的操作,将旧的检测引擎替换为新的检测引擎。这个过程需要确保在交换过程中不会出现任何数据丢失或不一致的情况。

5.确保所有线程都更新:由于 Suricata 是多线程运行的,因此它需要确保所有正在运行的线程都更新为使用新的检测引擎。这通常涉及到线程同步和状态管理,以确保在切换过程中不会有线程继续使用旧的检测引擎。

6.释放旧的检测引擎:最后,Suricata 会释放旧的检测引擎所占用的资源,以便进行垃圾回收和内存管理。

通过以上步骤,Suricata 能够在不中断服务的情况下重新加载规则,从而提供了一种灵活且高效的方式来管理网络安全策略。这种能力使得管理员能够在需要时快速更新规则,以应对新的安全威胁或调整安全策略,同时保持网络服务的连续性和稳定性。

2.14.2 通过发送信号的方式来重新加载规则

命令如下:

suricata-update --reload-command='sudo kill -USR2 $(pidof suricata)'   # 告诉 Suricata 重新加载其规则

kill -USR2 是一个 Unix 信号,用于通知 Suricata 进程重新加载其配置文件和规则集,而不需要重启整个进程。

$(pidof suricata) 是一个 shell 命令,用于获取 Suricata 进程的进程ID(PID)。

此外,Suricata 还提供了通过 Unix 套接字触发重新加载的功能。

2.14.3 阻塞式重新加载(Blocking reload)

在重新加载过程中,Suricata 会等待重新加载完成。

suricata-update --reload-command='sudo suricatasc -c reload-rules'

suricatasc 是 Suricata 的命令行接口工具,-c reload-rules 是告诉它执行重新加载规则的命令。

以上命令可以触发阻塞式重新加载。

例:

root@ndr:/etc/suricata/rules# suricata-update --reload-command='sudo suricatasc -c reload-rules'
23/4/2024 -- 16:31:56 - <Info> -- Using data-directory /var/lib/suricata.
23/4/2024 -- 16:31:56 - <Info> -- Using Suricata configuration /etc/suricata/suricata.yaml
23/4/2024 -- 16:31:56 - <Info> -- Using /usr/share/suricata/rules for Suricata provided rules.
23/4/2024 -- 16:31:56 - <Info> -- Found Suricata version 7.0.4 at /usr/bin/suricata.
23/4/2024 -- 16:31:56 - <Info> -- Loading /etc/suricata/disable.conf.
23/4/2024 -- 16:31:56 - <Info> -- Loading /etc/suricata/suricata.yaml
23/4/2024 -- 16:31:56 - <Info> -- Disabling rules for protocol pgsql
23/4/2024 -- 16:31:56 - <Info> -- Disabling rules for protocol modbus
23/4/2024 -- 16:31:56 - <Info> -- Disabling rules for protocol dnp3
23/4/2024 -- 16:31:56 - <Info> -- Disabling rules for protocol enip
23/4/2024 -- 16:31:56 - <Info> -- Last download less than 15 minutes ago. Not downloading https://rules.emergingthreats.net/open/suricata-7.0.4/emerging.rules.tar.gz.
23/4/2024 -- 16:31:56 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/app-layer-events.rules
23/4/2024 -- 16:31:56 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/decoder-events.rules
23/4/2024 -- 16:31:56 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/dhcp-events.rules
23/4/2024 -- 16:31:56 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/dnp3-events.rules
23/4/2024 -- 16:31:56 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/dns-events.rules
23/4/2024 -- 16:31:56 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/files.rules
23/4/2024 -- 16:31:56 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/http-events.rules
23/4/2024 -- 16:31:56 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/ipsec-events.rules
23/4/2024 -- 16:31:56 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/kerberos-events.rules
23/4/2024 -- 16:31:56 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/modbus-events.rules
23/4/2024 -- 16:31:56 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/nfs-events.rules
23/4/2024 -- 16:31:56 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/ntp-events.rules
23/4/2024 -- 16:31:56 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/smb-events.rules
23/4/2024 -- 16:31:56 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/smtp-events.rules
23/4/2024 -- 16:31:56 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/stream-events.rules
23/4/2024 -- 16:31:56 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/tls-events.rules
23/4/2024 -- 16:31:56 - <Info> -- Ignoring file 51f50afad3967db2f32b753c395f52bb/rules/emerging-deleted.rules
23/4/2024 -- 16:32:01 - <Info> -- Loaded 48784 rules.
23/4/2024 -- 16:32:29 - <Info> -- Disabled 21136 rules.
23/4/2024 -- 16:32:29 - <Info> -- Enabled 0 rules.
23/4/2024 -- 16:32:29 - <Info> -- Modified 0 rules.
23/4/2024 -- 16:32:29 - <Info> -- Dropped 0 rules.
23/4/2024 -- 16:32:30 - <Info> -- Enabled 241 rules for flowbit dependencies.
23/4/2024 -- 16:32:30 - <Info> -- Backing up current rules.
23/4/2024 -- 16:32:36 - <Info> -- Writing rules to /var/lib/suricata/rules/suricata.rules: total: 48784; enabled: 16169; added: 0; removed 0; modified: 0
23/4/2024 -- 16:32:36 - <Info> -- Writing /var/lib/suricata/rules/classification.config
23/4/2024 -- 16:32:37 - <Info> -- No changes detected, exiting.

从上面的输出可以看到,重新加载了规则。

2.14.4 非阻塞式重新加载(Non-blocking reload)

这种重新加载方式不会阻塞 Suricata 的运行,即 Suricata 不会在重新加载过程中暂停处理流量。

suricata-update --reload-command='sudo suricatasc -c ruleset-reload-nonblocking'

suricata-update 命令通常用于从远程源(如Emerging Threats或其他威胁情报提供商)下载和更新Suricata的规则集。

--reload-command 选项,告诉 suricata-update 在成功下载并更新本地规则文件后执行哪个命令来重新加载Suricata的规则集。

suricatasc -c ruleset-reload-nonblocking 命令用于触发 Suricata 重新加载其规则集,加载的是/etc/suricata/suricata.yaml配置文件里设置的规则文件,这里我设置的是规则目录是:/etc/suricata/rules/,规则文件是:suricata.rules 。

以上命令可以触发非阻塞式重新加载。

注:由于suricata-update更新规则,默认保存到的是/var/lib/suricata/rules/目录下的。

所有要想更新规则的话,得使用-o选项指定保存的目录 /etc/suricata/rules/

suricata-update  --reload-command='sudo suricatasc -c ruleset-reload-nonblocking' -o /etc/suricata/rules/

执行记录如下:

root@ndr:/usr/share/suricata/rules# suricata-update  --reload-command='sudo suricatasc -c ruleset-reload-nonblocking' -o /etc/suricata/rules/
25/4/2024 -- 10:52:56 - <Info> -- Using data-directory /var/lib/suricata.
25/4/2024 -- 10:52:56 - <Info> -- Using Suricata configuration /etc/suricata/suricata.yaml
25/4/2024 -- 10:52:56 - <Info> -- Using /usr/share/suricata/rules for Suricata provided rules.
25/4/2024 -- 10:52:56 - <Info> -- Found Suricata version 7.0.4 at /usr/bin/suricata.
25/4/2024 -- 10:52:56 - <Info> -- Loading /etc/suricata/disable.conf.
25/4/2024 -- 10:52:56 - <Info> -- Loading /etc/suricata/suricata.yaml
25/4/2024 -- 10:52:57 - <Info> -- Disabling rules for protocol pgsql
25/4/2024 -- 10:52:57 - <Info> -- Disabling rules for protocol modbus
25/4/2024 -- 10:52:57 - <Info> -- Disabling rules for protocol dnp3
25/4/2024 -- 10:52:57 - <Info> -- Disabling rules for protocol enip
25/4/2024 -- 10:52:57 - <Info> -- Checking https://rules.emergingthreats.net/open/suricata-7.0.4/emerging.rules.tar.gz.md5.
25/4/2024 -- 10:52:58 - <Info> -- Remote checksum has not changed. Not fetching.
25/4/2024 -- 10:52:58 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/app-layer-events.rules
25/4/2024 -- 10:52:58 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/decoder-events.rules
25/4/2024 -- 10:52:58 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/dhcp-events.rules
25/4/2024 -- 10:52:58 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/dnp3-events.rules
25/4/2024 -- 10:52:58 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/dns-events.rules
25/4/2024 -- 10:52:58 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/files.rules
25/4/2024 -- 10:52:58 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/http-events.rules
25/4/2024 -- 10:52:58 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/ipsec-events.rules
25/4/2024 -- 10:52:58 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/kerberos-events.rules
25/4/2024 -- 10:52:58 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/modbus-events.rules
25/4/2024 -- 10:52:58 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/nfs-events.rules
25/4/2024 -- 10:52:58 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/ntp-events.rules
25/4/2024 -- 10:52:58 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/smb-events.rules
25/4/2024 -- 10:52:58 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/smtp-events.rules
25/4/2024 -- 10:52:58 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/stream-events.rules
25/4/2024 -- 10:52:58 - <Info> -- Loading distribution rule file /usr/share/suricata/rules/tls-events.rules
25/4/2024 -- 10:52:58 - <Info> -- Ignoring file 51f50afad3967db2f32b753c395f52bb/rules/emerging-deleted.rules
25/4/2024 -- 10:53:04 - <Info> -- Loaded 48815 rules.
25/4/2024 -- 10:53:37 - <Info> -- Disabled 21140 rules.
25/4/2024 -- 10:53:37 - <Info> -- Enabled 0 rules.
25/4/2024 -- 10:53:37 - <Info> -- Modified 0 rules.
25/4/2024 -- 10:53:37 - <Info> -- Dropped 0 rules.
25/4/2024 -- 10:53:39 - <Info> -- Enabled 241 rules for flowbit dependencies.
25/4/2024 -- 10:53:39 - <Info> -- Backing up current rules.
25/4/2024 -- 10:53:46 - <Info> -- Writing rules to /etc/suricata/rules/suricata.rules: total: 48815; enabled: 16180; added: 34; removed 3; modified: 1228
25/4/2024 -- 10:53:46 - <Info> -- Writing /etc/suricata/rules/classification.config
25/4/2024 -- 10:53:47 - <Info> -- Testing with suricata -T.
25/4/2024 -- 10:54:25 - <Info> -- Running sudo suricatasc -c ruleset-reload-nonblocking.
{"message": "done", "return": "OK"}
25/4/2024 -- 10:54:25 - <Info> -- Done.

2.14.5 不同重新加载规则方法的使用场景

这两种重新加载方式的选择取决于具体的应用场景和需求。例如,在需要保证规则更新后立即生效且能够处理流量中断的情况下,可能会选择阻塞式重新加载;而在对实时性要求不高,或者希望避免由于重新加载导致的短暂服务中断的情况下,可能会选择非阻塞式重新加载。

3. 给规则设置设置IP白名单

有时候,我们需要给某条规则设置白名单,只需要修改规则的原目的IP即可。

例子

含义

!1.1.1.1

Every IP address but 1.1.1.1

![1.1.1.1, 1.1.1.2]

Every IP address but 1.1.1.1 and 1.1.1.2

$HOME_NET

Your setting of HOME_NET in yaml

[$EXTERNAL_NET, !$HOME_NET]

EXTERNAL_NET and not HOME_NET

[10.0.0.0/24, !10.0.0.5]

10.0.0.0/24 except for 10.0.0.5

[..., [....]]

[..., ![.....]]

规则示例:

alert ip any any -> !192.168.1.1 any (msg:"GPL ATTACK_RESPONSE id check returned root"; content:"uid=0|28|root|29|"; classtype:bad-unknown; sid:2100498; rev:7; metadata:created_at 2010_09_23, updated_at 2019_07_26;)

重新加载suricata规则。

sudo kill -USR2 $(pidof suricata)

 

  • 22
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Simo2024

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值