国外VPS的nginx防止xss和sql注入的方法:
将以下nginx配置文件代码放入到对应站点的.conf 配置文件server里,重启nginx即可,代码如下:
if($request_method !~* GET|POST){return444;}
#使用444错误代码减轻服务器负载压力
#防止sql注入
if($query_string ~*(\$|‘|–|[+|(%20)]union[+|(%20)]|[+|(%20)]insert[+|(%20)]|[+|(%20)]drop[+|(%20)]|[+|(%20)]truncate[+|(%20)]|[+|(%20)]update[+|(%20)]|[+|(%20)]from[+|(%20)]|[+|(%20)]grant[+|(%20)]|[+|(%20)]exec[+|(%20)]|[+|(%20)]where[+|(%20)]|[+|(%20)]select[+|(%20)]|[+|(%20)]and[+|(%20)]|[+|(%20)]or[+|(%20)]|[+|(%20)]count[+|(%20)]|[+|(%20)]exec[+|(%20)]|[+|(%20)]chr[+|(%20)]|[+|(%20)]mid[+|(%20)]|[+|(%20)]like[+|(%20)]|[+|(%20)]iframe[+|(%20)]|[\<|%3c]script[\>|%3e]|javascript|alert|webscan|dbappsecurity|style|confirm\(|innerhtml|innertext)(.*)$) { return 555; }
if ($uri ~* (/~).*) { return 501; }
if ($uri ~* (\\x.)) { return 501; }
#防止sql注入
if ($query_string ~* “[;’<>].*“) { return 509; }
if ($request_uri ~ ““) { return 509; }
if ($request_uri ~ (\/\.+)) { return 509; }
if ($request_uri ~ (\.+\/)) { return 509; }
#if ($uri ~* (insert|select|delete|update|count|master|truncate|declare|exec|\*|\’)(.*)$ ) { return 503; }
#防止sql注入
if ($request_uri ~* “(cost\()|(concat\()“) { return 504; }
if ($request_uri ~* “[+|(%20)]union[+|(%20)]“) { return 504; }
if ($request_uri ~* “[+|(%20)]and[+|(%20)]“) { return 504; }
if ($request_uri ~* “[+|(%20)]select[+|(%20)]“) { return 504; }
if ($request_uri ~* “[+|(%20)]or[+|(%20)]“) { return 504; }
if ($request_uri ~* “[+|(%20)]delete[+|(%20)]“) { return 504; }
if ($request_uri ~* “[+|(%20)]update[+|(%20)]“) { return 504; }
if ($request_uri ~* “[+|(%20)]insert[+|(%20)]“) { return 504; }
if ($query_string ~ “(<|%3C).*script.*(>|%3E)“) { return 505; }
if ($query_string ~ “GLOBALS(=|\[|\%[0–9A–Z]{0,2})“) { return 505; }
if ($query_string ~ “_REQUEST(=|\[|\%[0–9A–Z]{0,2})“) { return 505; }
if ($query_string ~ “proc/self/environ“) { return 505; }
if ($query_string ~ “mosConfig_[a–zA–Z_]{1,21}(=|\%3D)“) { return 505; }
if ($query_string ~ “base64_(en|de)code\(.*\)“) { return 505; }
if ($query_string ~ “[a–zA–Z0–9_]=http://”) { return 506; }
if($query_string ~“[a-zA-Z0-9_]=(\.\.//?)+”){return506;}
if($query_string ~“[a-zA-Z0-9_]=/([a-z0-9_.]//?)+”){return506;}
if($query_string ~“b(ultram|unicauca|valium|viagra|vicodin|xanax|ypxaieo)b”){return507;}
if($query_string ~“b(erections|hoodia|huronriveracres|impotence|levitra|libido)b”){return507;}
if($query_string ~“b(ambien|bluespill|cialis|cocaine|ejaculation|erectile)b”){return507;}
if($query_string ~“b(lipitor|phentermin|pro[sz]ac|sandyauer|tramadol|troyhamby)b”){return507;}
#根据自身情况添加删减上述判断参数,cURL、wget 这类的屏蔽有点儿极端
if($http_user_agent ~*YisouSpider|ApacheBench|WebBench|Jmeter|JoeDog|Havij|GetRight|TurnitinBot|GrabNet|masscan|mail2000|github|wget|curl|Java|python){return508;}
#同上,根据自身站点实际情况来添加删减下面的屏蔽拦截参数
if($http_user_agent ~*“Go-Ahead-Got-It”){return508;}
if($http_user_agent ~*“GetWeb!”){return508;}
if($http_user_agent ~*“Go!Zilla”){return508;}
if($http_user_agent ~*“Download Demon”){return508;}
if($http_user_agent ~*“Indy Library”){return508;}
if($http_user_agent ~*“libwww-perl”){return508;}
if($http_user_agent ~*“Nmap Scripting Engine”){return508;}
if($http_user_agent ~*“~17ce.com”){return508;}
if($http_user_agent ~*“WebBench*”){return508;}
if($http_user_agent ~*“spider”){return508;}#这个会影响国内某些搜索引擎爬虫,比如:搜狗
#拦截各恶意请求的 UA,可以通过分析站点日志文件或者waf日志作为参考配置
if($http_referer ~*xxx.com){return509;}
#拦截xxx.com站点测速节点的请求
if($http_referer ~*WebBench*“) { return 509; }
#拦截WebBench或者类似压力测试工具
一诺网络提供的国外vps,是一款弹性计算服务类产品,其功能基本上与传统的x86物理服务器相当,具备分钟级交付效率,可快速部署和创建所需要的业务应用环境,服务器资源和配置支持弹性伸缩;拥有管理便捷、易于操作等诸多优点。可以极大降低用户的IT使用成本,用户无需亲自搭建基础设施、简化了运维和管理的日常工作量,使得用户能够更专注于自身的业务发展和创新。