-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathJSONandHTTPP.py
100 lines (81 loc) · 3.75 KB
/
JSONandHTTPP.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
# -*- coding:utf-8 -*-
# Author: Vulkey_Chen
# Blog: gh0st.cn
# Team: MSTSEC
import json,re
from burp import IBurpExtender, ITab
from javax.swing import JPanel,JButton,JTextArea,JScrollPane
from java.awt import BorderLayout
class BurpExtender(IBurpExtender, ITab):
def registerExtenderCallbacks(self, callbacks):
print 'JSON&HTTPP by [Vulkey_Chen]\nBlog: gh0st.cn\nTeam: MSTSEC'
self._cb = callbacks
self._hp = callbacks.getHelpers()
self._cb.setExtensionName('JSON&HTTPP')
self.mainPanel = JPanel()
self.mainPanel.setLayout(BorderLayout())
self.jsonTextArea = JTextArea(20,0)
self.jsonTextArea.setLineWrap(True)
self.dictTextArea = JTextArea()
self.dictTextArea.setLineWrap(True)
self.jsonTextWrapper = JPanel()
self.jsonTextWrapper.setLayout(BorderLayout())
self.dictTextWrapper = JPanel()
self.dictTextWrapper.setLayout(BorderLayout())
self.jsonScrollPane = JScrollPane(self.jsonTextArea)
self.dictScrollPane = JScrollPane(self.dictTextArea)
self.jsonTextWrapper.add(self.jsonScrollPane, BorderLayout.CENTER)
self.dictTextWrapper.add(self.dictScrollPane, BorderLayout.CENTER)
self.mainPanel.add(self.jsonTextWrapper, BorderLayout.NORTH)
self.mainPanel.add(self.dictTextWrapper, BorderLayout.CENTER)
self.beautifyButton_1 = JButton("JSON2HTTPP", actionPerformed=self.onClick1)
self.beautifyButton_2 = JButton("HTTPP2JSON", actionPerformed=self.onClick2)
self.buttons = JPanel();
self.buttons.add(self.beautifyButton_1, BorderLayout.CENTER)
self.buttons.add(self.beautifyButton_2, BorderLayout.CENTER)
self.mainPanel.add(self.buttons, BorderLayout.SOUTH)
self._cb.customizeUiComponent(self.mainPanel)
self._cb.addSuiteTab(self)
def onClick1(self, event):
_jsontext = self.jsonTextArea.getText()
try:
_jsontext = json.loads(re.search(r'\({.*?}\)',_jsontext).group().replace('(','').replace(')',''))
except:
_jsontext = json.loads(_jsontext)
self._result = []
self.dictTextArea.setText('&'.join(self.json2dict(_jsontext)))
# self.dictTextArea.setText('\n'.join(self.json2dict(_jsontext)))
def onClick2(self, event):
_jsontext = self.jsonTextArea.getText()
_res = []
for i in _jsontext.split('&'):
for x in i.split('='):
_res.append(x)
self.dictTextArea.setText(json.dumps(dict(zip(_res[0::2],_res[1::2]))))
def json2dict(self,_jsontext):
keyValue = ""
if isinstance(_jsontext, dict):
for key in _jsontext.keys():
keyValue = _jsontext.get(key)
if isinstance(keyValue, dict):
self.json2dict(keyValue)
elif isinstance(keyValue, list):
for json_array in keyValue:
self.json2dict(json_array)
else:
if type(keyValue) is int or type(keyValue) == long or type(keyValue) == str:
self._result.append(str(key) + "=" + str(keyValue))
elif type(keyValue) is bool:
self._result.append(str(key) + "=" + str(int(keyValue)))
elif type(keyValue) == type(None):
self._result.append(str(key) + "=" + "")
else:
self._result.append(str(key) + "=" + keyValue)
elif isinstance(_jsontext, list):
for _jsontext_array in _jsontext:
self.json2dict(_jsontext_array)
return self._result
def getTabCaption(self):
return 'JSON&HTTPP'
def getUiComponent(self):
return self.mainPanel