/
passwordHashScanner.py
218 lines (187 loc) · 7.15 KB
/
passwordHashScanner.py
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
'''
Written by: Brian Berg - www.github.com/xexzy
hashMaker.py is used generate a file of hashes.
the format of the of hashes is [hash]:[algorithm] example: aGFzaGNhdA==:Base64
'''
from burp import IBurpExtender
from burp import ITab
from burp import IScannerCheck
from burp import IScanIssue
#from java.net import URL
from java.awt import Dimension
from javax import swing
import os.path
from array import array
from java.lang import Runnable
#from java.io import PrintWriter
class BurpExtender(IBurpExtender, ITab, IScannerCheck, IScanIssue):
def registerExtenderCallbacks(self, callbacks):
self.hashes = {}
#self._stdout = PrintWriter(callbacks.getStdout(), True)
self._callbacks = callbacks
self._helpers = callbacks.getHelpers()
self._callbacks.setExtensionName("Password Hash Scanner")
self._callbacks.registerScannerCheck(self)
self._fileLocation = None
self._jPanel = swing.JPanel()
boxVertical = swing.Box.createVerticalBox()
boxHorizontal = swing.Box.createHorizontalBox()
getFileButton = swing.JButton('Open hashout.txt',actionPerformed=self.getFile)
self._fileText = swing.JTextArea("", 1, 50)
boxHorizontal.add(getFileButton)
boxHorizontal.add(self._fileText)
boxVertical.add(boxHorizontal)
boxHorizontal = swing.Box.createHorizontalBox()
submitQueryButton = swing.JButton('Parse hash file',actionPerformed=self.hashParse)
boxHorizontal.add(submitQueryButton)
boxVertical.add(boxHorizontal)
boxHorizontal = swing.Box.createHorizontalBox()
boxHorizontal.add(swing.JLabel("Output"))
boxVertical.add(boxHorizontal)
boxHorizontal = swing.Box.createHorizontalBox()
self._resultsTextArea = swing.JTextArea()
resultsOutput = swing.JScrollPane(self._resultsTextArea)
resultsOutput.setPreferredSize(Dimension(500,200))
boxHorizontal.add(resultsOutput)
boxVertical.add(boxHorizontal)
self._jPanel.add(boxVertical)
# add the custom tab to Burp's UI
self._callbacks.addSuiteTab(self)
return
#Appends results to the resultsTextArea
def appendToResults(self, s):
self._resultsTextArea.append(s)
def getFile(self, button):
chooser = swing.JFileChooser()
c = chooser.showOpenDialog(None)
if chooser is not None:
if (chooser.currentDirectory and chooser.selectedFile.name) is not None:
self._fileLocation = str(chooser.currentDirectory) + os.sep + str(chooser.selectedFile.name)
self._fileText.setText(self._fileLocation)
else:
self._fileText.setText("File Not Valid, Try Again")
def hashParse(self, button):
hashFile = self._fileLocation
try: # Attempt to open file
source = open(hashFile)
source.close()
except:
print "hashout.txt file not found (Check if Path and Filename is Correct)\n"
return
with open(hashFile,"r") as hashout:
for line in hashout:
hashWord = line.split(":")[0].strip()
hashType = line.split(":")[1].strip()
self.hashes[hashWord] = hashType
output = "Parsed hashes\n"
output += "\n".join(self.hashes.keys())
output += "\n"
output += "#"*20
output += "\n"
self.appendToResults(output)
def getTabCaption(self):
return "Hash Check"
def getUiComponent(self):
return self._jPanel
def consolidateDuplicateIssues(self, existingIssue, newIssue):
if (existingIssue.getIssueDetail() == newIssue.getIssueDetail()):
return -1
else:
return 0
def doPassiveScan(self, baseRequestResponse):
scan_issues = []
tmp_issues = []
self._CustomScans = CustomScans(baseRequestResponse, self._callbacks)
issuename = "Potential password hash match"
issuelevel = "Information"
tmp_issues = self._CustomScans.findReflections(issuename, issuelevel, self.hashes)
scan_issues = scan_issues + tmp_issues
if len(scan_issues) > 0:
return scan_issues
else:
return None
def doActiveScan(self, baseRequestResponse, insertionPoint):
scan_issues = []
tmp_issues = []
self._CustomScans = CustomScans(baseRequestResponse, self._callbacks)
issuename = "Potential password hash match"
issuelevel = "Information"
tmp_issues = self._CustomScans.findReflections(issuename, issuelevel, self.hashes)
scan_issues = scan_issues + tmp_issues
if len(scan_issues) > 0:
return scan_issues
else:
return None
class CustomScans:
def __init__(self, requestResponse, callbacks):
# Set class variables with the arguments passed to the constructor
self._requestResponse = requestResponse
self._callbacks = callbacks
# Get an instance of IHelpers, which has lots of useful methods, as a class
# variable, so we have class-level scope to all the helper methods
self._helpers = self._callbacks.getHelpers()
# Put the parameters from the HTTP message in a class variable so we have class-level scope
self._params = self._helpers.analyzeRequest(requestResponse.getRequest()).getParameters()
return
def findReflections(self, issuename, issuelevel, hashes):
self.hashes = hashes
scan_issues = []
offset = array('i', [0, 0])
response = self._requestResponse.getResponse()
request = self._requestResponse.getRequest()
responseLength = len(response)
requestLength = len(request)
for hashWord in self.hashes.keys(): # checks to see if the password hash is in requests and responses
if hashWord in self._helpers.bytesToString(response):
offsets = []
start = self._helpers.indexOf(response, hashWord, False, 0, responseLength)
#marking the offsets isn't working
offset[0] = start
offset[1] = start + len(hashWord)
issuedetail = "HTTP Response contains this potential hash: {0} ({1})".format(hashWord,self.hashes[hashWord])
scan_issues.append(ScanIssue(self._requestResponse.getHttpService(),
self._helpers.analyzeRequest(self._requestResponse).getUrl(),
[self._callbacks.applyMarkers(self._requestResponse, None, offsets)],
issuename, issuelevel, issuedetail))
if hashWord in self._helpers.bytesToString(request):
offsets = []
start = self._helpers.indexOf(request, hashWord, False, 0, requestLength)
#marking offsets isn't working :(
offset[0] = start
offset[1] = start + len(hashWord)
issuedetail = "HTTP Request contains this potential hash: {0} ({1})".format(hashWord,self.hashes[hashWord])
scan_issues.append(ScanIssue(self._requestResponse.getHttpService(),
self._helpers.analyzeRequest(self._requestResponse).getUrl(),
[self._callbacks.applyMarkers(self._requestResponse, None, offsets)],
issuename, issuelevel, issuedetail))
return (scan_issues)
class ScanIssue(IScanIssue):
def __init__(self, httpservice, url, requestresponsearray, name, severity, detailmsg):
self._url = url
self._httpservice = httpservice
self._requestresponsearray = requestresponsearray
self._name = name
self._severity = severity
self._detailmsg = detailmsg
def getUrl(self):
return self._url
def getHttpMessages(self):
return self._requestresponsearray
def getHttpService(self):
return self._httpservice
def getRemediationDetail(self):
return None
def getIssueDetail(self):
return self._detailmsg
def getIssueBackground(self):
return None
def getRemediationBackground(self):
return None
def getIssueType(self):
return 0
def getIssueName(self):
return self._name
def getSeverity(self):
return self._severity
def getConfidence(self):
return "Certain"