1、下载OWASP的ModSecurity规则

cd /etc/httpd
git clone https://github.com/SpiderLabs/owasp-modsecurity-crs.git
mv owasp-modsecurity-crs modsecurity-crs
cd modsecurity-crs
mv modsecurity_crs_10_setup.conf.example modsecurity_crs_10_setup.conf

2、在Apache中启用规则

vi /etc/httpd/conf/httpd.conf

末尾添加

<IfModule security2_module>
Include modsecurity-crs/modsecurity_crs_10_setup.conf
Include modsecurity-crs/base_rules/*.conf
Include modsecurity-crs/activated_rules/*.conf
</IfModule>

3、创建白名单

vi /etc/httpd/modsecuirty.d/whitelist.conf

#Whitelist file to control ModSec

<IfModule mod_security2.c>
SecRuleEngine On
SecRequestBodyAccess On
SecResponseBodyAccess On SecDataDir /tmp </IfModule>

4、自定义规则

vi /etc/httpd/modsecurity-crs/activated_rules/custom.conf

此处可以自己写一些规则或者移除一些规则。

IP白名单

SecRule REMOTE_ADDR "^192\.168\.1\.11" phase:1,log,allow,ctl:ruleEngine=off,id:100001

规则白名单

<LocationMatch .*>
SecRuleRemoveById 960020
</LocationMatch>

目录规则白名单

<LocationMatch “/home/www/test/”>
SecRuleRemoveById 300015 300016 300017
</LocationMatch>

或者

<Directory /path/to/dir>
SecRuleEngine Off
</Directory>

5、常见问题

本地测试时,如果启用全策略,访问web目录时。

Forbidden

You don't have permission to access /bWAPP/ on this server.

查看modsec日志

Message: Access denied with code 403 (phase 2). Pattern match "^[\\d.:]+$" at REQUEST_HEADERS:Host. [file "/etc/httpd/modsecurity-crs/base_rules/modsecurity_crs_21_protocol_anomalies.conf"] [line "98"] [id "960017"] [rev "2"] [msg "Host header is a numeric IP address"] [data "192.168.14.21"] [severity "WARNING"] [ver "OWASP_CRS/2.2.9"] [maturity "9"] [accuracy "9"] [tag "OWASP_CRS/PROTOCOL_VIOLATION/IP_HOST"] [tag "WASCTC/WASC-21"] [tag "OWASP_TOP_10/A7"] [tag "PCI/6.5.10"] [tag "http://technet.microsoft.com/en-us/magazine/2005.01.hackerbasher.aspx"]
Action: Intercepted (phase 2)
Apache-Handler: php5-script
Stopwatch: 1478141159604281 1340 (- - -)
Stopwatch2: 1478141159604281 1340; combined=316, p1=207, p2=82, p3=0, p4=0, p5=27, sr=23, sw=0, l=0, gc=0
Response-Body-Transformed: Dechunked
Producer: ModSecurity for Apache/2.7.3 (http://www.modsecurity.org/); OWASP_CRS/2.2.9.
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod_auth_gssapi/1.3.1
Engine-Mode: "ENABLED"

960017对应的规则

# Check that the host header is not an IP address
# This is not an HTTP RFC violation but it is indicative of automated client access.
# Many web-based worms propagate by scanning IP address blocks.
#
# -=[ Rule Logic ]=-
# This rule triggers if the Host header contains all digits (and possible port)
#
# -=[ References ]=-
# http://technet.microsoft.com/en-us/magazine/2005.01.hackerbasher.aspx
# SecRule REQUEST_HEADERS:Host "^[\d.:]+$" "phase:2,rev:'2',ver:'OWASP_CRS/2.2.9',maturity:'9',accuracy:'9',t:none,block,msg:'Host header is a numeric IP address',logdata:'%{matched_var}',severity:'4',id:'960017',tag:'OWASP_CRS/PROTOCOL_VIOLATION/IP_HOST',tag:'WASCTC/WASC-21',tag:'OWASP_TOP_10/A7',tag:'PCI/6.5.10',tag:'http://technet.microsoft.com/en-us/magazine/2005.01.hackerbasher.aspx',setvar:'tx.msg=%{rule.msg}',setvar:tx.anomaly_score=+%{tx.warning_anomaly_score},setvar:tx.%{rule.id}-OWASP_CRS/POLICY/IP_HOST-%{matched_var_name}=%{matched_var}"

在/etc/httpd/modsecurity-crs/activated_rules/custom.conf加入规则

<LocationMatch .*>
    SecRuleRemoveById 960017
</LocationMatch>

去掉对HTTP Header Host字段内容是否为IP地址的检测。默认如果是IP地址就会阻断访问。

配置OWASP的ModSecurity规则的更多相关文章

  1. [security][modsecurity] modsecurity 规则说明/中文/转发

    原文转发以防丢失. 地址: http://www.catssec.com:8090/exploit/?p=691 转来细读之后,并没有太多的参考价值  :( modsecurity规则手册 通用格式 ...

  2. Nginx配置location及rewrite规则

    Nginx配置location及rewrite规则 示例: location  = / {   # 精确匹配 / ,主机名后面不能带任何字符串   [ configuration A ] } loca ...

  3. ADFS 2.0 配置简介 PartⅢ – 声明规则语言

    上一篇我们最终把 ADFS 与应用之间的信任关系建立起来了,但是应用接收到的声明信息只有默认的两个,这次我们就来学学怎么配置声明. 一.声明存储配置 ADFS 目前默认支持三种方式的声明值存储,另外还 ...

  4. nginx配置 location及rewrite规则详解

    1. location正则写法 语法规则: location [=|~|~*|^~] /uri/ { … } =    开头表示精确匹配 ^~  开头表示uri以某个常规字符串开头,理解为匹配 url ...

  5. Spring Cloud Alibaba基础教程:Nacos配置的加载规则详解

    前情回顾: <Spring Cloud Alibaba基础教程:使用Nacos实现服务注册与发现> <Spring Cloud Alibaba基础教程:支持的几种服务消费方式(Res ...

  6. centos 7 配置iptables(转) + iptabes规则理解

    一.防火墙配置 1.检测并关闭firewall 1 2 3 4 5 systemctl status firewalld.service #检测是否开启了firewall   systemctl st ...

  7. SpringBoot整合mybatis——配置mybatis驼峰命名规则自动转换

    一.简述 mybatis驼峰式命名规则自动转换: 使用前提:数据库表设计按照规范“字段名中各单词使用下划线"_"划分”: 使用好处:省去mapper.xml文件中繁琐编写表字段列表 ...

  8. iptables配置顺序-两条规则会忽略后边的

    oracle在centos本机能够正常访问,关闭防火墙也能够远程访问,但是一旦开启防火墙则不能远程访问 尝试添加规则iptables -A INPUT -m state --state NEW -m ...

  9. k8s istio 配置请求的路由规则

    使用istio我们可以根据权重和HTTP headers来动态配置请求路由. 基于内容的路由 因为BookInfo示例部署了3个版本的评论微服务,我们需要设置一个默认路由. 否则,当你多次访问应用程序 ...

随机推荐

  1. swift实现饭否应用客户端源码

    swift 版 iOS 饭否客户端 源码下载:http://code.662p.com/view/13318.html 饭否是中国大陆地区第一家提供微博服务的网站,被称为中国版Twitter.用户可通 ...

  2. Eclipse部署项目的原理简介eclipse,wtpwebapps,tomcat

    转载请注明出处! http://www.cnblogs.com/libingbin/ 感谢您的阅读.如果文章对您有用,那么请轻轻点个赞,以资鼓励.

  3. String.Empty、null、“” 区别

    概念准备: 1.引用类型是将对象是实际数据保存在堆中, 将对象在堆中的地址保存在栈中. 2.值类型直接将实际数据存放在堆中,不会将对象在堆中的地址保存在栈中. 一.String.Empty和" ...

  4. Oracle索引梳理系列(五)- Oracle索引种类之表簇索引(cluster index)

    版权声明:本文发布于http://www.cnblogs.com/yumiko/,版权由Yumiko_sunny所有,欢迎转载.转载时,请在文章明显位置注明原文链接.若在未经作者同意的情况下,将本文内 ...

  5. 【hbase】——bulk load导入数据时value=\x00\x00\x00\x01问题解析

    一.存入数据类型 Hbase里面,rowkey是按照字典序进行排序.存储的value值,当用filter进行数据筛选的时候,所用的比较算法也是字典序的. 1.当存储的value值是float类型的时候 ...

  6. 大数据系统之监控系统(二)Flume的扩展

    一些需求是原生Flume无法满足的,因此,基于开源的Flume我们增加了许多功能. EventDeserializer的缺陷 Flume的每一个source对应的deserializer必须实现接口E ...

  7. SQL Server 2008 R2——用CTE进行递归计算求解累计值

    =================================版权声明================================= 版权声明:原创文章 谢绝转载  请通过右侧公告中的“联系邮 ...

  8. java 版本EChart使用

    一.简介 EChart是百度开发的js图表软件,用它我们可以很方便地以图形化的方式对数据进行分析统计.该种方式js在页面动态拼接json数据,再进行渲染.这种方法的优点是,灵活,可以随时进行修改.缺点 ...

  9. ActionBar详解

    转: 一.ActionBar介绍 在Android 3.0中除了我们重点讲解的Fragment外,Action Bar也是一个非常重要的交互元素,Action Bar取代了传统的tittle bar和 ...

  10. hadoop2.6.2+hbase+zookeeper环境搭建

    1.hadoop环境搭建,版本:2.6.2,参考:http://www.cnblogs.com/bookwed/p/5251393.html 启动服务:在master机器上,进入hadoop安装目录, ...