Apache模块mod_security 和 Nginx过滤配置
1.安装mod_security
yum install mod_security
2.安装mod_security_crs
yum install mod_security_crs
3.在/etc/httpd/modsecurity.d建立exclude.conf文件用来排除无需检查的文件
<IfModule mod_security2.c>
<Location /PATH/>
SecRuleEngine off
</Location>
</IfModule>
白名单:
编辑modsecurity.conf
#vi /etc/modsecurity/modsecurity.conf
增加一行
SecRule REMOTE_ADDR "@ipMatch 192.168.30.0/24" "phase:1,nolog,allow"
忽略某个站的安全检测:
在VirtualHost 段内加入
SecRuleInheritance Off
SecRule通常规则的格式如下:
SecRule VARIABLES OPERATOR [ACTIONS]
第一部分,VARIABLES描述哪个变量被检查,取值通常有
REQUEST_COOKIES,REQUEST_COOKIES_NAMES,REQUEST_FILENAME,ARGS_NAMES,ARGS,XML,REQUEST_URI
第二部分,OPERATOR描述如何进行检查
第三部分可选的,ACTIONS,描述当操作进行成功的匹配一,个变量时具体怎么做。
// 示例
#如果cookie名称中有sg,通过
SecRule REQUEST_COOKIES_NAMES sg "phase:1,nolog,allow"
#匹配ip,直接通过
SecRule REQUEST_URI "@ipMatch 192.168.30.0/24" "phase:1,nolog,allow"
#可以使用rx来使用正则表达式,参数中含有dirty的通过
SecRule ARGS "@rx dirty" "phase:1,nolog,allow"
配置
# http guardian
SecGuardianLog |/etc/httpd/httpd-guardian
=======================================================================
Nginx的防注入配置:
建立drop_sql.conf文件,复制以下内容:
## Block SQL injections
set $block_sql_injections 0;
if ($query_string ~ "union.*select.*\(") {
set $block_sql_injections 1;
}
if ($query_string ~ "union.*all.*select.*") {
set $block_sql_injections 1;
}
if ($query_string ~ "concat.*\(") {
set $block_sql_injections 1;
}
if ($block_sql_injections = 1) {
return 403;
}
## Block file injections
set $block_file_injections 0;
if ($query_string ~ "[a-zA-Z0-9_]=http://") {
set $block_file_injections 1;
}
if ($query_string ~ "[a-zA-Z0-9_]=(\.\.//?)+") {
set $block_file_injections 1;
}
if ($query_string ~ "[a-zA-Z0-9_]=/([a-z0-9_.]//?)+") {
set $block_file_injections 1;
}
if ($block_file_injections = 1) {
return 403;
}
## Block common exploits
set $block_common_exploits 0;
if ($query_string ~ "(<|<).*script.*(>|>)") {
set $block_common_exploits 1;
}
if ($query_string ~ "GLOBALS(=|\[|\%[0-9A-Z]{0,2})") {
set $block_common_exploits 1;
}
if ($query_string ~ "_REQUEST(=|\[|\%[0-9A-Z]{0,2})") {
set $block_common_exploits 1;
}
if ($query_string ~ "proc/self/environ") {
set $block_common_exploits 1;
}
if ($query_string ~ "mosConfig_[a-zA-Z_]{1,21}(=|\=)") {
set $block_common_exploits 1;
}
if ($query_string ~ "base64_(en|de)code\(.*\)") {
set $block_common_exploits 1;
}
if ($block_common_exploits = 1) {
return 403;
}
## Block spam
set $block_spam 0;
if ($query_string ~ "\b(ultram|unicauca|valium|viagra|vicodin|xanax|ypxaieo)\b") {
set $block_spam 1;
}
if ($query_string ~ "\b(erections|hoodia|huronriveracres|impotence|levitra|libido)\b") {
set $block_spam 1;
}
if ($query_string ~ "\b(ambien|blue\spill|cialis|cocaine|ejaculation|erectile)\b") {
set $block_spam 1;
}
if ($query_string ~ "\b(lipitor|phentermin|pro[sz]ac|sandyauer|tramadol|troyhamby)\b") {
set $block_spam 1;
}
if ($block_spam = 1) {
return 403;
}
## Block user agents
set $block_user_agents 0;
# Don't disable wget if you need it to run cron jobs!
#if ($http_user_agent ~ "Wget") {
# set $block_user_agents 1;
#}
# Disable Akeeba Remote Control 2.5 and earlier
if ($http_user_agent ~ "Indy Library") {
set $block_user_agents 1;
}
# Common bandwidth hoggers and hacking tools.
if ($http_user_agent ~ "libwww-perl") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "GetRight") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "GetWeb!") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "Go!Zilla") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "Download Demon") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "Go-Ahead-Got-It") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "TurnitinBot") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "GrabNet") {
set $block_user_agents 1;
}
if ($block_user_agents = 1) {
return 403;
}
***********
在server段中包含该配置,
include drop_sql.conf;
Apache模块mod_security 和 Nginx过滤配置的更多相关文章
- apache上.htaccess转向nginx上配置.htaccess伪静态规则
nginx上配置.htaccess伪静态规则 在apache上.htaccess转向,只要apache编译的时候指明支持rewrite模块即可. 但是换到nginx上方法会有不同,有人说把.htacc ...
- Apache、tomcat、Nginx常用配置合集
配置文件地址: Apache: /etc/httpd/conf/httpd.conf tomcat: /usr/local/tomcat/conf/server.xml Nginx : /usr/l ...
- nginx安装配置+清缓存模块安装
经过一段时间的使用,发现nginx在并发与负载能力方面确实优于apache,现在已经将大部分站点从apache转到了nginx了.以下是nginx的一些简单的安装配置. 环境 操作系统:CentOS. ...
- nginx 安装配置+清缓存模块安装
经过一段时间的使用,发现 nginx 在并发与负载能力方面确实优于 apache,现在已经将大部分站点从 apache 转到了 nginx 了.以下是 nginx 的一些简单的安装配置.环境操作系统: ...
- nginx的yum安装,基本参数使用,编译参数说明和Nginx基本配置,模块安装
nginx的yum安装从nginx官网获取源 vim /etc/yum.repose.d/nginx.repo[nginx]name=nginx repobaseurl=http://nginx.or ...
- Nginx下配置SSL模块,支持https
Http与Https的区别 HTTP:是互联网上应用最为广泛的一种网络协议,是一个客户端和服务器端请求和应答的标准(TCP),用于从WWW服务器传输超文本到本地浏览器的传输协议,它可以使浏览器更加高效 ...
- 转:NGNIX模块开发——nginx的配置系统
From:http://tengine.taobao.org/book/chapter_02.html nginx的配置系统 nginx的配置系统由一个主配置文件和其他一些辅助的配置文件构成.这些配置 ...
- 如何查看nginx的版本及配置选项?nginx都配置了哪些的模块?
需求描述: 新接手别人的nginx,想要查看当前都配置了哪些模块 操作过程: 1.通过nginx -V选项查看nginx的配置选项 [root@hadoop3 sbin]# ./nginx -V ng ...
- 高性能Web服务器Nginx的配置与部署研究(13)应用模块之Memcached模块+Proxy_Cache双层缓存模式
通过<高性能Web服务器Nginx的配置与部署研究——(11)应用模块之Memcached模块的两大应用场景>一文,我们知道Nginx从Memcached读取数据的方式,如果命中,那么效率 ...
随机推荐
- Java学习——开端
学号 <Java程序设计>第1周学习总结(1) 教材学习内容总结(第一章) Java最早是由Sun公司研发,原称Oak(橡树),开发者之一的James Gosling被尊称为Java之父. ...
- DOM基础3
隔行变色 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF- ...
- Sqlserver自定义函数Function
一.FUNCTION: 在sqlserver2008中有3中自定义函数:标量函数/内联表值函数/多语句表值函数,首先总结下他们语法的异同点: 同点:1.创建定义是一样的: ...
- 内网配置DNS服务器,无域名,只有主机名
Hadoop集群中,使用DNS而不是hosts来访问服务器. 1. 安装bind软件 用root用户运行: yum -y install bind* 2. 配置named.conf文件 vi /etc ...
- ACM : HDU 2899 Strange fuction 解题报告 -二分、三分
Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- 【URAL】1960. Palindromes and Super Abilities
http://acm.timus.ru/problem.aspx?space=1&num=1960 题意:给一个串s,要求输出所有的s[0]~s[i],i<|s|的回文串数目.(|s|& ...
- Codeforces Beta Round #7
A题,应该是水题,我没看懂... B题,这题很多坑,注意x是LL,而且x = 0的情况,所以初始化要为-1,最后这题是内存管理啊..操作系统学的不好,题意读不懂啊. 申请内存的时候,是从头找 如果这一 ...
- SRM 615 DIV1 500
TC 都615了...时间过的真快啊. 第一次做出500分,心情还是很激动的,虽然看了很久的题解,TC官网上的题解,很详细,但是英语的...我搜了搜,发现一份日语的...好吧,我还是看看英语的吧... ...
- IOS开发常用设计模式
IOS开发常用设计模式 说起设计模式,感觉自己把握不了笔头,所以单拿出iOS开发中的几种常用设计模式谈一下. 单例模式(Singleton) 概念:整个应用或系统只能有该类的一个实例 在iOS开发我们 ...
- unix network programming volume1 sorce code build and get(UNIX網絡編程卷1第三版)
source code下载地址:unpv13e.tar.gz下载 (也有放一份在google cloud storage) compile 1. ./configure 2. cd lib make ...