-
Notifications
You must be signed in to change notification settings - Fork 1
/
BurpExtender_UncryptDES.py
323 lines (281 loc) · 14.9 KB
/
BurpExtender_UncryptDES.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
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# -*- coding: utf-8 -*-
# Author: Ramoncjs
# Time: 2020/4/16
import java.lang as lang
import base64
from javax import swing
from java.awt import Color
from java.awt import Font
from burp import IBurpExtender
from burp import IHttpListener
from burp import IMessageEditorTabFactory
from burp import IMessageEditorTab
from burp import IParameter
from burp import ITab
from pyDes import des, PAD_PKCS5, ECB
param = 'Null'
secret_key = 'Null'
iv = 'Null'
class BurpExtender(IBurpExtender, IMessageEditorTabFactory, IHttpListener, ITab):
def registerExtenderCallbacks(self, callbacks):
self._callbacks = callbacks
self._helpers = callbacks.getHelpers()
callbacks.setExtensionName("Des Decrypt")
# 初始化UI
self.TabUI()
self._callbacks.addSuiteTab(self)
callbacks.registerMessageEditorTabFactory(self)
# 实现IMessageEditorTabFactory方法
# Burp 将会对每一个 HTTP 消息编辑器调用一次此方法,此工厂必须返回一个新的 IMessageEditorTab 对象
def createNewInstance(self, controller, editable):
# create a new instance of our custom editor tab
return DataInputTab(self, controller, editable)
# 实现Itab接口
def getTabCaption(self):
return 'Des Decrypt'
def getUiComponent(self):
return self.tab
# 实现新窗口功能与UI
def TabUI(self):
self.tab = swing.JPanel()
layout = swing.GroupLayout(self.tab)
self.tab.setLayout(layout)
self.titleLabel = swing.JLabel("DES Plugin")
self.titleLabel.setFont(Font("Tahoma", 1, 16))
self.titleLabel.setForeground(Color(135, 206, 250))
self.infoLabel = swing.JLabel("Please enter the parameters to be decrypted and DES's Key and IV.")
self.infoLabel.setFont(Font("Tahoma", 0, 12))
self.keyLabel = swing.JLabel("Des Plugin Params")
self.keyLabel.setFont(Font("Tahoma", 1, 12))
self.setKeyTextArea = swing.JTextArea("")
self.setIVTextArea = swing.JTextArea("")
self.setParamTextArea = swing.JTextArea("")
self.setkeyButton = swing.JButton(" setKey ", actionPerformed=self.setKey)
self.setIVButton = swing.JButton(" setIV ", actionPerformed=self.setIV)
self.setParamButton = swing.JButton("setParam", actionPerformed=self.setParam)
self.logLabel = swing.JLabel("Log")
self.logLabel.setFont(Font("Tahoma", 1, 12))
self.logPane = swing.JScrollPane()
self.logArea = swing.JTextArea("Logs.\n")
self.logArea.setLineWrap(True)
self.logPane.setViewportView(self.logArea)
self.logClearButton = swing.JButton(" Clear ", actionPerformed=self.logClear)
self.getParamsButton = swing.JButton("getParams", actionPerformed=self.getParams)
self.bar = swing.JSeparator(swing.SwingConstants.HORIZONTAL)
self.bar2 = swing.JSeparator(swing.SwingConstants.HORIZONTAL)
# 设置水平布局
# .addPreferredGap(swing.LayoutStyle.ComponentPlacement.UNRELATED)
layout.setHorizontalGroup(
layout.createParallelGroup()
.addGroup(layout.createSequentialGroup()
.addGap(15)
.addGroup(layout.createParallelGroup()
.addComponent(self.titleLabel)
.addComponent(self.infoLabel)
.addComponent(self.bar)
.addComponent(self.keyLabel)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup()
.addComponent(self.setkeyButton)
.addComponent(self.setIVButton)
.addComponent(self.setParamButton))
.addGroup(layout.createParallelGroup()
.addComponent(self.setKeyTextArea,
swing.GroupLayout.PREFERRED_SIZE, 300,
swing.GroupLayout.PREFERRED_SIZE)
.addComponent(self.setIVTextArea,
swing.GroupLayout.PREFERRED_SIZE, 300,
swing.GroupLayout.PREFERRED_SIZE)
.addComponent(self.setParamTextArea,
swing.GroupLayout.PREFERRED_SIZE, 300,
swing.GroupLayout.PREFERRED_SIZE))
)
.addComponent(self.bar2)
.addComponent(self.logLabel)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup()
.addComponent(self.logClearButton)
.addComponent(self.getParamsButton)
)
.addGroup(layout.createParallelGroup()
.addComponent(self.logPane, swing.GroupLayout.PREFERRED_SIZE,
300, swing.GroupLayout.PREFERRED_SIZE)))
))
)
# 设置垂直布局
layout.setVerticalGroup(
layout.createParallelGroup()
.addGroup(layout.createSequentialGroup()
.addGap(15)
.addComponent(self.titleLabel)
.addGap(10)
.addComponent(self.infoLabel)
.addGap(30)
.addComponent(self.bar)
.addGap(10)
.addComponent(self.keyLabel)
.addGap(20)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup()
.addGroup(layout.createParallelGroup()
.addGroup(layout.createSequentialGroup()
.addComponent(self.setkeyButton)
.addGap(20)
.addComponent(self.setIVButton)
.addGap(20)
.addComponent(self.setParamButton))
)
.addGroup(layout.createParallelGroup()
.addGroup(layout.createSequentialGroup()
.addComponent(self.setKeyTextArea,
swing.GroupLayout.PREFERRED_SIZE, 30,
swing.GroupLayout.PREFERRED_SIZE)
.addGap(20)
.addComponent(self.setIVTextArea,
swing.GroupLayout.PREFERRED_SIZE, 30,
swing.GroupLayout.PREFERRED_SIZE)
.addGap(20)
.addComponent(self.setParamTextArea,
swing.GroupLayout.PREFERRED_SIZE, 30,
swing.GroupLayout.PREFERRED_SIZE))
)
)
)
.addGap(40)
.addComponent(self.bar2)
.addGap(10)
.addComponent(self.logLabel)
.addGap(10)
.addGroup(layout.createParallelGroup()
.addGroup(layout.createSequentialGroup()
.addComponent(self.getParamsButton)
.addGap(20)
.addComponent(self.logClearButton)
)
.addComponent(self.logPane, swing.GroupLayout.PREFERRED_SIZE, 500,
swing.GroupLayout.PREFERRED_SIZE))
)
)
def setKey(self, key):
global secret_key
pubText = self.setKeyTextArea.getText().strip('\n')
if pubText != None and len(pubText) > 0:
status = False
try:
secret_key = str((pubText).encode("utf-8"))
status = True
except:
pass
self.logPrint(status,'secret_key:' + secret_key)
def setIV(self, setiv):
global iv
pubText = self.setIVTextArea.getText().strip('\n')
if pubText != None and len(pubText) > 0:
status = False
try:
iv = str((pubText).encode("utf-8"))
status = True
except:
pass
self.logPrint(status,'iv:' + iv)
def setParam(self, setparam):
global param
pubText = self.setParamTextArea.getText().strip('\n')
if pubText != None and len(pubText) > 0:
status = False
try:
param = str((pubText).encode("utf-8"))
status = True
except:
pass
self.logPrint(status,'param:' + param)
def logClear(self, log):
self.logArea.setText("")
def getParams(self,params):
status = True
try:
self.logPrint(status,'secret_key:' + secret_key)
self.logPrint(status,'iv:' + iv)
self.logPrint(status,'param:' + param)
except:
pass
def logPrint(self, status, data):
statusList = ["[!] Failure: ", "[+] Success: "]
message = statusList[status] + data
self.logArea.append(message+'\n')
# 实现 IMessageEditorTab
class DataInputTab(IMessageEditorTab):
def __init__(self, extender, controller, editable):
self._extender = extender
self._editable = editable
self._helpers = extender._helpers
# create an instance of Burp's text editor, to display our deserialized data
self._txtInput = extender._callbacks.createTextEditor()
self._txtInput.setEditable(editable)
# 此方法用于获取自定义标签的标题文本
def getTabCaption(self):
return "unCrypto"
# 调用此方法获取自定义标签页显示的组件
def getUiComponent(self):
return self._txtInput.getComponent()
# 在显示一个新的 HTTP 消息时,启用自定义的标签页
def isEnabled(self, content, isRequest):
r = self._helpers.analyzeResponse(content)
msg = content[r.getBodyOffset():].tostring()
# enable this tab for requests containing a data parameter
if isRequest:
return (isRequest and not self._extender._helpers.getRequestParameter(content, "%s" % (param)) is None)
elif not isRequest:
return (not isRequest and not msg is None)
# 此方法用于将一个 HTTP 消息显示在编辑器中
def setMessage(self, content, isRequest):
r = self._helpers.analyzeResponse(content)
msg = content[r.getBodyOffset():].tostring()
if content is None:
# clear our display
self._txtInput.setText(None)
self._txtInput.setEditable(False)
else:
if isRequest:
parameter = self._extender._helpers.getRequestParameter(content, "%s" % (param))
a = self._extender._helpers.urlDecode(parameter.getValue())
b = des_crypto().des_de(a)
self._txtInput.setText(b)
self._txtInput.setEditable(self._editable)
elif not isRequest:
c = des_crypto().des_de(msg)
self._txtInput.setText(c)
self._txtInput.setEditable(self._editable)
self._currentMessage = content
# 此方法用于获取当前已显示的消息,此消息可能已被用户修改
def getMessage(self):
# 用户是否修改编辑器内容
if self._txtInput.isTextModified():
# reserialize the data
text = self._txtInput.getText()
# 输入字符串默认转换成burp数组格式,加密需进行格式转换,注意:byte转换成string后无需再次转换回去
a = self._extender._helpers.bytesToString(text)
b = des_crypto().des_en(str(a.encode("utf-8")))
input = self._extender._helpers.urlEncode(b)
# update the request with the new parameter value
return self._extender._helpers.updateParameter(self._currentMessage,
self._extender._helpers.buildParameter("%s" % (param), input,
IParameter.PARAM_BODY))
else:
return self._currentMessage
# 此方法用于指示用户是否对编辑器的内容做了修改
def isModified(self):
return self._txtInput.isTextModified()
# 直接返回 iTextEditor 中选中的文本
def getSelectedData(self):
return self._txtInput.getSelectedText()
# DES加解密脚本
class des_crypto():
def des_en(self, msg):
key = des(secret_key, ECB, iv, pad=None, padmode=PAD_PKCS5)
entrymsg = key.encrypt(msg, padmode=PAD_PKCS5)
return base64.b64encode(entrymsg).decode('utf-8')
def des_de(self, msg):
key = des(secret_key, ECB, iv, pad=None, padmode=PAD_PKCS5)
desmsg = key.decrypt((base64.b64decode(msg)), padmode=PAD_PKCS5)
return desmsg.decode('utf-8')