通过自动分析modsecurity审核日志生成modsecurity异常规则的工具。
modsecurity-exception-factor的Python项目详细描述
modsecurity异常生成器是通过自动分析modsecurity审核日志生成modsecurity异常规则的工具。这对避免误报和拒绝合法客户非常有用,几乎是必不可少的。
安装
pip install modsecurity-exception-generator
用法
命令选项
-d
SQL URL of the data store where the ModSecurity audit log parsed data will be stored and loaded from.
Example: ‘sqlite:////tmp/modsecurity-exception-factory.db’.
-i[可选]
Path to the ModSecurity audit log file to parse.
One can use ‘-‘ as a value for this parameter to read the audit log data from standard input.
-c[可选]
Path of the optional configuration file.
基本示例
modsecurity-exception-generator \ -i /path/to/modsec_audit.log \ -d "sqlite:////tmp/service.db"\ > modsecurity_crs_15_exceptions.conf
zcat modsec_audit.log.*.gz \ | modsecurity-exception-generator \ -i - \ -d "sqlite:////tmp/service.db"\ > modsecurity_crs_15_exceptions.conf
警告
The produced exceptions must be loaded BEFORE the rules they are applied to.
删除多余的异常
简单地运行“modsecurity exception generator”程序生成异常,就像在基本示例中一样,可能会生成一些多余的异常规则。因此,我们需要一些先进的选择,以获得更聪明的结果。这就是使用-c选项给出的yaml配置文件的用处所在。
yaml配置文件支持以下指令:
忽略
指示异常生成器最容易忽略的日志。
示例
忽略由ID为981176的规则生成的任何日志消息。
ignore: rule_id: [981176]
这也可以应用于其他变量,如'host-name'(目标主机名),'request-filename'(目标url)或'payload-container'(与规则匹配的变量)。
最小出现次数阈值
忽略影响小于minimum_occurrence_count_threshold的异常记录消息出现次数。
最大值,阈值
有时,异常规则可能具有具有太多值的条件,如以下示例所示。
SecRule REQUEST_FILENAME "@rx ^(/foo_bar|/blabla|/test_2/|...)$" ...
此条件可以通过设置^ {STR 1 } $Max MuxUnValueA.CurtTyPosith>而忽略,低于正则表达式中的值个数。
核心规则集
的配置示例ignore: rule_id: [981174, 981176, 981203, 981200, 981201, 981202, 981203, 981204, 981205, 981220] minimum_occurrence_count_threshold: 1000