Other/其他

Nginx 拦截非法字符禁止过滤url访问特定字符访问

阿里云

前缀为无限,后面的精准屏蔽字符 123

  1. if  ($request_uri ~* "123") {
  2. return 403   "I've recorded your ip Wait to check the water meter";
  3. }
也想出现在这里?联系我们
创客主机

前缀为 index.php,后面的精准屏蔽字符 123

  1. if  ($request_uri  ~* "/index.php\123") {
  2. return 403   "I've recorded your ip Wait to check the water meter";
  3. }

当访问的 url 中含有某个字段时返回 404

  1. location / {
  2.  # 当访问的url中含有/%#时返回404
  3.         if ($request_uri ~* "/%#") {
  4.             return 404;
  5.         }
  6.         #当访问url的后面带有?的链接 返回404
  7.         if ($request_uri ~*  ^/a/m/(.*)\.HTML\?(.*)$) {
  8.              return 404;
  9.         }
  10.  }

本站测试代码,小白一键复制(注:需要自行根据网站程序定义)
宝塔为例:/www/server/panel/vhost/nginx/你的网站域名.conf,复制代码点击保存

  1. #前缀为无限,后面的是屏蔽字符
  2. if  ($request_uri ~* "../../../../../../") {
  3. return 403   "I've recorded your ip Wait to check the water meter";
  4. }
  5. #前缀为无限,后面的是屏蔽字符
  6. if  ($request_uri ~* ";") {
  7. return 403   "I've recorded your ip Wait to check the water meter";
  8. }
  9. #前缀为无限,后面的是屏蔽字符
  10. if  ($request_uri ~* "&amp") {
  11. return 403   "I've recorded your ip Wait to check the water meter";
  12. }
  13. #前缀为无限,后面的是屏蔽字符
  14. if  ($request_uri ~* "base64") {
  15. return 403   "I've recorded your ip Wait to check the water meter";
  16. }
  17. #前缀为index.php屏蔽,后面的是屏蔽字符
  18. if  ($request_uri  ~* "/index.php\&") {
  19. return 403   "I've recorded your ip Wait to check the water meter";
  20. }
  21. #前缀为index.php屏蔽,后面的是屏蔽字符
  22. if  ($request_uri  ~* "/index.php\?") {
  23. return 403   "I've recorded your ip Wait to check the water meter";
  24. }
  25. #前缀为index.php屏蔽,后面的是屏蔽字符
  26. if  ($request_uri  ~* "/index.php\;") {
  27. return 403   "I've recorded your ip Wait to check the water meter";
  28. }
  29. #前缀为index.php屏蔽,后面的是屏蔽字符
  30. if  ($request_uri  ~* "/index.php\=") {
  31. return 403   "I've recorded your ip Wait to check the water meter";
  32. }
  33. #前缀为index.php屏蔽,后面的是屏蔽字符
  34. if  ($request_uri  ~* "/index.php\=") {
  35. return 403   "I've recorded your ip Wait to check the water meter";
  36. }
  37. #前缀为index.php屏蔽,后面的是屏蔽字符
  38. if  ($request_uri  ~* "/index.php\_") {
  39. return 403   "I've recorded your ip Wait to check the water meter";
  40. }
  41. #前缀为index.php屏蔽,后面的是屏蔽字符
  42. if  ($request_uri  ~* "/index.php\./") {
  43. return 403   "I've recorded your ip Wait to check the water meter";
  44. }
  45. #前缀为index.php屏蔽,后面的是屏蔽字符
  46. if  ($request_uri  ~* "/index.php\:") {
  47. return 403   "I've recorded your ip Wait to check the water meter";
  48. }
  49. #前缀为index.php屏蔽,后面的是屏蔽字符
  50. if  ($request_uri  ~* "/index.php\base64") {
  51. return 403   "I've recorded your ip Wait to check the water meter";
  52. }
  53. #前缀为index.php屏蔽,后面的是屏蔽字符
  54. if  ($request_uri  ~* "/index.php\%") {
  55. return 403   "I've recorded your ip Wait to check the water meter";
  56. }
  57. #前缀为index.php屏蔽,后面的是屏蔽字符
  58. if  ($request_uri  ~* "/index.php\wp-content") {
  59. return 403   "I've recorded your ip Wait to check the water meter";
  60. }
  61. #前缀为index.php屏蔽,后面的是屏蔽字符
  62. if  ($request_uri  ~* "/index.php\;amp") {
  63. return 403   "I've recorded your ip Wait to check the water meter";
  64. }

sql 语句过滤

  1. if ($request_uri ~* "(cost\()|(concat\()") {
  2.                  return 444;
  3.          }
  4.          if ($request_uri ~* "[+|(%20)]union[+|(%20)]") {
  5.                  return 444;
  6.          }
  7.          if ($request_uri ~* "[+|(%20)]and[+|(%20)]") {
  8.                  return 444;
  9.          }
  10.          if ($request_uri ~* "[+|(%20)]select[+|(%20)]") {
  11.                  return 444;
  12.          }

文件注入禁止

  1. set $block_file_injections 0;
  2. if ($query_string ~ “[a-zA-Z0-9_]=http://) {
  3. set $block_file_injections 1;
  4. }
  5. if ($query_string ~ “[a-zA-Z0-9_]=(\.\.//?)+”) {
  6. set $block_file_injections 1;
  7. }
  8. if ($query_string ~ “[a-zA-Z0-9_]=/([a-z0-9_.]//?)+”) {
  9. set $block_file_injections 1;
  10. }
  11. if ($block_file_injections = 1) {
  12. return 444;
  13. }

溢出攻击过滤

  1. set $block_common_exploits 0;
  2. if ($query_string ~ “(<|%3C).*script.*(>|%3E)) {
  3. set $block_common_exploits 1;
  4. }
  5. if ($query_string ~ “GLOBALS(=|\[|\%[0-9A-Z]{0,2})) {
  6. set $block_common_exploits 1;
  7. }
  8. if ($query_string ~ “_REQUEST(=|\[|\%[0-9A-Z]{0,2})) {
  9. set $block_common_exploits 1;
  10. }
  11. if ($query_string ~ “proc/self/environ”) {
  12. set $block_common_exploits 1;
  13. }
  14. if ($query_string ~ “mosConfig_[a-zA-Z_]{1,21}(=|\%3D)) {
  15. set $block_common_exploits 1;
  16. }
  17. if ($query_string ~ “base64_(en|de)code\(.*\)) {
  18. set $block_common_exploits 1;
  19. }
  20. if ($block_common_exploits = 1) {
  21. return 444;
  22. }

spam 字段过滤

  1. set $block_spam 0;
  2. if ($query_string ~ “\b(ultram|unicauca|valium|viagra|vicodin|xanax|ypxaieo)\b”) {
  3. set $block_spam 1;
  4. }
  5. if ($query_string ~ “\b(erections|hoodia|huronriveracres|impotence|levitra|libido)\b”) {
  6. set $block_spam 1;
  7. }
  8. if ($query_string ~ “\b(ambien|blue\spill|cialis|cocaine|ejaculation|erectile)\b”) {
  9. set $block_spam 1;
  10. }
  11. if ($query_string ~ “\b(lipitor|phentermin|pro[sz]ac|sandyauer|tramadol|troyhamby)\b”) {
  12. set $block_spam 1;
  13. }
  14. if ($block_spam = 1) {
  15. return 444;
  16. }

user-agents 头过滤

  1. set $block_user_agents 0;
  2. if ($http_user_agent ~ “Wget”) {
  3.  set $block_user_agents 1;
  4. }
  5. # Disable Akeeba Remote Control 2.5 and earlier
  6. if ($http_user_agent ~ “Indy Library”) {
  7. set $block_user_agents 1;
  8. }
  9. # Common bandwidth hoggers and hacking tools.
  10. if ($http_user_agent ~ “libwww-perl”) {
  11. set $block_user_agents 1;
  12. }
  13. if ($http_user_agent ~ “GetRight”) {
  14. set $block_user_agents 1;
  15. }
  16. if ($http_user_agent ~ “GetWeb!) {
  17. set $block_user_agents 1;
  18. }
  19. if ($http_user_agent ~ “Go!Zilla”) {
  20. set $block_user_agents 1;
  21. }
  22. if ($http_user_agent ~ “Download Demon”) {
  23. set $block_user_agents 1;
  24. }
  25. if ($http_user_agent ~ “Go-Ahead-Got-It”) {
  26. set $block_user_agents 1;
  27. }
  28. if ($http_user_agent ~ “TurnitinBot”) {
  29. set $block_user_agents 1;
  30. }
  31. if ($http_user_agent ~ “GrabNet”) {
  32. set $block_user_agents 1;
  33. }
  34. if ($block_user_agents = 1) {
  35. return 444;
  36. }
  37. }

自动防护

  1. if ($request_uri ~* \.(htm|do)\?(.*)$) {
  2.            set $req $2;
  3.         }
  4.         if ($req ~* "(cost\()|(concat\()") {
  5.                 return 503;
  6.         }
  7.         if ($req ~* "union[+|(%20)]") {
  8.                 return 503;
  9.         }
  10.         if ($req ~* "and[+|(%20)]") {
  11.                 return 503;
  12.         }
  13.         if ($req ~* "select[+|(%20)]") {
  14.                 return 503;
  15.         }

注:使用上也需要进行相应的调整

Nginx 拦截非法字符禁止过滤 url 访问特定字符访问

已有 229 人购买
查看演示升级 VIP立刻购买

收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!