nginx 另一WAF方式

http://blog.csdn.net/cnbird2008/article/details/8625179

 

 
 
  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 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值