-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoScanWithBurp.py
More file actions
134 lines (114 loc) · 4.36 KB
/
Copy pathAutoScanWithBurp.py
File metadata and controls
134 lines (114 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# This is a modification of the carbonator extension originally
# created by Blake Cornell of Integris Security LLC
# Released under GPL Version 2 license.
#
# Modifications were made by Carrie Roberts of Black Hills Information Security
# August 20, 2015
# BHISAutoScan.py Version 2.1
from burp import IBurpExtender
from burp import IHttpListener
from burp import IScannerListener
from java.net import URL
from java.io import File
import datetime
import time
class BurpExtender(IBurpExtender, IHttpListener, IScannerListener):
def registerExtenderCallbacks(self, callbacks):
self._callbacks = callbacks
self._callbacks.setExtensionName("AutoScanWithBurp")
self._helpers = self._callbacks.getHelpers()
self.clivars = None
self.spider_results=[]
self.scanner_results=[]
self.packet_timeout=5
if not self.processCLI():
self.log("No CLI's")
return None
else:
self.log("Processing CLI's")
self.clivars = True
self.log( "loading state . . .")
fileName = self.sessionToLoad
self._callbacks.restoreState(File(fileName))
self.log( "Done loading state")
self.log( "Initiating BHISAutoScan Against: " + str(self.url))
self.last_packet_seen= int(time.time()) #initialize the start of the spider/scan
#add to scope if not already in there.
if self._callbacks.isInScope(self.url) == 0:
self._callbacks.includeInScope(self.url)
#added to ensure that the root directory is scanned
base_request = str.encode(str("GET "+self.path+" HTTP/1.1\nHost: "+self.fqdn+"\n\n"))
if(self.scheme == 'https'):
self._callbacks.doActiveScan(self.fqdn,self.port,1,base_request)
else:
self._callbacks.doActiveScan(self.fqdn,self.port,0,base_request)
self._callbacks.sendToSpider(self.url)
self._callbacks.registerHttpListener(self)
self._callbacks.registerScannerListener(self)
while int(time.time())-self.last_packet_seen <= self.packet_timeout:
time.sleep(1)
self.log( "No packets seen in the last " + str(self.packet_timeout) + " seconds.")
self.log( "Removing Listeners")
self._callbacks.removeHttpListener(self)
self._callbacks.removeScannerListener(self)
self.log( "Generating Report")
self.generateReport('HTML')
self.log( "Report Generated")
self.log( "Closing Burp in " + str(self.packet_timeout) + " seconds.")
time.sleep(self.packet_timeout)
self.log( "Saving state for later review: " + self.sessionToSave)
self._callbacks.saveState(File(self.sessionToSave))
self.log( "done saving state")
if self.clivars:
self._callbacks.exitSuite(False)
return
def processHttpMessage(self, tool_flag, isRequest, current):
self.last_packet_seen = int(time.time())
if tool_flag == self._callbacks.TOOL_SPIDER and isRequest: #if is a spider request then send to scanner
self.spider_results.append(current)
self.log("Sending new URL to Vulnerability Scanner: URL # " + str(len(self.spider_results)))
if self.scheme == 'https':
self._callbacks.doActiveScan(self.fqdn,self.port,1,current.getRequest()) #returns scan queue, push to array
else:
self._callbacks.doActiveScan(self.fqdn,self.port,0,current.getRequest()) #returns scan queue, push to array
return
def newScanIssue(self, issue):
self.scanner_results.append(issue)
self.log( "New issue identified: Issue # " + str(len(self.scanner_results)))
return
def generateReport(self, format):
if format != 'XML':
format = 'HTML'
self._callbacks.generateScanReport(format,self.scanner_results,File(self.reportFile))
time.sleep(5)
return
def processCLI(self):
cli = self._callbacks.getCommandLineArguments()
if len(cli) < 0:
self.log( "Incomplete target information provided.")
return False
elif not cli:
self.log( "Extension loaded.")
return False
elif cli[0] == 'https' or cli[0] == 'http': #cli[0]=scheme,cli[1]=fqdn,cli[2]=port,cli[3]=path,cli[4]=reportFile,cli[5]=sessionToLoad,cli[6]=sessionToSave
self.scheme = cli[0]
self.fqdn = cli[1]
self.port = int(cli[2])
if len(cli) == 3:
self.path = '/'
elif len(cli) >= 4:
self.path = cli[3]
self.reportFile = cli[4]
self.sessionToLoad = cli[5]
self.sessionToSave = cli[6]
else:
self.log( "Unknown number of CLI arguments")
return False
self.url = URL(self.scheme,self.fqdn,self.port,self.path)
else:
self.log( "Invalid command line arguments supplied")
return False
return True
def log(self, logStr):
print str(time.time()) + " " + logStr
return