$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. 黄金含量版本——KTV

    呀,进来的都是盆友,首先先给大家拜年了,祝大家新年快乐,万事如意,家和万事兴~! 大家看了标题进来就不能让大家白进来,一定会让大家带着满满的果实. 下面我们就来讨论讨论KTV这个项目: (1)KTV的 ...

  2. delphi 判断MDI窗体的子窗体是否存在

    //***************************************************************************//函 数名: CreateForm //返 ...

  3. UIStakView的添加与移除

    subView和arrangedSubView对于Stack View的子控件添加和移除,我们是这样描述的. 添加-->(Stack View管理的subview) addArrangedSub ...

  4. 【靶场练习_sqli-labs】SQLi-LABS Page-3 (Stacked Injections)

    Less-39: ?id=1 and 1 ,?id=1 and 1 : 回显不同,数字型 ?id=0 union select 1,2,group_concat(table_name) from in ...

  5. (转)Java并发包:AtomicBoolean和AtomicReference

    转:https://blog.csdn.net/zxc123e/article/details/52057289 文章译自:http://tutorials.jenkov.com/java-util- ...

  6. MySQL中truncate误操作后的数据恢复案例

    MySQL中truncate误操作后的数据恢复案例 这篇文章主要介绍了MySQL中truncate误操作后的数据恢复案例,主要是要从日志中定位到truncate操作的地方然后备份之前丢失的数据,需要的 ...

  7. frida的js脚本处理正则的一个小坑

    frida的server模式需要python支持,所以js脚本中的正则需要多一次转义 比如匹配"/proc/{数字pid}" server: paramPath.match(&qu ...

  8. 为GitLab帐号添加SSH keys并连接GitLab

    https://blog.csdn.net/xyzchenxiaolin/article/details/51852333 为github帐号添加SSH keys使用git clone命令从GitLa ...

  9. centos 7.2 离线安装 gcc

    1.查看有没有挂载 centos 7.2 的镜像源文件 2.如果没有就通过服务端挂载 如果不知怎么挂载,就解压CentOS-7-x86_64-DVD-1511.iso 镜像文件,在Packages找到 ...

  10. 任正非:5G技术只独家卖给美国!不卖给韩国、日本、欧洲

    https://v.qq.com/x/page/g3001d0xvxe.html 我只转个标题,细节不管了. 呃,实际上就是说,老任头也决定向美国低头了,对不. 不过,也确实没办法. 该起床吃钙片了.