亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

nginx如何防止xss和sql注入

小新
903
2020-12-28 15:09:15
欄目: 云計算

nginx如何防止xss和sql注入


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或者類似壓力測試工具


0
巴南区| 两当县| 蓬莱市| 鹤庆县| 孝感市| 吉安市| 浮山县| 昌都县| 黎川县| 横山县| 金溪县| 昌江| 逊克县| 香港| 龙州县| 和静县| 徐水县| 惠来县| SHOW| 宣化县| 饶阳县| 滦平县| 峨山| 丹凤县| 宁远县| 沁阳市| 汝阳县| 新乡县| 额敏县| 郁南县| 汪清县| 吐鲁番市| 神农架林区| 竹山县| 交城县| 安宁市| 明溪县| 九龙坡区| 天气| 德安县| 蕲春县|