首页
社区
课程
招聘
[原创]利用BurpSuite到SQLMap批量测试SQL注入
发表于: 2018-11-14 19:44 8313

[原创]利用BurpSuite到SQLMap批量测试SQL注入

2018-11-14 19:44
8313

前言

通过Python脚本把Burp的HTTP请求提取出来交给SQLMap批量测试,提升找大门户网站SQL注入点的效率。

导出Burp的请求包

配置到Burp的代理后浏览门户站点,Burp会将URL纪录存储在HTTP History选项卡的内容里

 

 

导出Burp的请求包到SQLMAP中测试SQL注入漏洞,可以通过【Filter】选择【Show only parametrized requests】筛选出需要测试的URL请求。

 

 

Ctrl+A全选所有的请求条目,右击点击保存【Save items】

 

 

默认输出的HTTP请求包是经过Base64编码后的。可以选择勾选掉【Base64-encode requests and responses】

配置SQLMap

环境变量里把SQLMap设置为直接打开cmd窗口就可以使用。

Burp-To-SQLMap Script

测试环境:Windows10、Python2。

 

脚本测试命令,使用示例代码保存的Brup包不需要勾选掉Base64的编码。因为不用Base64编码的文件数据看起来太混乱了。

- 导出的文件名如果是burp情况


把Burp导出的文件放到脚本目录下,直接用这个脚本就可以了。

> Burp-to-sqlmap.py


- 自定义参数

  Usage: ./burp-to-sqlmap.py [options]"
    print"  Options: -f, --file               <BurpSuit State File>"
    print"  Options: -o, --outputdirectory    <Output Directory>"
    print"  Options: -s, --sqlmappath         <SQLMap Path>"
    print"  Options: -p, --proxy              <Use Proxy>"
    print"  Example: python burp-to-sqlmap.py -f [BURP-STATE-FILE] -o [OUTPUT-DIRECTORY] -s [SQLMap-Path] -p [Proxy]"

代码:

#encoding: utf-8


import os
from bs4 import BeautifulSoup
import os.path
import argparse
import sys
import base64

# SQLMap自定义选项
_options = " --technique BEST --batch --threads 10 "


def usage():
    print" "
    print"  Usage: ./burp-to-sqlmap.py [options]"
    print"  Options: -f, --file               <BurpSuit State File>"
    print"  Options: -o, --outputdirectory    <Output Directory>"
    print"  Options: -s, --sqlmappath         <SQLMap Path>"
    print"  Options: -p, --proxy              <Use Proxy>"
    print"  Example: python burp-to-sqlmap.py -f [BURP-STATE-FILE] -o [OUTPUT-DIRECTORY] -s [SQLMap-Path] -p [Proxy]"
    print" "


parser = argparse.ArgumentParser()
parser.add_argument("-f", "--file",default="burp")
parser.add_argument("-o", "--outputdirectory",default="output")
parser.add_argument("-s", "--sqlmappath")
parser.add_argument("-p", "--proxy")
args = parser.parse_args()

if not args.file or (os.path.exists("burp") == False):
    usage()
    sys.exit(0)

if os.path.exists("output") == False:
    os.mkdir("output")

if args.proxy:
    proxyvalue = "--proxy " + args.proxy
else:
    proxyvalue = ""

vulnerablefiles = []
filename = args.file
directory = args.outputdirectory
sqlmappath = args.sqlmappath
if not os.path.exists(directory):
    os.makedirs(directory)

# 提取数据包
packetnumber = 0
print " [+] Exporting Packets ..."
with open(filename, 'r') as f:
    soup = BeautifulSoup(f.read(), "html.parser")
    for i in soup.find_all("request"):
        packetnumber = packetnumber + 1
        print "   [-] Packet " + str(packetnumber) + " Exported."
        outfile = open(os.path.join(args.outputdirectory, str(packetnumber) + ".txt"), "w")
        outfile.write(base64.b64decode(i.text.strip()))
    print " "
    print str(packetnumber) + " Packets Exported Successfully."
    print " "

# SQLMap测试
print " [+] Testing SQL Injection on packets ...  (Based on your network connection Test can take up to 5 minutes.)"
for file in os.listdir(directory):
    print "   [-] Performing SQL Injection on packet number " + file[:-4] + ". Please Wait ..."
    _command = "sqlmap -r " + directory + "\\" + file + _options + proxyvalue + " > " + directory + "\\testresult" + file
    print _command
    os.system(_command)
    if 'is vulnerable' in open(directory + "\\testresult" + file).read() or "Payload:" in open(
            directory + "\\testresult" + file).read():
        print "    - URL is Vulnerable."
        vulnerablefiles.append(file)
    else:
        print "    - URL is not Vulnerable."
    print "    - Output saved in " + directory + "\\testresult" + file
print " "
print "--------------"
print "Test Done."
print "Result:"
if not vulnerablefiles:   
    print "No vulnerabilities found on your target."
else:
    for items in vulnerablefiles:
        print "Packet " + items[:-4] + " is vulnerable to SQL Injection. for more information please see " + items
print "--------------"
print " "

测试效果

 

参考

https://www.exploit-db.com/docs/english/45428-bulk-sql-injection-using-burp-to-sqlmap.pdf


[课程]Linux pwn 探索篇!

收藏
免费 4
支持
分享
打赏 + 1.00雪花
打赏次数 1 雪花 + 1.00
 
赞赏  junkboy   +1.00 2018/11/14
最新回复 (9)
雪    币: 4634
活跃值: (936)
能力值: ( LV13,RANK:350 )
在线值:
发帖
回帖
粉丝
2

除此外,还有多种方法可以结合Burp的请求测试

 

1、Burp与SQLMap结合测试插件
https://www.freebuf.com/sectool/45239.html

 

2、配置burpsuite下记录所有的request记录,并保存在指定文件夹。

 

执行命令:sqlmap.py -l burp.log --batch -smart  即可对burp.log中保存的所有request进行注入扫描。

  Batch:会自动选择yes

  Smart:启发式快速判断,节约时间。

  window版的sqlmap最后能注入的URL都会保存到C:\Users\Administrator\.sqlmap文件夹下。

3、sqlmapapi.py

 

调用sqlmapapi的开源项目,不能检测POST注入

 

https://github.com/zt2/sqli-hunter

 

https://github.com/LeeHDsniper/AutoSqli

 

https://github.com/az0ne/AZScanner

 

https://github.com/0xbug/SQLiScanner

2018-11-14 19:50
1
雪    币: 11716
活跃值: (133)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
lipss 除此外,还有多种方法可以结合Burp的请求测试 1、Burp与SQLMap结合测试插件 https://www.freebuf.com/sectool/45239.html 2、配置bu ...
感谢分享
2018-11-14 19:54
1
雪    币: 3561
活跃值: (541)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
fighter
2018-11-14 20:13
0
雪    币: 163
活跃值: (11)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
还能这么玩,强
2018-11-14 21:25
2
雪    币: 966
活跃值: (1310)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
老铁666
2018-11-28 10:02
0
雪    币: 257
活跃值: (15)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
请问:那如果使用工具过程中ip被网站加黑名单怎么办??或者说在使用sqlmap的时候如何隐藏自己的ip?
2018-12-1 20:38
0
雪    币: 4634
活跃值: (936)
能力值: ( LV13,RANK:350 )
在线值:
发帖
回帖
粉丝
8
大大星 请问:那如果使用工具过程中ip被网站加黑名单怎么办??或者说在使用sqlmap的时候如何隐藏自己的ip?
嗯,我觉得你这个问题。

1、Sqlmap中有个选项,是有–proxy参数的。可以代理本地,然后通过中间服务器来代理ip!也就是类似SS的方式。如果不熟悉SQLMap用法,建议查手册(自己找)
https://wenku.baidu.com/view/88b1320166ec102de2bd960590c69ec3d4bbdb70.html

2、ip被网站加黑名单,你可以购买网上一些提供IP代理的服务(自己找)。搞个接口,扫描的时候随机切换IP。。

2018-12-2 18:53
1
雪    币: 534
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
能这么玩,强 
2018-12-3 20:52
0
雪    币: 257
活跃值: (15)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
通过您的解答我大致明白,感谢前辈的无私解答~
2018-12-10 10:57
0
游客
登录 | 注册 方可回帖
返回
//