-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathEncodeDecodeHash.py
More file actions
304 lines (255 loc) · 11.1 KB
/
EncodeDecodeHash.py
File metadata and controls
304 lines (255 loc) · 11.1 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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
__author__ = 'Jake Miller (@LaconicWolf)'
__date__ = '20190206'
__version__ = '0.01'
__description__ = """Burp Extension that encodes, decodes,
and hashes user input. Inspired by a
similar tool in OWASP's ZAP.
"""
from burp import IBurpExtender, ITab
from javax import swing
from java.awt import BorderLayout
import sys
import threading
import base64
import urllib
import binascii
import cgi
import json
import re
import hashlib
from HTMLParser import HTMLParser
try:
from exceptions_fix import FixBurpExceptions
except ImportError:
pass
class BurpExtender(IBurpExtender, ITab):
def registerExtenderCallbacks(self, callbacks):
# Required for easier debugging:
# https://github.com/securityMB/burp-exceptions
sys.stdout = callbacks.getStdout()
# Keep a reference to our callbacks object
self.callbacks = callbacks
# Set our extension name
self.callbacks.setExtensionName("Encode/Decode/Hash")
# Create the tab
self.tab = swing.JPanel(BorderLayout())
# Create the text area at the top of the tab
textPanel = swing.JPanel()
# Create the label for the text area
boxVertical = swing.Box.createVerticalBox()
boxHorizontal = swing.Box.createHorizontalBox()
textLabel = swing.JLabel("Text to be encoded/decoded/hashed")
boxHorizontal.add(textLabel)
boxVertical.add(boxHorizontal)
# Create the text area itself
boxHorizontal = swing.Box.createHorizontalBox()
self.textArea = swing.JTextArea('', 6, 100)
self.textArea.setLineWrap(True)
scroll = swing.JScrollPane(self.textArea)
boxHorizontal.add(scroll)
boxVertical.add(boxHorizontal)
# Add the text label and area to the text panel
textPanel.add(boxVertical)
# Add the text panel to the top of the main tab
self.tab.add(textPanel, BorderLayout.NORTH)
# Created a tabbed pane to go in the center of the
# main tab, below the text area
tabbedPane = swing.JTabbedPane()
self.tab.add("Center", tabbedPane);
# First tab
firstTab = swing.JPanel()
firstTab.layout = BorderLayout()
tabbedPane.addTab("Encode", firstTab)
# Button for first tab
buttonPanel = swing.JPanel()
buttonPanel.add(swing.JButton('Encode', actionPerformed=self.handleButtonClick))
firstTab.add(buttonPanel, "North")
# Panel for the encoders. Each label and text field
# will go in horizontal boxes which will then go in
# a vertical box
encPanel = swing.JPanel()
boxVertical = swing.Box.createVerticalBox()
boxHorizontal = swing.Box.createHorizontalBox()
self.b64EncField = swing.JTextArea('', 3, 65)
self.b64EncField.setLineWrap(True)
scroll = swing.JScrollPane(self.b64EncField)
boxHorizontal.add(swing.JLabel(" Base64 :"))
boxHorizontal.add(scroll)
boxVertical.add(boxHorizontal)
boxHorizontal = swing.Box.createHorizontalBox()
self.urlEncField = swing.JTextArea('', 3, 65)
self.urlEncField.setLineWrap(True)
scroll = swing.JScrollPane(self.urlEncField)
boxHorizontal.add(swing.JLabel(" URL :"))
boxHorizontal.add(scroll)
boxVertical.add(boxHorizontal)
boxHorizontal = swing.Box.createHorizontalBox()
self.asciiHexEncField = swing.JTextArea('', 3, 65)
self.asciiHexEncField.setLineWrap(True)
scroll = swing.JScrollPane(self.asciiHexEncField)
boxHorizontal.add(swing.JLabel(" Ascii Hex :"))
boxHorizontal.add(scroll)
boxVertical.add(boxHorizontal)
boxHorizontal = swing.Box.createHorizontalBox()
self.htmlEncField = swing.JTextArea('', 3, 65)
self.htmlEncField.setLineWrap(True)
scroll = swing.JScrollPane(self.htmlEncField)
boxHorizontal.add(swing.JLabel(" HTML :"))
boxHorizontal.add(scroll)
boxVertical.add(boxHorizontal)
boxHorizontal = swing.Box.createHorizontalBox()
self.jsEncField = swing.JTextArea('', 3, 65)
self.jsEncField.setLineWrap(True)
scroll = swing.JScrollPane(self.jsEncField)
boxHorizontal.add(swing.JLabel(" JavaScript:"))
boxHorizontal.add(scroll)
boxVertical.add(boxHorizontal)
# Add the vertical box to the Encode tab
firstTab.add(boxVertical, "Center")
# Repeat the same process for the remaining tabs
secondTab = swing.JPanel()
secondTab.layout = BorderLayout()
tabbedPane.addTab("Decode", secondTab)
buttonPanel = swing.JPanel()
buttonPanel.add(swing.JButton('Decode', actionPerformed=self.handleButtonClick))
secondTab.add(buttonPanel, "North")
decPanel = swing.JPanel()
boxVertical = swing.Box.createVerticalBox()
boxHorizontal = swing.Box.createHorizontalBox()
self.b64DecField = swing.JTextArea('', 3, 65)
self.b64DecField.setLineWrap(True)
scroll = swing.JScrollPane(self.b64DecField)
boxHorizontal.add(swing.JLabel(" Base64 :"))
boxHorizontal.add(scroll)
boxVertical.add(boxHorizontal)
boxHorizontal = swing.Box.createHorizontalBox()
self.urlDecField = swing.JTextArea('', 3, 65)
self.urlDecField.setLineWrap(True)
scroll = swing.JScrollPane(self.urlDecField)
boxHorizontal.add(swing.JLabel(" URL :"))
boxHorizontal.add(scroll)
boxVertical.add(boxHorizontal)
boxHorizontal = swing.Box.createHorizontalBox()
self.asciiHexDecField = swing.JTextArea('', 3, 75)
self.asciiHexDecField.setLineWrap(True)
scroll = swing.JScrollPane(self.asciiHexDecField)
boxHorizontal.add(swing.JLabel(" Ascii Hex :"))
boxHorizontal.add(scroll)
boxVertical.add(boxHorizontal)
boxHorizontal = swing.Box.createHorizontalBox()
self.htmlDecField = swing.JTextArea('', 3, 75)
self.htmlDecField.setLineWrap(True)
scroll = swing.JScrollPane(self.htmlDecField)
boxHorizontal.add(swing.JLabel(" HTML :"))
boxHorizontal.add(scroll)
boxVertical.add(boxHorizontal)
boxHorizontal = swing.Box.createHorizontalBox()
self.jsDecField = swing.JTextArea('', 3, 65)
self.jsDecField.setLineWrap(True)
scroll = swing.JScrollPane(self.jsDecField)
boxHorizontal.add(swing.JLabel(" JavaScript:"))
boxHorizontal.add(scroll)
boxVertical.add(boxHorizontal)
secondTab.add(boxVertical, "Center")
thirdTab = swing.JPanel()
thirdTab.layout = BorderLayout()
tabbedPane.addTab("Hash", thirdTab)
buttonPanel = swing.JPanel()
buttonPanel.add(swing.JButton('Hash', actionPerformed=self.handleButtonClick))
thirdTab.add(buttonPanel, "North")
decPanel = swing.JPanel()
boxVertical = swing.Box.createVerticalBox()
boxHorizontal = swing.Box.createHorizontalBox()
self.md5Field = swing.JTextField('', 75)
boxHorizontal.add(swing.JLabel(" MD5 :"))
boxHorizontal.add(self.md5Field)
boxVertical.add(boxHorizontal)
boxHorizontal = swing.Box.createHorizontalBox()
self.sha1Field = swing.JTextField('', 75)
boxHorizontal.add(swing.JLabel(" SHA-1 :"))
boxHorizontal.add(self.sha1Field)
boxVertical.add(boxHorizontal)
boxHorizontal = swing.Box.createHorizontalBox()
self.sha256Field = swing.JTextField('', 75)
boxHorizontal.add(swing.JLabel(" SHA-256 :"))
boxHorizontal.add(self.sha256Field)
boxVertical.add(boxHorizontal)
boxHorizontal = swing.Box.createHorizontalBox()
self.sha512Field = swing.JTextField('', 75)
boxHorizontal.add(swing.JLabel(" SHA-512 :"))
boxHorizontal.add(self.sha512Field)
boxVertical.add(boxHorizontal)
boxHorizontal = swing.Box.createHorizontalBox()
self.ntlmField = swing.JTextField('', 75)
boxHorizontal.add(swing.JLabel(" NTLM :"))
boxHorizontal.add(self.ntlmField)
boxVertical.add(boxHorizontal)
thirdTab.add(boxVertical, "Center")
# Add the custom tab to Burp's UI
callbacks.addSuiteTab(self)
return
# Implement ITab
def getTabCaption(self):
"""Return the text to be displayed on the tab"""
return "Encode/Decode/Hash"
def getUiComponent(self):
"""Passes the UI to burp"""
return self.tab
# Implement the functions from the button clicks
def encode(self):
"""Encodes the user input and writes the encoded
value to text fields.
"""
self.b64EncField.text = base64.b64encode(self.textArea.text)
self.urlEncField.text = urllib.quote(self.textArea.text)
self.asciiHexEncField.text = binascii.hexlify(self.textArea.text)
self.htmlEncField.text = cgi.escape(self.textArea.text)
self.jsEncField.text = json.dumps(self.textArea.text)
def decode(self):
"""Decodes the user input and writes the decoded
value to text fields."""
try:
self.b64DecField.text = base64.b64decode(self.textArea.text)
except TypeError:
pass
self.urlDecField.text = urllib.unquote(self.textArea.text)
try:
self.asciiHexDecField.text = binascii.unhexlify(self.textArea.text)
except TypeError:
pass
parser = HTMLParser()
self.htmlDecField.text = parser.unescape(self.textArea.text)
self.jsDecField.text = re.sub(r'%u([a-fA-F0-9]{4}|[a-fA-F0-9]{2})', lambda m: chr(int(m.group(1), 16)), self.textArea.text)
def generateHashes(self):
"""Hashes the user input and writes the hashed
value to text fields.
"""
self.md5Field.text = hashlib.md5(self.textArea.text).hexdigest()
self.sha1Field.text = hashlib.sha1(self.textArea.text).hexdigest()
self.sha256Field.text = hashlib.sha256(self.textArea.text).hexdigest()
self.sha512Field.text = hashlib.sha512(self.textArea.text).hexdigest()
self.ntlmField.text = binascii.hexlify(hashlib.new('md4', self.textArea.text.encode('utf-16le')).digest())
def launchThread(self, targetFunction, arguments=None):
"""Launches a thread against a specified target function"""
if arguments:
t = threading.Thread(target=targetFunction, args=arguments)
else:
t = threading.Thread(target=targetFunction)
t.daemon = True
t.start()
def handleButtonClick(self, event):
"""Handles button clicks and passes appropriate function
to be launched in new thread."""
buttonText = event.source.text
if buttonText == "Encode":
self.launchThread(self.encode)
elif buttonText == "Decode":
self.launchThread(self.decode)
elif buttonText == 'Hash':
self.launchThread(self.generateHashes)
else:
print buttonText
try:
FixBurpExceptions()
except:
pass