$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. vue和php-前后台交互

    vue和php-前后台交互 前端主要代码: <template> <div class="main-member-info"> <form @subm ...

  2. 九. jenkins用户权限管理

    由于jenkins默认的权限管理体系不支持用户组和角色的配置,所以需要使用第三方插件来支持角色的配置: Role-based Authorization Strategy 1.先安装插件,如下: 2. ...

  3. django4-模板,templates

    如何使用templates呢? 在views.py文件中,函数或者方法通过return render(request,"userInfor.html",{"info_li ...

  4. Python多进程、多线程和协程简介

    一.进程和线程 进程是一个执行中的程序.每个进程都拥有自己的地址空间.内存.数据栈以及其他用于跟踪执行的辅助数据.在单核CPU系统中的多进程,内存中可以有许多程序,但在给定一个时刻只有一个程序在运行: ...

  5. Spark Streaming + Kafka 整合向导之createDirectStream

    启动zk: zkServer.sh start 启动kafka:kafka-server-start.sh $KAFKA_HOME/config/server.properties 创建一个topic ...

  6. 【摘】Linux虚拟地址空间布局以及进程栈和线程栈总结

    在CSDN上看到的一篇文章,讲的还是满好的. 原文地址:Linux虚拟地址空间布局以及进程栈和线程栈总结 一:Linux虚拟地址空间布局 (转自:Linux虚拟地址空间布局) 在多任务操作系统中,每个 ...

  7. Java 编程技巧之数据结构

    前言: 介绍几种常见的java数据结构及应用. 使用HashSet判断主键是否存在 HashSet 实现 Set 接口,由哈希表(实际上是 HashMap )实现,但不保证 set  的迭代顺序,并允 ...

  8. linux 系统管理--进程管理

    目录 linux 系统管理--进程管理 一.进程基本概述 二.监控进程状态 三.进程的优先级[进阶] 四.企业案例,Linux假死是怎么回事 五.后台进程管理 六.系统平均负载[进阶] linux 系 ...

  9. go语言从例子开始之Example7.switch分支结构

    switch ,方便的条件分支语句 package main import "fmt" import "time" func main() { 一个基本的 sw ...

  10. js使用childnodes获取子节点时多了text节点

    当我们获取标签的节点时如果使用childnodes发现它会把空格和回车都算着节点,明明里面才有3个节点,结果显示5个,而且childnodes[0]="text" 在IE浏览器中没 ...