-
Notifications
You must be signed in to change notification settings - Fork 11
/
Add & Track Custom Issues.py
2713 lines (1982 loc) · 137 KB
/
Add & Track Custom Issues.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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from burp import IBurpExtender # for the extension
from burp import IContextMenuFactory # for adding an option to the right click popup menu
from burp import IHttpRequestResponse # for custom IHttpRequestResponse
from burp import IHttpService # for custom IHttpService
from burp import IScanIssue # for adding a new issue
from burp import ITab # for creating an extension tab
from java.awt import BorderLayout # for panel layouts
from java.awt import Color # for setting a darker background on disabled text areas
from java.awt import Font # for adding bold font to red text labels in main tab
from java.awt import GridBagConstraints # for panel layouts alignment
from java.awt import GridBagLayout # for panel layouts
from java.awt import GridLayout # for button layout in main tab
from java.awt import Insets # for panel layouts spacing
from java.awt.event import ActionListener # for custom action listener for protocol combo box
from java.awt.event import InputEvent # for undo and redo in text areas
from java.awt.event import KeyEvent # for allowing tab key to change focus instead of inserting tab into text areas
from java.awt.event import MouseListener # for detecting mouse clicks on tables so row doesn't flash when dragging a clicked mouse
from java.lang import Integer # for filter on port text area
from java.lang import StringBuilder # for filter on port text area
from java.net import URL # for creating URLs
from javax.swing import AbstractAction # for undo and redo in text areas
from javax.swing import Action # for undo and redo in text areas
from javax.swing import BorderFactory # for panel borders
from javax.swing import JButton # for buttons
from javax.swing import JComboBox # for severity, confidence, and protocol combo boxes
from javax.swing import JDialog # for main popup dialog box
from javax.swing import JFileChooser # for importing and exporting dialog boxes
from javax.swing import JFrame # for importing and exporting dialog boxes
from javax.swing import JLabel # for labels
from javax.swing import JMenuItem # for adding menu choices to add a new issue
from javax.swing import JOptionPane # for import and export message boxes
from javax.swing import JPanel # for panels
from javax.swing import JScrollPane # for scroll panes to help with extended text areas
from javax.swing import JSplitPane # for split panes in issue selection popup dialog tab and main tab
from javax.swing import JTabbedPane # for tabbed pane in popup dialog
from javax.swing import JTable # for tables in issue selection popup dialog tab and main tab
from javax.swing import JTextArea # for text areas in popup dialog and main panel
from javax.swing import JTextPane # for centering text in disabled issue name and severity text panes
from javax.swing import KeyStroke # for undo and redo in text areas
from javax.swing import ListSelectionModel # for only allowing single row selection
from javax.swing import SortOrder # for setting table sort order ascending descending unsorted
from javax.swing import SwingConstants # for Swing constants
from javax.swing.border import TitledBorder # for panel borders
from javax.swing.event import DocumentListener # for detecting changes to text areas to update the issue location
from javax.swing.event import UndoableEditListener # for undo and redo in text areas
from javax.swing.filechooser import FileNameExtensionFilter # for importing and exporting
from javax.swing.table import DefaultTableModel # for creating shared a custom table model
from javax.swing.table import TableRowSorter # for setting table sort order ascending descending unsorted
from javax.swing.text import DocumentFilter # for applying filters on the issue name, host, and port text areas
from javax.swing.text import SimpleAttributeSet # for centering text in disabled issue name and severity text panes
from javax.swing.text import StyleConstants # for centering text in disabled issue name and severity text panes
from javax.swing.undo import UndoManager # for undo and redo in text areas
import csv # for importing and exporting to and from csv
import json # for importing and exporting to and from json
import os # for splitting the file name and file extension when importing and exporting
#
# Burp extender main class
#
class BurpExtender(IBurpExtender, ITab, IContextMenuFactory):
#
# implement IBurpExtender when the extension is loaded
#
def registerExtenderCallbacks(self, callbacks):
# keep reference to callbacks object
self._callbacks = callbacks
# obtain extension helpers object
self._helpers = callbacks.getHelpers()
# set the extension name
self._EXTENSION_NAME = "Add & Track Custom Issues"
# set the extension version
self._EXTENSION_VERSION = "1.0"
# set names for the tabs
self._MAIN_TAB_NAME = "Main"
self._DIALOG_TAB_1_NAME = "New Issue"
self._DIALOG_TAB_2_NAME = "Issue Selection"
# create the button names for the main tab
self._MAIN_TAB_BUTTON_NAMES = ["Add Issue", "Export Issues To CSV", "Import Issues From CSV", "Delete Issue", "Export Issues To JSON", "Import Issues From JSON"]
# create a consistent background color for disabled text areas and text panes
self._DISABLED_BACKGROUND_COLOR = Color(224, 225, 226)
# set warning message text for when the table has been updated and not exported yet
self._WARNING_MESSAGE_TABLE_UPDATED = "*** WARNING: The table has been updated since the last export. ***"
# set html text for text panes
self._HTML_FOR_TEXT_PANES = ["<html><body style='background-color:#e2e3e4; text-align:center; padding-top:3px; padding-bottom:3px;'>", "</body></html>"]
# create choices for the combo boxes
self._SEVERITY_COMBOBOX_CHOICES = ["High", "Medium", "Low", "Information"]
self._CONFIDENCE_COMBOBOX_CHOICES = ["Certain", "Firm", "Tentative"]
self._PROTOCOL_COMBOBOX_CHOICES = ["HTTPS", "HTTP"]
# create spacing for before and after each combo box choice to make combo boxes larger and center text with labels since the dropdown icon takes up space
spacesForComboBox = [" ", " "]
# add spacing before and after each combo box choice
self._SEVERITY_COMBOBOX_CHOICES = [spacesForComboBox[0] + severity + spacesForComboBox[1] for severity in self._SEVERITY_COMBOBOX_CHOICES]
self._CONFIDENCE_COMBOBOX_CHOICES = [spacesForComboBox[0] + confidence + spacesForComboBox[1] for confidence in self._CONFIDENCE_COMBOBOX_CHOICES]
self._PROTOCOL_COMBOBOX_CHOICES = [spacesForComboBox[0] + protocol + spacesForComboBox[1] for protocol in self._PROTOCOL_COMBOBOX_CHOICES]
# create a dictionaries for code reuse
self._dictionaryOfTextAreas = dict()
self._dictionaryOfTextPanes = dict()
self._dictionaryOfScrollPanes = dict()
self._dictionaryOfScrollPaneBorders = dict()
self._dictionaryOfComboBoxes = dict()
self._dictionaryOfPanels = dict()
self._dictionaryOfSplitPanes = dict()
self._dictionaryOfTables = dict()
self._dictionaryOfTableRowSorters = dict()
self._dictionaryOfButtons = dict()
self._dictionaryOfLabels = dict()
self._dictionaryOfLastSelectedRowsAndColumns = dict()
# create main extension tab and issue selection tab for popup dialog
self.createMainTabOrIssueSelectionTab(self._MAIN_TAB_NAME)
self.createMainTabOrIssueSelectionTab(self._DIALOG_TAB_2_NAME)
# create popup dialog to add a new issue
self.createAddIssueDialog(self._DIALOG_TAB_1_NAME)
# set the extension name
callbacks.setExtensionName(self._EXTENSION_NAME)
# register the context menu factory
callbacks.registerContextMenuFactory(self)
# customize UI components (recursive on child components) sets highlighted text in tables black instead of white. Will not center text in combo boxes
callbacks.customizeUiComponent(self._dictionaryOfTables[self._MAIN_TAB_NAME])
callbacks.customizeUiComponent(self._dictionaryOfTables[self._DIALOG_TAB_2_NAME])
# add custom tab to Burp's UI
callbacks.addSuiteTab(self)
# print text to output window
print(self._EXTENSION_NAME + " v" + self._EXTENSION_VERSION)
print("Created by James Morris")
print("https://github.com/jamesm0rr1s")
# end of BurpExtender
return
#
# implement ITab - set tab caption
#
def getTabCaption(self):
return self._EXTENSION_NAME
#
# implement ITab - set main component
#
def getUiComponent(self):
return self._dictionaryOfSplitPanes[self._MAIN_TAB_NAME]
#
# create a menu item when right clicking on the site map, contents, proxy history, message viewers, ect.
#
def createMenuItems(self, invocation):
# create a menu array
menu = []
# lambda has two parameters: x is menuActionOpenAddIssueDialog, and inv which is set to invocation
menu.append(JMenuItem(self._EXTENSION_NAME[:-1], None, actionPerformed=lambda x, inv=invocation: self.menuActionOpenAddIssueDialog(inv)))
# return menu if it exists
return menu if menu else None
#
# create undo and redo on changes to the text areas
#
def createUndoRedo(self, longName):
# try to check if the undo manager has been created
try:
# check if the undo manager has been created
self._undoManager
# undo manager has not been created
except:
# create an undo manager
self._undoManager = UndoManager()
# set undo keystroke to Ctrl+z
undoKeystroke = KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_MASK)
# set redo keystroke to Ctrl+Shift+z or Ctrl+y
redoKeystroke1 = KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_MASK + InputEvent.SHIFT_MASK)
redoKeystroke2 = KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_MASK)
# create custom undoable edit listener
undoRedoListener = CustomUndoableEditListener(self)
# create undo action
self._undoAction = CustomAbstractAction(self, "Undo")
# create redo action
self._redoAction = CustomAbstractAction(self, "Redo")
# add undo redo listener to text area
self._dictionaryOfTextAreas[longName].getDocument().addUndoableEditListener(undoRedoListener)
# add undo action
self._dictionaryOfTextAreas[longName].getInputMap().put(undoKeystroke, "undoKeystroke")
self._dictionaryOfTextAreas[longName].getActionMap().put("undoKeystroke", self._undoAction)
# add redo action
self._dictionaryOfTextAreas[longName].getInputMap().put(redoKeystroke1, "redoKeystroke")
self._dictionaryOfTextAreas[longName].getInputMap().put(redoKeystroke2, "redoKeystroke")
self._dictionaryOfTextAreas[longName].getActionMap().put("redoKeystroke", self._redoAction)
# return
return
#
# create text areas, text panes, scroll panes, and panels
#
def createTextAndScrollPaneAndPanel(self, textType, editable, tabName, rowHeight, shortName):
# create unique name for dictionary items
longName = tabName + " " + shortName
# check if the type is a text area
if textType == "TextArea":
# create text areas
self._dictionaryOfTextAreas[longName] = CustomJTextArea("")
# possible feature for the future, but it crowds everything and does not look as clean
# create text editor for requests and responses that includes a search bar
# if shortName == "Request" or shortName == "Response":
# self._dictionaryOfTextAreas[longName] = self._callbacks.createTextEditor().getComponent()
# set row count to keep text areas from resizing when more or less text is displayed
self._dictionaryOfTextAreas[longName].setRows(rowHeight)
# set line wrap for text areas
self._dictionaryOfTextAreas[longName].setLineWrap(True)
# split new lines at words instead of characters
self._dictionaryOfTextAreas[longName].setWrapStyleWord(True)
# create scroll pane
self._dictionaryOfScrollPanes[longName] = JScrollPane(self._dictionaryOfTextAreas[longName])
# check if port
if shortName == "Port":
# set default port to 443 to match default protocol of https
self._dictionaryOfTextAreas[longName].setText("443")
# check if issue name, port, host, or path
if shortName == "Issue Name" or shortName == "Port" or shortName == "Host" or shortName == "Path":
# disable newlines
self._dictionaryOfTextAreas[longName].getDocument().putProperty("filterNewlines", True)
# set custom filter to only allow valid ports
self._dictionaryOfTextAreas[longName].getDocument().setDocumentFilter(CustomDocumentFilter(shortName))
# check if text area is for port, host, or path
if shortName == "Port" or shortName == "Host" or shortName == "Path":
# add listener to text areas to build issue location as text is entered
self._dictionaryOfTextAreas[longName].getDocument().addDocumentListener(CustomDocumentListener(self))
# check if issue name, port, or host
if shortName == "Issue Name" or shortName == "Port" or shortName == "Host":
# store the default border in case border is turned red for missing information
self._dictionaryOfScrollPaneBorders[longName] = self._dictionaryOfScrollPanes[longName].getBorder()
# check if text area is not editable
if editable == "editableN":
# set to read only
self._dictionaryOfTextAreas[longName].setEditable(False)
# set disabled background color
self._dictionaryOfTextAreas[longName].setBackground(self._DISABLED_BACKGROUND_COLOR)
# text area is editable
else:
# allow undo and redo for changes to the text
self.createUndoRedo(longName)
# check if the type is a text pane
elif textType == "TextPane":
# create text pane
self._dictionaryOfTextPanes[longName] = JTextPane()
# set content type to html
self._dictionaryOfTextPanes[longName].setContentType("text/html")
# set text in text pane
self._dictionaryOfTextPanes[longName].setText(self._HTML_FOR_TEXT_PANES[0] + " " + self._HTML_FOR_TEXT_PANES[1])
# remove default white border
self._dictionaryOfTextPanes[longName].setBorder(BorderFactory.createEmptyBorder())
# create scroll pane
self._dictionaryOfScrollPanes[longName] = JScrollPane(self._dictionaryOfTextPanes[longName])
# check if text pane is not editable
if editable == "editableN":
# set to read only
self._dictionaryOfTextPanes[longName].setEditable(False)
# set disabled background color
self._dictionaryOfTextPanes[longName].setBackground(self._DISABLED_BACKGROUND_COLOR)
# create panels
self._dictionaryOfPanels[longName] = JPanel()
# set border for panels
self._dictionaryOfPanels[longName].setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK, 1, False), shortName, TitledBorder.CENTER, TitledBorder.TOP))
# set layout for panels
self._dictionaryOfPanels[longName].setLayout(BorderLayout())
# add scroll panes to panels
self._dictionaryOfPanels[longName].add(self._dictionaryOfScrollPanes[longName])
# return
return
#
# create combo boxes and panels
#
def createComboBoxAndPanel(self, tabName, shortName):
# create unique name for dictionary items
longName = tabName + " " + shortName
# create combo box
self._dictionaryOfComboBoxes[longName] = JComboBox()
# check if combo box is for severity
if shortName == "Severity":
# loop through the choices
for choice in self._SEVERITY_COMBOBOX_CHOICES:
# add the choice
self._dictionaryOfComboBoxes[longName].addItem(choice)
# check if combo box is for confidence
elif shortName == "Confidence":
# loop through the choices
for choice in self._CONFIDENCE_COMBOBOX_CHOICES:
# add the choice
self._dictionaryOfComboBoxes[longName].addItem(choice)
# check if combo box is for protocol
elif shortName == "Protocol":
# loop through the choices
for choice in self._PROTOCOL_COMBOBOX_CHOICES:
# add the choice
self._dictionaryOfComboBoxes[longName].addItem(choice)
# add listener to combo box to build issue location as text is entered
self._dictionaryOfComboBoxes[longName].addActionListener(CustomActionListener(self))
# center combo box choices
self._dictionaryOfComboBoxes[longName].getRenderer().setHorizontalAlignment(SwingConstants.CENTER)
self._dictionaryOfComboBoxes[longName].getRenderer().setVerticalAlignment(SwingConstants.CENTER)
# create panels
self._dictionaryOfPanels[longName] = JPanel()
# set border for panels
self._dictionaryOfPanels[longName].setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK, 1, False), shortName, TitledBorder.CENTER, TitledBorder.TOP))
# set layout for panels
self._dictionaryOfPanels[longName].setLayout(BorderLayout())
# add combo box to panels
self._dictionaryOfPanels[longName].add(self._dictionaryOfComboBoxes[longName])
# return
return
#
# create buttons and button panels for the main tab
#
def createMainTabButtonAndButtonPanel(self, tabName, buttonName, halfWayPoint):
# create button
self._dictionaryOfButtons[buttonName] = JButton(buttonName, actionPerformed=lambda x, buttonClicked=buttonName: self.buttonActionButtonClickedFromMainTab(buttonClicked))
# create button panel
self._dictionaryOfPanels[buttonName] = JPanel()
# center button
self._dictionaryOfPanels[buttonName].setLayout(GridBagLayout())
# add button to button panel
self._dictionaryOfPanels[buttonName].add(self._dictionaryOfButtons[buttonName])
# add button panel to top main tab panel
self._dictionaryOfPanels[tabName + " Buttons"].add(self._dictionaryOfPanels[buttonName])
# check if half the button panels have been created
if halfWayPoint:
pass
# return
return
#
# create labels warning that the table has changed since the last export
#
def createWarningLabel(self, tabName, labelNumber):
# create label setting text to blank since hiding label does not consume the space
self._dictionaryOfLabels[tabName + labelNumber] = JLabel(" ")
# center label
self._dictionaryOfLabels[tabName + labelNumber].setHorizontalAlignment(JLabel.CENTER)
self._dictionaryOfLabels[tabName + labelNumber].setVerticalAlignment(JLabel.CENTER)
# set font color to red
self._dictionaryOfLabels[tabName + labelNumber].setForeground(Color.RED)
# set font to bold
labelFont = self._dictionaryOfLabels[tabName + labelNumber].getFont()
self._dictionaryOfLabels[tabName + labelNumber].setFont(labelFont.deriveFont(labelFont.getStyle() | Font.BOLD))
# return
return
#
# create a shared table model for multiple tables to use
#
def createSharedTableModel(self):
# create variable to allow or disallow the table row to be unselected
self._allowTableRowToBeUnselected = True
# set the last selected row and column for both tables
self._dictionaryOfLastSelectedRowsAndColumns[self._MAIN_TAB_NAME + " Row"] = -1
self._dictionaryOfLastSelectedRowsAndColumns[self._MAIN_TAB_NAME + " Column"] = -1
self._dictionaryOfLastSelectedRowsAndColumns[self._DIALOG_TAB_2_NAME + " Row"] = -1
self._dictionaryOfLastSelectedRowsAndColumns[self._DIALOG_TAB_2_NAME + " Column"] = -1
# create headers for the tables
headers = ["Issue Name", "Severity", "Type", "Issue Detail", "Issue Background", "Remediation Detail", "Remediation Background"]
# create custom default table model
self._tableModelShared = CustomDefaultTableModel(None, headers)
# populate the table with initial issues
PopulateSharedTableModel(self).populate()
# return
return
#
# add panels with constraints to other panels
#
def addPanelWithConstraints(self, gridx, gridy, gridwidth, weightx, weighty, panelMain, panelToAdd, constraints):
# set constraints
constraints.gridx = gridx
constraints.gridy = gridy
constraints.gridwidth = gridwidth
constraints.weightx = weightx
constraints.weighty = weighty
# add panel with constraints to dialog panel
panelMain.add(panelToAdd, constraints)
# return
return
#
# create the main extension tab and issue selection tab for the popup dialog
#
def createMainTabOrIssueSelectionTab(self, tabName):
# create panels
self._dictionaryOfPanels[tabName + " Buttons"] = JPanel()
self._dictionaryOfPanels[tabName + " Top North"] = JPanel()
self._dictionaryOfPanels[tabName + " Top"] = JPanel()
self._dictionaryOfPanels[tabName + " Bottom"] = JPanel()
# set layout for panels
self._dictionaryOfPanels[tabName + " Top North"].setLayout(BorderLayout())
self._dictionaryOfPanels[tabName + " Top"].setLayout(BorderLayout())
self._dictionaryOfPanels[tabName + " Bottom"].setLayout(GridBagLayout())
##### Top Section - Start #####
# check if main tab
if tabName == self._MAIN_TAB_NAME:
# create a custom grid layout
customGridLayout = GridLayout(2, 3)
# set vertical gap to help with spacing
customGridLayout.setVgap(10)
# set layout for button panel
self._dictionaryOfPanels[tabName + " Buttons"].setLayout(customGridLayout)
# set variable for the largest button size
largestButtonSize = None
# get the count of items in the array of buttons
arrayLength = len(self._MAIN_TAB_BUTTON_NAMES)
# loop through all of the button names for the main tab
for index, buttonName in enumerate(self._MAIN_TAB_BUTTON_NAMES):
# set variable if it is half way through the array
halfWayPoint = (index + 1) == (arrayLength / 2)
# create button and button panel
self.createMainTabButtonAndButtonPanel(tabName, buttonName, halfWayPoint)
# get the button size
buttonSize = self._dictionaryOfButtons[buttonName].getPreferredSize()
# check if the largest button size is set
if largestButtonSize == None:
# set the largest button size
largestButtonSize = buttonSize
# check if the button width is larger than the largest button size width
elif buttonSize.getWidth() > largestButtonSize.getWidth():
# set largest button size to the button size
largestButtonSize = buttonSize
# loop through all of the button names for the main tab
for buttonName in self._MAIN_TAB_BUTTON_NAMES:
# set button to largest button size
self._dictionaryOfButtons[buttonName].setPreferredSize(largestButtonSize)
# check if issue selection tab
elif tabName == self._DIALOG_TAB_2_NAME:
# set layout for button panel
self._dictionaryOfPanels[tabName + " Buttons"].setLayout(GridBagLayout())
# create button
self._buttonSelectIssue = JButton("Add Information From Highlighted Issue", actionPerformed=lambda x, tab=tabName: self.buttonActionOpenAddIssueDialog(tab))
# add button to top panel
self._dictionaryOfPanels[tabName + " Buttons"].add(self._buttonSelectIssue)
##### Middle Section - Start #####
# try to check if the table model has been created
try:
# check if the table model has been created
self._tableModelShared
# table model has not been created
except:
# create a shared table model for the issue selection tab and main tab
self.createSharedTableModel()
# create custom JTable
self._dictionaryOfTables[tabName] = CustomJTable(self, self._tableModelShared, tabName)
# set preferred column widths for table
self._dictionaryOfTables[tabName].getColumnModel().getColumn(0).setPreferredWidth(270)
self._dictionaryOfTables[tabName].getColumnModel().getColumn(1).setPreferredWidth(65)
self._dictionaryOfTables[tabName].getColumnModel().getColumn(2).setPreferredWidth(55)
self._dictionaryOfTables[tabName].getColumnModel().getColumn(3).setPreferredWidth(185)
self._dictionaryOfTables[tabName].getColumnModel().getColumn(4).setPreferredWidth(185)
self._dictionaryOfTables[tabName].getColumnModel().getColumn(5).setPreferredWidth(110)
self._dictionaryOfTables[tabName].getColumnModel().getColumn(6).setPreferredWidth(180)
# create custom table row sorter that can unsort
self._dictionaryOfTableRowSorters[tabName] = CustomTableRowSorter(self._dictionaryOfTables[tabName].getModel())
# set row sorter
self._dictionaryOfTables[tabName].setRowSorter(self._dictionaryOfTableRowSorters[tabName])
# only allow single rows to be selected
self._dictionaryOfTables[tabName].setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
# create a custom mouse listener to detect if the mouse is clicked and dragging on the table to prevent the same row from being selected and unselected
self._dictionaryOfTables[tabName].addMouseListener(CustomMouseListener(self))
# set mouse state to detect if the mouse is clicked and dragging on the table to prevent the same row from being selected and unselected
self._mouseState = None
# create scroll pane
self._dictionaryOfScrollPanes[tabName] = JScrollPane(self._dictionaryOfTables[tabName])
##### Bottom Section - Start #####
# create text areas, scroll panes, and panels
self.createTextAndScrollPaneAndPanel("TextPane", "editableN", tabName, 0, "Issue Name")
self.createTextAndScrollPaneAndPanel("TextPane", "editableN", tabName, 0, "Severity")
self.createTextAndScrollPaneAndPanel("TextArea", "editableN", tabName, 6, "Issue Detail")
self.createTextAndScrollPaneAndPanel("TextArea", "editableN", tabName, 6, "Issue Background")
self.createTextAndScrollPaneAndPanel("TextArea", "editableN", tabName, 6, "Remediation Detail")
self.createTextAndScrollPaneAndPanel("TextArea", "editableN", tabName, 6, "Remediation Background")
# create grid bag constraints for main extension tab, popup dialog, and issue selection tab
self._gridBagConstraints = GridBagConstraints()
# fill vertically and horizontally
self._gridBagConstraints.fill = GridBagConstraints.BOTH
# set spacing
self._gridBagConstraints.insets = Insets(0, 0, 0, 0)
# first row
self.addPanelWithConstraints(0, 1, 1, 1, 0, self._dictionaryOfPanels[tabName + " Bottom"], self._dictionaryOfPanels[tabName + " Issue Name"], self._gridBagConstraints)
self.addPanelWithConstraints(1, 1, 1, 1, 0, self._dictionaryOfPanels[tabName + " Bottom"], self._dictionaryOfPanels[tabName + " Severity"], self._gridBagConstraints)
# second row
self.addPanelWithConstraints(0, 3, 1, 1, 0.5, self._dictionaryOfPanels[tabName + " Bottom"], self._dictionaryOfPanels[tabName + " Issue Detail"], self._gridBagConstraints)
self.addPanelWithConstraints(1, 3, 1, 1, 0.5, self._dictionaryOfPanels[tabName + " Bottom"], self._dictionaryOfPanels[tabName + " Issue Background"], self._gridBagConstraints)
# third row
self.addPanelWithConstraints(0, 5, 1, 1, 0.5, self._dictionaryOfPanels[tabName + " Bottom"], self._dictionaryOfPanels[tabName + " Remediation Detail"], self._gridBagConstraints)
self.addPanelWithConstraints(1, 5, 1, 1, 0.5, self._dictionaryOfPanels[tabName + " Bottom"], self._dictionaryOfPanels[tabName + " Remediation Background"], self._gridBagConstraints)
# add space before each row of panels
self.addPanelWithConstraints(0, 0, 2, 0, 0, self._dictionaryOfPanels[tabName + " Bottom"], JPanel(), self._gridBagConstraints)
self.addPanelWithConstraints(0, 2, 2, 0, 0, self._dictionaryOfPanels[tabName + " Bottom"], JPanel(), self._gridBagConstraints)
self.addPanelWithConstraints(0, 4, 2, 0, 0, self._dictionaryOfPanels[tabName + " Bottom"], JPanel(), self._gridBagConstraints)
# create split pane
self._dictionaryOfSplitPanes[tabName] = JSplitPane(JSplitPane.VERTICAL_SPLIT)
self._dictionaryOfSplitPanes[tabName].setResizeWeight(0.3)
self._dictionaryOfSplitPanes[tabName].setDividerLocation(0.3)
# create warning labels
self.createWarningLabel(tabName, " 1")
self.createWarningLabel(tabName, " 2")
# set top north panel
self._dictionaryOfPanels[tabName + " Top North"].add(self._dictionaryOfLabels[tabName + " 1"], BorderLayout.NORTH)
self._dictionaryOfPanels[tabName + " Top North"].add(self._dictionaryOfPanels[tabName + " Buttons"], BorderLayout.CENTER)
self._dictionaryOfPanels[tabName + " Top North"].add(self._dictionaryOfLabels[tabName + " 2"], BorderLayout.SOUTH)
# set top panel
self._dictionaryOfPanels[tabName + " Top"].add(self._dictionaryOfPanels[tabName + " Top North"], BorderLayout.NORTH)
self._dictionaryOfPanels[tabName + " Top"].add(self._dictionaryOfScrollPanes[tabName], BorderLayout.CENTER)
# set top and bottom of split pane
self._dictionaryOfSplitPanes[tabName].setLeftComponent(self._dictionaryOfPanels[tabName + " Top"])
self._dictionaryOfSplitPanes[tabName].setRightComponent(self._dictionaryOfPanels[tabName + " Bottom"])
# check if tabName is the issue selection tab
if tabName == self._DIALOG_TAB_2_NAME:
# set flag to determine if the issue selection tab becomes visible for the first time to reset split pane location. Since it is not visible when created, it will not set correctly
self._issueSelectionTabFirstTimeVisible = True
# return
return
#
# create the popup dialog to add a new issue from
#
def createAddIssueDialog(self, tabName):
# create dialog box to add issues manually
self._dialogAddIssue = JDialog()
# hide dialog box
self._dialogAddIssue.setVisible(False)
# create panel for dialog box
self._panelDialogAddIssueMain = JPanel()
self._panelDialogAddIssueMain.setLayout(BorderLayout())
# create top panel for first row of five columns
self._panelDialogAddIssueTop = JPanel()
self._panelDialogAddIssueTop.setLayout(GridBagLayout())
# create bottom panel for all other rows of two columns
self._panelDialogAddIssueBottom = JPanel()
self._panelDialogAddIssueBottom.setLayout(GridBagLayout())
# create text areas, scroll panes, and panels for main tab
self.createTextAndScrollPaneAndPanel("TextArea", "editableY", tabName, 1, "Issue Name")
self.createTextAndScrollPaneAndPanel("TextArea", "editableY", tabName, 1, "Port")
self.createTextAndScrollPaneAndPanel("TextArea", "editableY", tabName, 1, "Host")
self.createTextAndScrollPaneAndPanel("TextArea", "editableY", tabName, 1, "Path")
self.createTextAndScrollPaneAndPanel("TextArea", "editableN", tabName, 1, "Issue Location")
self.createTextAndScrollPaneAndPanel("TextArea", "editableY", tabName, 4, "Issue Detail")
self.createTextAndScrollPaneAndPanel("TextArea", "editableY", tabName, 4, "Issue Background")
self.createTextAndScrollPaneAndPanel("TextArea", "editableY", tabName, 4, "Remediation Detail")
self.createTextAndScrollPaneAndPanel("TextArea", "editableY", tabName, 4, "Remediation Background")
self.createTextAndScrollPaneAndPanel("TextArea", "editableY", tabName, 6, "Request")
self.createTextAndScrollPaneAndPanel("TextArea", "editableY", tabName, 6, "Response")
# create combo boxes and panels for main tab
self.createComboBoxAndPanel(tabName, "Severity")
self.createComboBoxAndPanel(tabName, "Confidence")
self.createComboBoxAndPanel(tabName, "Protocol")
# fill vertically and horizontally
self._gridBagConstraints.fill = GridBagConstraints.BOTH
# set spacing
self._gridBagConstraints.insets = Insets(0, 0, 0, 0)
# first row
self.addPanelWithConstraints(0, 1, 1, 0.2, 0.02, self._panelDialogAddIssueTop, self._dictionaryOfPanels[tabName + " Issue Name"], self._gridBagConstraints)
self.addPanelWithConstraints(1, 1, 1, 0.0, 0.02, self._panelDialogAddIssueTop, self._dictionaryOfPanels[tabName + " Severity"], self._gridBagConstraints)
self.addPanelWithConstraints(2, 1, 1, 0.0, 0.02, self._panelDialogAddIssueTop, self._dictionaryOfPanels[tabName + " Confidence"], self._gridBagConstraints)
self.addPanelWithConstraints(3, 1, 1, 0.0, 0.02, self._panelDialogAddIssueTop, self._dictionaryOfPanels[tabName + " Protocol"], self._gridBagConstraints)
self.addPanelWithConstraints(4, 1, 1, 0.2, 0.02, self._panelDialogAddIssueTop, self._dictionaryOfPanels[tabName + " Port"], self._gridBagConstraints)
# second row
self.addPanelWithConstraints(0, 1, 1, 0.5, 0.05, self._panelDialogAddIssueBottom, self._dictionaryOfPanels[tabName + " Host"], self._gridBagConstraints)
self.addPanelWithConstraints(1, 1, 1, 0.5, 0.05, self._panelDialogAddIssueBottom, self._dictionaryOfPanels[tabName + " Path"], self._gridBagConstraints)
# third row
self.addPanelWithConstraints(0, 3, 2, 1, 0.05, self._panelDialogAddIssueBottom, self._dictionaryOfPanels[tabName + " Issue Location"], self._gridBagConstraints)
# fourth row
self.addPanelWithConstraints(0, 5, 1, 1, 0.75, self._panelDialogAddIssueBottom, self._dictionaryOfPanels[tabName + " Issue Detail"], self._gridBagConstraints)
self.addPanelWithConstraints(1, 5, 1, 1, 0.75, self._panelDialogAddIssueBottom, self._dictionaryOfPanels[tabName + " Issue Background"], self._gridBagConstraints)
# fifth row
self.addPanelWithConstraints(0, 7, 1, 1, 0.75, self._panelDialogAddIssueBottom, self._dictionaryOfPanels[tabName + " Remediation Detail"], self._gridBagConstraints)
self.addPanelWithConstraints(1, 7, 1, 1, 0.75, self._panelDialogAddIssueBottom, self._dictionaryOfPanels[tabName + " Remediation Background"], self._gridBagConstraints)
# sixth row
self.addPanelWithConstraints(0, 9, 1, 0.5, 1, self._panelDialogAddIssueBottom, self._dictionaryOfPanels[tabName + " Request"], self._gridBagConstraints)
self.addPanelWithConstraints(1, 9, 1, 0.5, 1, self._panelDialogAddIssueBottom, self._dictionaryOfPanels[tabName + " Response"], self._gridBagConstraints)
# add space before each row of panels
self.addPanelWithConstraints(0, 0, 5, 0, 0, self._panelDialogAddIssueTop, JPanel(), self._gridBagConstraints)
self.addPanelWithConstraints(0, 0, 2, 0, 0, self._panelDialogAddIssueBottom, JPanel(), self._gridBagConstraints)
self.addPanelWithConstraints(0, 2, 2, 0, 0, self._panelDialogAddIssueBottom, JPanel(), self._gridBagConstraints)
self.addPanelWithConstraints(0, 4, 2, 0, 0, self._panelDialogAddIssueBottom, JPanel(), self._gridBagConstraints)
self.addPanelWithConstraints(0, 6, 2, 0, 0, self._panelDialogAddIssueBottom, JPanel(), self._gridBagConstraints)
self.addPanelWithConstraints(0, 8, 2, 0, 0, self._panelDialogAddIssueBottom, JPanel(), self._gridBagConstraints)
# do not stretch button
self._gridBagConstraints.fill = GridBagConstraints.NONE
# create button
self._buttonDialogAddIssue = JButton(" " + self._EXTENSION_NAME[:-1] + " ", actionPerformed=self.buttonActionAddIssue)
# add seventh row
self.addPanelWithConstraints(0, 10, 2, 1, 0, self._panelDialogAddIssueBottom, self._buttonDialogAddIssue, self._gridBagConstraints)
# add top and bottom panels to main panel
self._panelDialogAddIssueMain.add(self._panelDialogAddIssueTop, BorderLayout.NORTH)
self._panelDialogAddIssueMain.add(self._panelDialogAddIssueBottom, BorderLayout.CENTER)
# create tabs for dialog box
self._tabbedPaneDialog = JTabbedPane()
self._tabbedPaneDialog.addTab(tabName, self._panelDialogAddIssueMain)
self._tabbedPaneDialog.addTab(self._DIALOG_TAB_2_NAME, self._dictionaryOfSplitPanes[self._DIALOG_TAB_2_NAME])
# add tabbed pane to dialog
self._dialogAddIssue.add(self._tabbedPaneDialog)
# set dialog size
self._dialogAddIssue.setBounds(0, 0, 1200, 740)
# set dialog title
self._dialogAddIssue.setTitle(self._EXTENSION_NAME)
# return
return
#
# open the issue dialog from the menu choice
#
def menuActionOpenAddIssueDialog(self, invocation):
# clear the popup dialog
self.clearAddIssueDialog()
# make the add issue dialog visible
self.makeAddIssueDialogVisible()
# set selected text area to issue name
self._dictionaryOfTextAreas[self._DIALOG_TAB_1_NAME + " Issue Name"].requestFocusInWindow()
# set port to default value
setPortToDefaultValue = False
# check that the IHttpRequestResponse messages is not none and one exists in the array
if invocation.getSelectedMessages() != None and len(invocation.getSelectedMessages()) > 0:
# set the message
invocationMessagesOrIssues = invocation.getSelectedMessages()
# get message
invocationMessagesOrIssue = invocationMessagesOrIssues[0]
# check that the IScanIssue issues is not none and one exists in the array
elif invocation.getSelectedIssues() != None and len(invocation.getSelectedIssues()) > 0:
# set the issue
invocationMessagesOrIssues = invocation.getSelectedIssues()
# get issue
invocationMessagesOrIssue = invocationMessagesOrIssues[0]
# no message or issue
else:
# set to none
invocationMessagesOrIssue = None
# set port to default value instead of blank
setPortToDefaultValue = True
# try to get the http service
try:
# set http service
httpService = invocationMessagesOrIssue.getHttpService()
except:
# set to blank
httpService = ""
# try to get the protocol
try:
# set protocol
protocol = httpService.getProtocol()
except:
# set to blank
protocol = ""
# try to get the host
try:
# set host
host = httpService.getHost()
except:
# set to blank
host = ""
# try to get the port
try:
# set port
port = str(httpService.getPort())
except:
# check if the port should be set to the default value
if setPortToDefaultValue:
# set to blank
port = "443"
else:
# set to blank
port = ""
# try to get the url
try:
# set url
url = invocationMessagesOrIssue.getUrl()
except:
# set to blank
url = ""
# try to get the path
try:
# set path
path = url.getPath()
except:
# set to blank
path = ""
# try to get the request
try:
# set request
request = invocationMessagesOrIssue.getRequest().tostring()
except:
# set to blank
request = ""
# try to get the response
try:
# set response
response = invocationMessagesOrIssue.getResponse().tostring()
except:
# set to blank
response = ""
# loop through each protocol choice for the combo box
for protocolChoice in self._PROTOCOL_COMBOBOX_CHOICES:
# check if the protocol choice matches the protocol
if protocolChoice.strip().lower() == protocol:
# set the protocol combo box to the protocol
self._dictionaryOfComboBoxes[self._DIALOG_TAB_1_NAME + " Protocol"].setSelectedItem(protocolChoice)
# do not continue through the choices
break
# set text fields
self._dictionaryOfTextAreas[self._DIALOG_TAB_1_NAME + " Port"].setText(port)
self._dictionaryOfTextAreas[self._DIALOG_TAB_1_NAME + " Host"].setText(host)
self._dictionaryOfTextAreas[self._DIALOG_TAB_1_NAME + " Path"].setText(path)
self._dictionaryOfTextAreas[self._DIALOG_TAB_1_NAME + " Request"].setText(request)
self._dictionaryOfTextAreas[self._DIALOG_TAB_1_NAME + " Response"].setText(response)
# return
return
#
# open the issue dialog from the main tab button or the issue selection button
#
def buttonActionOpenAddIssueDialog(self, tabName):
# get the selected row
selectedRow = self._dictionaryOfTables[tabName].getSelectedRow()
# check if a row was not selected and the dialog is visible
if selectedRow == -1 and self._dialogAddIssue.isVisible():
# check if the click was from the main tab
if tabName == self._MAIN_TAB_NAME:
# make the add issue dialog visible which brings it to the front
self.makeAddIssueDialogVisible()
# set selected text area to host since an issue name was filled in
self._dictionaryOfTextAreas[self._DIALOG_TAB_1_NAME + " Issue Name"].requestFocusInWindow()
# do not continue
return
# check if the dialog is visible and a row was selected
elif self._dialogAddIssue.isVisible():
# make the add issue dialog visible which brings it to the front
self.makeAddIssueDialogVisible()
# set selected text area to host since an issue name was filled in
self._dictionaryOfTextAreas[self._DIALOG_TAB_1_NAME + " Host"].requestFocusInWindow()
# dialog is not visible
else:
# clear the popup dialog
self.clearAddIssueDialog()
# make the add issue dialog visible
self.makeAddIssueDialogVisible()
# check if a row was not selected
if selectedRow == -1:
# set selected text area to issue name since an issue was not selected