nginx 另一WAF方式

简介: 使用方法:vi /usr/local/nginx/conf/drop_sql.conf添加以下内容代码:## Block SQL injectionsset $block_sql_injections 0;if ($query_string ~ "union.
使用方法:
vi /usr/local/nginx/conf/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 ~ "(<|%3C).*script.*(>|%3E)") {
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}(=|\%3D)") {
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;
}

在nginx.conf配置文件中的server段中加入
include drop_sql.conf;

重新加载nginx配置文件即可生效
/usr/local/nginx/sbin/nginx -s reload
目录
相关文章
|
应用服务中间件 nginx
WAF实战nginx+naxsi(转载)
https://www.cnblogs.com/stone-dan-dan/p/stone1.html 第一部分---安装nginx+naxsi       首先,我说一下我的环境是ubuntu14.04LTS版本,并且是在root用户下进行操作的,省去了很多麻烦,至于其他的版本也应该是大同小异的,区别也极有可能只是命令的不通而已。
1561 0
|
缓存 应用服务中间件 网络安全
Nginx + Lua 搭建网站WAF防火墙
Nginx + Lua 搭建网站WAF防火墙目录: 前言1.在线安装1.1.修改yum源地址1.2.在线安装Nginx1.3.端口放行1.4.验证安装2.知识拓展2.1.编译参数2.2.安装目录2.3.
2858 0
|
应用服务中间件 PHP nginx
nginx+ngx_lua支持WAF防护功能
安装nginx+ngx_lua支持WAF防护功能 nginx lua模块淘宝开发的nginx第三方模块,它能将lua语言嵌入到nginx配置中,从而使用lua就极大增强了nginx的能力.
1624 0
|
应用服务中间件 PHP nginx
nginx+ngx_lua支持WAF防护功能
安装nginx+ngx_lua支持WAF防护功能 nginx lua模块淘宝开发的nginx第三方模块,它能将lua语言嵌入到nginx配置中,从而使用lua就极大增强了nginx的能力.
2050 0
|
应用服务中间件 PHP nginx
Nginx安装ngx_lua_waf改版
ngx_lua_waf改版,增加网段、UA、主机白名单等功能,修复了一些bug,项目地址:https://github.com/whsir/ngx_lua_waf ngx_lua_waf改版基于ngx_lua_waf二次修改,增加了一些必要的功能,使用起来简单,高性能和轻量级。
1516 0
|
Web App开发 安全 应用服务中间件
Nginx配合modsecurity实现企业级WAF应用防火墙功能
      ModSecurity原本是Apache上的一款开源waf,可以有效的增强web安全性,目前已经支持nginx和IIS,配合nginx的灵活和高效,可以打造成生产级的WAF,是保护和审核web安全的利器     对于配置以及基础教程在下面这本书中都已经提到了有感兴趣的可以联系我 目前这.
2134 0
|
tengine 应用服务中间件 PHP
Nginx 用ModSecurity实现WAF功能
转载:https://www.52os.net/articles/nginx-use-modsecurity-module-as-waf.html nginx配合modsecurity实现WAF功能 January 26, 2015 modsecurity原本是Apache上的一款开源waf,可以有效的增强web安全性,目前已经支持nginx和IIS,配合nginx的灵活和高效,可以打造成生产级的WAF,是保护和审核web安全的利器。
1717 0
|
应用服务中间件 nginx 网络安全
nginx_lua_waf 部署、测试记录
ngx_lua_waf ngx_lua_waf是一个基于lua-nginx-module(openresty)的web应用防火墙 源码:https://github.com/loveshell/ngx_lua_waf 安装部署 系统版本:Centos6.
1720 0
|
应用服务中间件 nginx
|
18天前
|
运维 前端开发 应用服务中间件
LNMP详解(八)——Nginx动静分离实战配置
LNMP详解(八)——Nginx动静分离实战配置
23 0