modsecurity 将某些类型的 cookies 列入白名单

modsecurity 将某些类型的 cookies 列入白名单

我发现我们的服务器上生成的 cookie 似乎来自网站中的第三方对象,并且在用户登录或浏览网站时不会显示。

这些 cookie 是随机的,但都以 Wm 开头。因此其中一些可能是 wm_cm_12345-12345-12345-12345,而其中一些可能是 wm-wtchd-22。我在想,如果它们是 Wm*,我或许可以让它们不发出警报。

我如何将以 Wm 开头的 cookie 列入白名单?

以及您可能还有什么其他想法想要包含在内以便我可以将其列入白名单?

谢谢

示例 Cookie

TX:981243-Detects classic SQL injection probings 2/2-OWASP_CRS/WEB_ATTACK/SQLI-REQUEST_COOKIES:wm_rx_123456eabcdef7890_0edb4989-1523-ff12-ccab-beddddaaffccc. [file "/etc/httpd/modsecurity.d/activated_rules/modsecurity_crs_49_inbound_blocking.conf"] [line "26"] [id "981176"] [msg "Inbound Anomaly Score Exceeded (Total Score: 41, SQLi=9, XSS=): Last Matched Message: 981243-Detects classic SQL injection probings 2/2"] [data "Last Matched Data: \\x22:61"] [hostname "Somefoowebsite.com"] [uri "/images/nyancat.jpg"] 

我看到的另一个例子:

[30/Nov/2015:13:54:27 --0700] [bumblebeetune.com/sid#7fee134ee758][rid#7fee13b510d8][/nyancat.foo][2] Warning. Pattern match "(.*)" at TX:981243-Detects classic SQL injection probings 2/2-OWASP_CRS/WEB_ATTACK/SQLI-REQUEST_COOKIES:[30/Nov/2015:13:54:27 --0700] [bumblebeetuna.com/sid#7fee134ee758][rid#7fee13b510d8][/nyancat.foo][2] Warning. Pattern match "(.*)" at TX:981243-Detects classic SQL injection probings 2/2-OWASP_CRS/WEB_ATTACK/SQLI-REQUEST_COOKIES:wm_ct_877bb6e0e4744fd6a270f70f3e0c8a67_d464ab47-3cf0-fe3f-89d5-bd785f7bdcfa. [file "/etc/httpd/modsecurity.d/activated_rules/modsecurity_crs_49_inbound_blocking.conf"] [line "26"] [id "981176"] [msg "Inbound Anomaly Score Exceeded (Total Score: 18, SQLi=4, XSS=): Last Matched Message: 981243-Detects classic SQL injection probings 2/2"] [data "Last Matched Data: \x22:61"]. [file "/etc/httpd/modsecurity.d/activated_rules/modsecurity_crs_49_inbound_blocking.conf"] [line "26"] [id "981176"] [msg "Inbound Anomaly Score Exceeded (Total Score: 18, SQLi=4, XSS=): Last Matched Message: 981243-Detects classic SQL injection probings 2/2"] [data "Last Matched Data: \x22:61"]

答案1

你可以做你想做的事,你可以添加这样的配置(详细信息这里):

SecRuleUpdateTargetById 981243 !REQUEST_COOKIES:'/^wm.*/'

事实上,这项功能已经内置于一些常规 Cookie 中,这些 Cookie 被该规则错误地标记为误报(Google Analytics 使用的 __utm 和类似分析软件使用的 _pk_ref),正如您在查看规则定义原始规则标记:

SecRule REQUEST_COOKIES|!REQUEST_COOKIES:/__utm/|!REQUEST_COOKIES:/_pk_ref/|REQUEST_COOKIES_NAMES|ARGS_NAMES|ARGS|XML:/*“(?i:(?:[\”' ´ ´’‘]\s*?\*.+(?:x?or|div|like|between|and|id)\W*?[\"'''] \d)|(?:\^[\”' ´’‘])|(?:^[\w\s\"'´''-]+(?<=and\s)(?<=or|xor|div|like|between|and\s)(?<=xor\s)(?<=nand\s)(?<=not\s)(?<=\|\|)(?<=\&\&)\w+()|(?:[\”' ´ ´’‘][\s\d]*?[^\w\s]+\W*?\d\W*?.*?[\"'''\d])|(?:[\”' ´’‘]\s*?[^\w\s?]+\s*?[^\w\s]+\s*?[\"'´''])|(?:[\”' ´’‘]\s*?[^\w\s]+\s*?[\W\d].*?(?:#|--))|(?:[\"'´''].?*\s?\d)|(?:[\"' ´’‘]\s*?(x?or|div|like|between|and)\s[^\d]+[\w-]+.*?\d)|(?:[()\*<>%+-][\w-]+[^\w\s]+[\"'´''][^,]))" "phase:2,capture,t:none,t:urlDecodeUni,block,msg:'检测经典 SQL 注入探测 2/2',id:'981243',tag:'OWASP_CRS/WEB_ATTACK/SQL_INJECTION',logdata:'匹配数据:在 %{MATCHED_VAR_NAME} 中找到 %{TX.0}: %{MATCHED_VAR}',严重性:'2',setvar:'tx.msg=%{rule.id}-%{rule.msg}',setvar:tx.sql_injection_score=+1,setvar:tx.anomaly_score=+%{tx.critical_anomaly_score},setvar:'tx.%{tx.msg}-OWASP_CRS/WEB_ATTACK/SQLI-%{matched_var_name}=%{tx.0}'”

现在,如果您可以弄清楚我们的正则表达式,那么您就比我更优秀了,但是您可以在一开始就看到它适用于哪些 cookie 的配置。

请注意,最好添加上述配置来动态修改规则,而不是编辑规则本身,因为升级规则将覆盖任何编辑,而可以保留覆盖(假设它们位于升级后仍然存在的单独的覆盖文件中)。

相关内容