This repository was archived by the owner on Nov 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathutils.py
190 lines (164 loc) · 5.89 KB
/
utils.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
from java.awt.event import ActionListener, MouseAdapter
from thread import start_new_thread
from java.awt.event import MouseAdapter
from burp import IContextMenuFactory
from burp import IContextMenuInvocation
from javax.swing import JMenuItem
from javax.swing import JButton
from java.awt import Desktop
from java.lang import Runtime
import platform
import os
from java import net
class ClickableLink():
"""
This method generates a clickable button inside the prompt
after the report is uploaded . It supposedly opens
your default browser on the test's page .
"""
def __init__(self,text,url):
self.text = text
self.url = url
def getClickAbleLink(self):
self.link = JButton(actionPerformed=self.openURL)
self.link.setText(self.text)
return self.link
def openURL(self,event):
try:
Desktop.getDesktop().browse(net.URI(self.url))
except:
Runtime.getRuntime().exec("xdg-open "+self.url)
def linkDialog(message, link, JOptionPane, src):
lbl = ClickableLink(message, link)
JOptionPane.showMessageDialog(src, lbl.getClickAbleLink())
def html2text(strText):
"""
This method transforms burp's HTML tags into normal
text .
TODO tranform into markdown .
"""
html = str(strText).encode('utf8', 'replace')
int2 = html.lower().find("<body")
if int2 > 0:
html = html[int2:]
int2 = html.lower().find("</body>")
if int2 > 0:
html = html[:int2]
list1 = ['<br>', '<tr', '<td', '</p>', 'span>', 'li>', '</h', 'div>']
list2 = [
chr(13),
chr(13),
chr(9),
chr(13),
chr(13),
chr(13),
chr(13),
chr(13)
]
f1 = True
f2 = True
toText = ""
for int1 in range(len(html)):
str2 = html[int1]
for int2 in range(len(list1)):
if html[int1:int1 + len(list1[int2])].lower() == list1[int2]:
toText = toText + list2[int2]
if str2 == '<':
f2 = False
if f1 and f2 and (ord(str2) != 10):
toText = toText + str2
if str2 == '>':
f2 = True
if f1 and f2:
toText = toText.replace(chr(32) + chr(13), chr(13))
toText = toText.replace(chr(9) + chr(13), chr(13))
toText = toText.replace(chr(13) + chr(32), chr(13))
toText = toText.replace(chr(13) + chr(9), chr(13))
toText = toText.replace(chr(13) + chr(13), chr(13))
return toText
class SendToDojo(IContextMenuFactory):
"""
SendToDojo implements the class needed to create the context
menu when rightclicking an issue .
"""
def __init__(self, data):
self.a = data
def createMenuItems(self, invoker):
self._invoker = invoker
context = self._invoker.getInvocationContext()
if not context == self._invoker.CONTEXT_SCANNER_RESULTS:
return None
self.selection = JMenuItem("Send To DefectDojo (Existing Test)",
actionPerformed=self.a.sendIssue)
return [self.selection]
class SendReportToDojo(IContextMenuFactory):
"""
SendReportToDojo implements the class needed to create
the context menu when rightclicking an issue(s) in order
to send them as a report to Defect Dojo .
"""
def __init__(self, data):
self.a = data
def createMenuItems(self, invoker):
self._invoker = invoker
context = self._invoker.getInvocationContext()
if not (context == self._invoker.CONTEXT_SCANNER_RESULTS
or context == self._invoker.CONTEXT_TARGET_SITE_MAP_TREE):
return None
if context == self._invoker.CONTEXT_SCANNER_RESULTS:
self.selection = JMenuItem("Send Report To DefectDojo (New Burp Test)",
actionPerformed=self.a.sendAsReport)
return [self.selection]
else:
self.selection = JMenuItem("Send All Issues to DefectDojo (New Burp Test)",
actionPerformed=self.a.sendAsReport)
return [self.selection]
class ProdListener(ActionListener):
"""
Updates the productID field based on the selection from the ComboBox
"""
def __init__(self, data):
self.a = data
def actionPerformed(self, e):
cmd = e.getActionCommand()
if cmd == 'comboBoxChanged':
selected = self.a.ddui.productName.selectedIndex
if selected >= 0:
self.a.ddui.productID.setText(
str(self.a.ddui.products.data['results'][selected]['id']))
start_new_thread(self.a.getEngagements, (e, ))
class ProdMouseListener(MouseAdapter):
"""
Fetches products for the product ComboBox
"""
def __init__(self, data):
self.a = data
def mousePressed(self, event):
self.a.getProducts(event)
class EngListener(ActionListener):
"""
Updates the engagementID field based on the selection from the ComboBox
"""
def __init__(self, data):
self.a = data
def actionPerformed(self, e):
cmd = e.getActionCommand()
if cmd == 'comboBoxChanged':
selected = self.a.ddui.engagementName.selectedIndex
if selected >= 0:
self.a.ddui.engagementID.setText(
str(self.a.ddui.engagements.data['results'][selected]['id']))
start_new_thread(self.a.getTests, (e, ))
class TestListener(ActionListener):
"""
Updates the testID field based on the selection from the ComboBox
"""
def __init__(self, data):
self.a = data
def actionPerformed(self, e):
cmd = e.getActionCommand()
if cmd == 'comboBoxChanged':
selected = self.a.ddui.testName.selectedIndex
if selected >= 0:
self.a.ddui.testID.setText(
str(self.a.ddui.tests.data['results'][selected]['id']))