$request_uri
This variable is equal to the *original* request URI as received from the client including the args. It cannot be modified. Look at $uri for the post-rewrite/altered URI. Does not include host name. Example: "/foo/bar.php?arg=baz"
这个变量等于从客户端发送来的原生请求URI,包括参数。它不可以进行修改。$uri变量反映的是重写后/改变的URI。不包括主机名张小三资源网。例如:"/foo/bar.php?arg=baz"

$uri
This variable is the current request URI, without any arguments (see $args for those). This variable will reflect any modifications done so far by internal redirects or the index module. Note this may be different from $request_uri, as $request_uri is what was originally sent by the browser before any such modifications. Does not include the protocol or host name. Example: /foo/bar.html
这个变量指当前的请求URI,不包括任何参数(见$args)。这个变量反映任何内部重定向或index模块所做的修改。注意,这和$request_uri不同,因$request_uri是浏览器发起的不做任何修改的原生URI。不包括协议及主机名。例如张小三资源:"/foo/bar.html"

$document_uri
The same as $uri.
同$uri.

下面是收集的一些简单规则:

if ($query_string ~* ".*('|--|union|insert|drop|truncate|update|from|grant|exec|where|select|and|or|count|chr|mid|like|iframe|script|alert|webscan|dbappsecurity|style|confirm|innerhtml|innertext|class).*")
{ return ; }
if ($uri ~* .*(viewsource.jsp)$) { return ; }
if ($uri ~* .*(/~).*) { return ; }

修补空字节解析漏洞

if ($query_string ~* ".*[;'<>].*") { return ; }
if ($request_uri ~ " ") { return ; }

禁止未允许的IP访问目录执行PHP。未开启pathinfo的情况下在location ~ [^/]\.php(/|$)前加如下

location ~ /(xxx)/.*\.(php|php5)?$
{ allow 允许的IP; deny all; }

开启pathinfo的情况下:在location ~ [^/]\.php(/|$)前加如下

location ^~ /xxx/ { #default_type text/plain; #expires 30d; allow 允许的IP; deny all; }

内部:

if ($uri ~* (.*)(insert|select|delete|update|count|master|truncate|declare|exec|\*|%|\')(.*)$ ) { return 403; }    

外部:

if ($request_uri ~* "(cost\()|(concat\()") { return ; }
if ($request_uri ~* "[+|(%20)]union[+|(%20)]") { return ; }
if ($request_uri ~* "[+|(%20)]and[+|(%20)]") { return ; }
if ($request_uri ~* "[+|(%20)]select[+|(%20)]") { return ; }
if ($request_uri ~* "[+|(%20)]or[+|(%20)]") { return ; }
if ($request_uri ~* "[+|(%20)]delete[+|(%20)]") { return ; }
if ($request_uri ~* "[+|(%20)]update[+|(%20)]") { return ; }
if ($request_uri ~* "[+|(%20)]insert[+|(%20)]") { return ; }

溢出过滤

if ($query_string ~ "(<|%3C).*script.*(>|%3E)") { return ; }
if ($query_string ~ "GLOBALS(=|\[|\%[0-9A-Z]{0,2})") { return ; }
if ($query_string ~ "_REQUEST(=|\[|\%[0-9A-Z]{0,2})") { return ; }
if ($query_string ~ "proc/self/environ") { return ; }
if ($query_string ~ "mosConfig_[a-zA-Z_]{1,21}(=|\%3D)") { return ; }
if ($query_string ~ "base64_(en|de)code\(.*\)") { return ; }

文件注入禁止

if ($query_string ~ "[a-zA-Z0-9_]=http://") { return ; }
if ($query_string ~ "[a-zA-Z0-9_]=(\.\.//?)+") { return ; }
if ($query_string ~ "[a-zA-Z0-9_]=/([a-z0-9_.]//?)+") { return ; }

一些头部的参考:

if ($http_user_agent ~ ApacheBench|WebBench|Jmeter|JoeDog|Havij|GetRight|TurnitinBot|GrabNet|masscan|mail2000|github|wget|curl) { return ; }
if ($http_user_agent ~ "Go-Ahead-Got-It") { return ; }
if ($http_user_agent ~ "GetWeb!") { return ; }
if ($http_user_agent ~ "Go!Zilla") { return ; }
if ($http_user_agent ~ "Download Demon") { return ; }
if ($http_user_agent ~ "Indy Library") { return ; }
if ($http_user_agent ~ "libwww-perl") { return ; }
if ($http_user_agent ~ "Nmap Scripting Engine") { return ; }
if ($http_user_agent ~ "Load Impact") { return ; }
if ($http_user_agent ~ "~17ce.com") { return ; }
if ($http_user_agent ~ "WebBench*") { return ; }
if ($http_referer ~* 17ce.com) { return ; }
if ($http_user_agent ~* qiyunce) { return ; }
if ($http_user_agent ~* YunGuanCe) { return ; }
if ($http_referer ~* WebBench*") { return 444; }
if ($http_user_agent ~ "BLEXBot") { return ; }
if ($http_user_agent ~ "MJ12bot") { return ; }
if ($http_user_agent ~ "semalt.com") { return ; }
屏蔽webkaka
iptables -I INPUT -s 122.226.213.3 -j DROP
加或者不加引号的效果都是一样的,但是如果名称中有空格则必须加双引号
~*不区分大小写 ~区分大小写

参考:Block Exploits
www.361way.com/nginx-ant-injection/2558.html

nginx防止SQL注入规则的更多相关文章

  1. Nginx 防止SQL注入、XSS攻击的实践配置方法

    下班的时候,发现博客访问缓慢,甚至出现504错误,通过 top -i 命令查看服务器负载发现负载数值飙升到3.2之多了,并且持续时间越来越频繁直至持续升高的趋势,还以为是被攻击了,对来访IP进行了阈值 ...

  2. nginx服务器防sql注入/溢出攻击/spam及禁User-agents

    本文章给大家介绍一个nginx服务器防sql注入/溢出攻击/spam及禁User-agents实例代码,有需要了解的朋友可进入参考. 在配置文件添加如下字段即可  代码如下 复制代码 server { ...

  3. web攻击之八:溢出攻击(nginx服务器防sql注入/溢出攻击/spam及禁User-agents)

    一.什么是溢出攻击 首先, 溢出,通俗的讲就是意外数据的重新写入,就像装满了水的水桶,继续装水就会溢出,而溢出攻击就是,攻击者可以控制溢出的代码,如果程序的对象是内核级别的,如dll.sys文件等,就 ...

  4. [SQL注入3]from_sqli_to_shell_II

    [SQL注入1]这关学习盲注 ,这篇还有些东西没理透,后面搞明白了再修改. http://www.pentesterlab.com/exercises/from_sqli_to_shell_II/ 准 ...

  5. 【转载】以Java的视角来聊聊SQL注入

    以Java的视角来聊聊SQL注入 原创 2017-08-08 javatiku Java面试那些事儿 在大二就接触过sql注入,之前一直在学习windows逆向技术,认为web安全以后不是自己的从业方 ...

  6. Bypass ngx_lua_waf SQL注入防御(多姿势)

    0x00 前言 ​ ngx_lua_waf是一款基于ngx_lua的web应用防火墙,使用简单,高性能.轻量级.默认防御规则在wafconf目录中,摘录几条核心的SQL注入防御规则: select.+ ...

  7. 23. Bypass ngx_lua_waf SQL注入防御(多姿势)

    0x00 前言 ngx_lua_waf是一款基于ngx_lua的web应用防火墙,使用简单,高性能.轻量级.默认防御规则在wafconf目录中,摘录几条核心的SQL注入防御规则: select.+(f ...

  8. TSRC挑战赛:WAF之SQL注入绕过挑战实录

    转自腾讯 博文作者:TSRC白帽子 发布日期:2014-09-03 阅读次数:1338 博文内容: 博文作者:lol [TSRC 白帽子] 第二作者:Conqu3r.花开若相惜 来自团队:[Pax.M ...

  9. 重新学习MySQL数据库11:以Java的视角来聊聊SQL注入

    本文转自互联网 本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查看 https://github.com/h2pl/Java-Tutorial ...

随机推荐

  1. k-近邻算法(kNN)测试算法:作为完整程序验证分类器

    #测试算法:作为完整程序验证分类器 def datingClassTest(): hoRatio = 0.10 #设置测试集比重,前10%作为测试集,后90%作为训练集 datingDataMat,d ...

  2. Java常用数据结构Set, Map, List

    1. Set Set相对于List.Map是最简单的一种集合.集合中的对象不按特定的方式排序,并且没有重复对象. 特点: 它不允许出现重复元素: 不保证和政集合中元素的顺序 允许包含值为null的元素 ...

  3. BZOJ 2741: 【FOTILE模拟赛】L(可持久化Trie+分块)

    传送门 解题思路 首先求出前缀异或和,那么问题就转化成了区间内选两个数使得其异或和最大.数据范围不是很大考虑分块,设\(f[x][i]\)表示第\(x\)块开头到\(i\)这个位置与\(a[i]\)异 ...

  4. BUUCTF | SQL COURSE 1

    一开始还以为是在登录框进行注入,于是fuzzing了一下发现一个注入点都没有 1 and 1 1 and 0 1' and '1 1' and '0 1" and "1 1&quo ...

  5. 四两拨千斤,ARM是如何运作、靠什么赚钱的

    在智能手机.平板大行其道的今天,ARM这个名字我们几乎每天都要见到或者听到几次,作为编辑的我更是如此,每天涉及到的新闻总是或多或少跟ARM扯上关系,它还与Intel.AMD.NVIDA等公司有说不清道 ...

  6. 112、TensorFlow初始化变量

    # 创建一个变量 # 最简单创建一个变量的方法就是调用 tf.get_variable function import tensorflow as tf # 下面创建了一个三维的张量大小是 [1,2, ...

  7. Java + selenium 元素定位(2)之By LinkText/PartialLinkText

    本章介绍的两种方法都是对于网页上的文字链接的定位操作.根据名字,我们就可以看出来,这两者其实很相似,那么他们的不同在哪里呢. By LinkText()方法,是对一个的网页超链接,我们所需要输入的关键 ...

  8. python3 zip 与tf.data.Data.zip的用法

    ###python自带的zip函数 与 tf.data.Dataset.zip函数 功能用法相似 ''' zip([iterator1,iterator2,]) 将可迭代对象中对应的元素打包成一个元祖 ...

  9. Python开发简介

    年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语言的一种继承 . 最新的TIOBE排行榜,Python已经占据世界第四名的位置, Python崇尚优美 ...

  10. OpenCV2马拉松第9圈——再谈对照度(对照度拉伸,直方图均衡化)

    收入囊中 lookup table 对照度拉伸 直方图均衡化 葵花宝典 lookup table是什么东西呢? 举个样例,假设你想把图像颠倒一下,f[i] = 255-f[i],你会怎么做? for( ...