$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. jquery设置、判断、获取input单选标签选中状态

    1.设置某项单选input为选中状态: $("input[type='radio']").eq(1).attr('checked',true); ②也可设其属性checked为'c ...

  2. java使用开源类库Tesseract实现图片识别

    Tesseract-OCR支持中文识别,并且开源和提供全套的训练工具,是快速低成本开发的首选. Tess4J则是Tesseract在Java PC上的应用 Tesseract的OCR引擎最先由HP实验 ...

  3. CF 39E. What Has Dirichlet Got to Do with That?(记忆化搜索+博弈论)

    传送门 解题思路 首先很好写出一个\(O(ab)\)的记搜,但发现这样无法处理\(a=1\)和\(b=1\)的情况,这两种情况需要特判.首先\(a=1\)的情况,就是如果当前选手让\(a+1\)必胜, ...

  4. [CSP-S模拟测试]:树(树形DP+期望)

    题目描述 梦游中的你来到了一棵$N$个节点的树上.你一共做了$Q$个梦,每个梦需要你从点$u$走到点$v$之后才能苏醒,由于你正在梦游,所以每到一个节点后,你会在它连出去的边中等概率地选择一条走过去, ...

  5. 2018-2019-2 20175126谢文航 实验三《敏捷开发与XP实践》实验报告

    一.实验报告封面 课程:Java程序设计 班级:1751 班 姓名:谢文航 学号:20175126 指导教师:娄嘉鹏 实验日期:2019年5月2日 实验时间:--- 实验序号:实验三 实验名称:敏捷开 ...

  6. centos7不能远程登陆的方案

    网上找了很多,就算百度经验写的都是坑,代码如下: BROWSER_ONLY=no BOOTPROTO=static DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INI ...

  7. delphi 简单的发送字符串消息

    var pMes:^String; begin New(pMes); pMes^:=msg; PostMessage(Application.handle, WM_Custom, 0, Integer ...

  8. Javascript在ajax提交过程中页面显示加载中,请等待效果,并在提交过程中限制确定按钮防止多次提交,提交完成后,解除提交限制

    加载中,请等待div: <div id="load" class="center-in-center" style="display:none; ...

  9. ucenter 整合同步登录的内部实现原理

    1.用户登录discuz,通过logging.php文件中的函数uc_user_login对post过来的数据进行验证,也就是对username和password进行验证. 2.如果验证成功,将调用位 ...

  10. day106 支付功能与优惠券功能 contentype

    https://blog.csdn.net/Ayhan_huang/article/details/78626957 一.ContenType from django.db import models ...