禁用特定目录的modsecurity

如何为特定的目录禁用modsecurity。 我在phpMyAdmin中遇到由基于规则的modsecurity跳闸引起的错误。 我有以下文件设置:

# /etc/httpd/modsecurity.d/modsecurity_crs_15_customrules.conf <LocationMatch "^/phpMA/"> SecRuleEngine Off </LocationMatch> # /etc/httpd/modsecurity.d/modsecurity_crs_60.custom.conf <LocationMatch '^/phpMA/*'> SecRuleRemoveById 950004 SecRuleRemoveById 950005 SecRuleRemoveById 950006 SecRuleRemoveById 960010 SecRuleRemoveById 960012 </LocationMatch> 

从我能find的第一个文件应该禁用它,但它仍然旅行,所以我试图添加它跳到60文件的规则ID,但它仍然抱怨。

我在CentOS 5.3上运行以下软件包:

  • mod_security的-2.5.0-jason.2
  • 的httpd-2.2.8-jason.3
  • MOD-PHP5,Apache2的-的Zend-CE-5.2.10-65

SecRuleEngineclosures必须工作。 你有没有尝试把SecRuleEngine放入目录:

 <Directory /var/www/site/phpMA> SecRuleEngine Off </Directory> 

而不是LocationMatch?

某些服务器和Web主机上,可以通过.htaccess禁用ModSecurity,但只能完全禁用(不是单独的规则)。

要限制这个特定的URL,你可以在下面的<If>语句中指定一个正则expression式…

 ### DISABLE mod_security firewall ### Some rules are currently too strict and are blocking legitimate users ### We only disable it for URLs that contain the regex below ### The regex below should be placed between "m#" and "#" ### (this syntax is required when the string contains forward slashes) <IfModule mod_security.c> <If "%{REQUEST_URI} =~ m#/admin/#"> SecFilterEngine Off SecFilterScanPOST Off </If> </IfModule> 

切勿禁用所有规则! 这会造成严重的安全问题!

您需要使用tail -f /var/log/apache2/modsec_audit.log命令来观察mod安全的日志文件,并逐一排除phpmyadmin接口上的错误。

接下来,添加:

 <Directory /path/to/phpmyadmin> <IfModule security2_module> SecRuleRemoveByTag "WEB_ATTACK/SQL_INJECTION" {And other rules you need to disable ...} </IfModule> </Directory> 

到/etc/apache2/mods-enabled/modsecurity.conf

您需要删除的标签将会像这样在日志文件中。 有关删除特定文件夹规则的完整说明,请参阅项目的Github wiki 。