nginx 另一WAF方式

简介:
 
  1. nginx 另一WAF方式 
  2. 2013-03-01 10:57 116人阅读 评论(0) 收藏 举报 
  3. 使用方法: 
  4. vi /usr/local/nginx/conf/drop_sql.conf 
  5. 添加以下内容 
  6. 代码: 
  7. ## Block SQL injections 
  8. set $block_sql_injections 0; 
  9. if ($query_string ~ "union.*select.*\(") { 
  10. set $block_sql_injections 1; 
  11. if ($query_string ~ "union.*all.*select.*") { 
  12. set $block_sql_injections 1; 
  13. if ($query_string ~ "concat.*\(") { 
  14. set $block_sql_injections 1; 
  15. if ($block_sql_injections = 1) { 
  16. return 403; 
  17.  
  18. ## Block file injections 
  19. set $block_file_injections 0; 
  20. if ($query_string ~ "[a-zA-Z0-9_]=http://") { 
  21. set $block_file_injections 1; 
  22. if ($query_string ~ "[a-zA-Z0-9_]=(\.\.//?)+") { 
  23. set $block_file_injections 1; 
  24. if ($query_string ~ "[a-zA-Z0-9_]=/([a-z0-9_.]//?)+") { 
  25. set $block_file_injections 1; 
  26. if ($block_file_injections = 1) { 
  27. return 403; 
  28.  
  29. ## Block common exploits 
  30. set $block_common_exploits 0; 
  31. if ($query_string ~ "(<|%3C).*script.*(>|%3E)") { 
  32. set $block_common_exploits 1; 
  33. if ($query_string ~ "GLOBALS(=|\[|\%[0-9A-Z]{0,2})") { 
  34. set $block_common_exploits 1; 
  35. if ($query_string ~ "_REQUEST(=|\[|\%[0-9A-Z]{0,2})") { 
  36. set $block_common_exploits 1; 
  37. if ($query_string ~ "proc/self/environ") { 
  38. set $block_common_exploits 1; 
  39. if ($query_string ~ "mosConfig_[a-zA-Z_]{1,21}(=|\%3D)") { 
  40. set $block_common_exploits 1; 
  41. if ($query_string ~ "base64_(en|de)code\(.*\)") { 
  42. set $block_common_exploits 1; 
  43. if ($block_common_exploits = 1) { 
  44. return 403; 
  45.  
  46. ## Block spam 
  47. set $block_spam 0; 
  48. if ($query_string ~ "\b(ultram|unicauca|valium|viagra|vicodin|xanax|ypxaieo)\b") { 
  49. set $block_spam 1; 
  50. if ($query_string ~ "\b(erections|hoodia|huronriveracres|impotence|levitra|libido)\b") { 
  51. set $block_spam 1; 
  52. if ($query_string ~ "\b(ambien|blue\spill|cialis|cocaine|ejaculation|erectile)\b") { 
  53. set $block_spam 1; 
  54. if ($query_string ~ "\b(lipitor|phentermin|pro[sz]ac|sandyauer|tramadol|troyhamby)\b") { 
  55. set $block_spam 1; 
  56. if ($block_spam = 1) { 
  57. return 403; 
  58.  
  59. ## Block user agents 
  60. set $block_user_agents 0; 
  61.  
  62. # Don't disable wget if you need it to run cron jobs! 
  63. #if ($http_user_agent ~ "Wget") { 
  64. # set $block_user_agents 1; 
  65. #} 
  66.  
  67. # Disable Akeeba Remote Control 2.5 and earlier 
  68. if ($http_user_agent ~ "Indy Library") { 
  69. set $block_user_agents 1; 
  70.  
  71. # Common bandwidth hoggers and hacking tools. 
  72. if ($http_user_agent ~ "libwww-perl") { 
  73. set $block_user_agents 1; 
  74. if ($http_user_agent ~ "GetRight") { 
  75. set $block_user_agents 1; 
  76. if ($http_user_agent ~ "GetWeb!") { 
  77. set $block_user_agents 1; 
  78. if ($http_user_agent ~ "Go!Zilla") { 
  79. set $block_user_agents 1; 
  80. if ($http_user_agent ~ "Download Demon") { 
  81. set $block_user_agents 1; 
  82. if ($http_user_agent ~ "Go-Ahead-Got-It") { 
  83. set $block_user_agents 1; 
  84. if ($http_user_agent ~ "TurnitinBot") { 
  85. set $block_user_agents 1; 
  86. if ($http_user_agent ~ "GrabNet") { 
  87. set $block_user_agents 1; 
  88.  
  89. if ($block_user_agents = 1) { 
  90. return 403; 
  91.  
  92. 在nginx.conf配置文件中的server段中加入 
  93. include drop_sql.conf; 
  94.  
  95. 重新加载nginx配置文件即可生效 
  96. /usr/local/nginx/sbin/nginx -s reload 

 本文转自it你好 51CTO博客,原文链接:http://blog.51cto.com/itnihao/745950,如需转载请自行联系原作者

相关文章
|
应用服务中间件 nginx
WAF实战nginx+naxsi(转载)
https://www.cnblogs.com/stone-dan-dan/p/stone1.html 第一部分---安装nginx+naxsi       首先,我说一下我的环境是ubuntu14.04LTS版本,并且是在root用户下进行操作的,省去了很多麻烦,至于其他的版本也应该是大同小异的,区别也极有可能只是命令的不通而已。
1562 0
|
缓存 应用服务中间件 网络安全
Nginx + Lua 搭建网站WAF防火墙
Nginx + Lua 搭建网站WAF防火墙目录: 前言1.在线安装1.1.修改yum源地址1.2.在线安装Nginx1.3.端口放行1.4.验证安装2.知识拓展2.1.编译参数2.2.安装目录2.3.
2862 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的能力.
2051 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安全的利器     对于配置以及基础教程在下面这本书中都已经提到了有感兴趣的可以联系我 目前这.
2137 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安全的利器。
1719 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
nginx 另一WAF方式
使用方法: vi /usr/local/nginx/conf/drop_sql.conf 添加以下内容代码: ## Block SQL injections set $block_sql_injections 0; if ($query_string ~ "union.
779 0
|
24天前
|
运维 前端开发 应用服务中间件
LNMP详解(八)——Nginx动静分离实战配置
LNMP详解(八)——Nginx动静分离实战配置
28 0