-
Notifications
You must be signed in to change notification settings - Fork 0
/
BurpSnippets.py
116 lines (89 loc) · 3.66 KB
/
BurpSnippets.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
from burp import IBurpExtender, IRequestInfo, IContextMenuFactory
from java.io import File
from javax.swing import JMenu, JMenuItem, JFileChooser
import json, jarray
from java.awt import Toolkit
from java.awt.datatransfer import Clipboard
from java.awt.datatransfer import StringSelection
# snippets file path.
SNIPPETS_FILE_PATH = "SNIPPETS.json"
class BurpExtender(IBurpExtender, IRequestInfo, IContextMenuFactory):
def __init__(self):
self.snippets_file_path = SNIPPETS_FILE_PATH
def registerExtenderCallbacks(self, callbacks):
self._actionName = "Paste a snippet"
self._helers = callbacks.getHelpers()
self._callbacks = callbacks
self._helpers = callbacks.getHelpers()
callbacks.setExtensionName("BurpSnippets")
callbacks.registerContextMenuFactory(self)
# write a message to the Burp alerts tab
callbacks.issueAlert("Installed BurpSnippets.")
def createMenuItems(self, invocation):
menu = JMenu(self._actionName)
# create import file menu.
import_menu = JMenu("import file")
as_json_menu_item = JMenuItem("as JSON")
as_json_menu_item.actionPerformed = self.generateSelectFileAction(
invocation, as_json_menu_item)
import_menu.add(as_json_menu_item)
menu.add(import_menu)
menu.addSeparator()
# load snippets json file.
snippets_data = None
try:
with open(self.snippets_file_path, "r") as f:
snippets_data = json.load(f)
except Exception as e:
print("Load JSON Error!")
print(e)
# create payload menu.
# # if snippets_data is not set.
if snippets_data is None:
return [menu]
try:
for i in snippets_data:
type_menu = JMenu(i["type"])
for j in i["items"]:
key = j["key"]
payload = j["value"]
a = JMenuItem(
key, None,
actionPerformed=self.generateClickAction(
invocation, payload),)
type_menu.add(a)
menu.add(type_menu)
except Exception as e:
print("Convert snippets Error!")
print(e)
return [menu]
def generateClickAction(self, invocation, payload):
def click_action(self):
# Copy payload to clipboard
kit = Toolkit.getDefaultToolkit()
clip = kit.getSystemClipboard()
ss = StringSelection(payload)
clip.setContents(ss, None)
# Paste payload to text area
selectedIndex = invocation.getSelectionBounds()
req = invocation.getSelectedMessages()[0]
request = req.getRequest()
# convert data into bytes list.
request_list = list(request)
payload_list = map(ord, bytes(payload))
# insert payload.
del request_list[selectedIndex[0]: selectedIndex[1]]
request_list[selectedIndex[0]: selectedIndex[0]] = payload_list
# override request.
request = jarray.array(request_list, "b")
req.setRequest(request)
return click_action
def generateSelectFileAction(self, invocation, parent_component):
burp_extender_obj = self
def selectSnippetsFile(self):
fc = JFileChooser()
result = fc.showOpenDialog(parent_component)
if result == JFileChooser.APPROVE_OPTION:
f = fc.getSelectedFile()
burp_extender_obj.snippets_file_path = fc.getName(f)
return selectSnippetsFile