-
Notifications
You must be signed in to change notification settings - Fork 6
/
jsextractor.py
61 lines (54 loc) · 2.71 KB
/
jsextractor.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
from burp import IBurpExtender
from burp import IContextMenuFactory
from burp import IContextMenuInvocation
from javax.swing import JMenuItem, JFileChooser
from java.awt import Toolkit
from java.awt.datatransfer import StringSelection
from java.io import FileWriter
class BurpExtender(IBurpExtender, IContextMenuFactory):
def registerExtenderCallbacks(self, callbacks):
self._callbacks = callbacks
self._helpers = callbacks.getHelpers()
self._callbacks.setExtensionName("JS File Extractor with Clipboard Support")
self._callbacks.registerContextMenuFactory(self)
def createMenuItems(self, invocation):
self.context = invocation
menu_list = []
menu_list.append(JMenuItem("Extract JS Files to File", actionPerformed=lambda x, inv=invocation: self.extract_js_files(inv)))
menu_list.append(JMenuItem("Copy JS Files to Clipboard", actionPerformed=lambda x, inv=invocation: self.copy_js_files_to_clipboard(inv)))
return menu_list
def extract_js_files(self, invocation):
fileChooser = JFileChooser()
returnValue = fileChooser.showSaveDialog(None)
if returnValue == JFileChooser.APPROVE_OPTION:
selectedFile = fileChooser.getSelectedFile()
with open(selectedFile.getPath(), 'w') as file:
js_files = self.get_js_files(invocation)
for js_file in js_files:
file.write(js_file + '\n')
def copy_js_files_to_clipboard(self, invocation):
js_files = self.get_js_files(invocation)
string_to_copy = '\n'.join(js_files)
stringSelection = StringSelection(string_to_copy)
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard()
clipboard.setContents(stringSelection, None)
def get_js_files(self, invocation):
selected_messages = invocation.getSelectedMessages()
target_domains = set()
js_files = set()
if selected_messages:
for message in selected_messages:
url = self._helpers.analyzeRequest(message).getUrl()
target_domains.add(url.getHost())
sitemap = self._callbacks.getSiteMap(None)
for item in sitemap:
request_info = self._helpers.analyzeRequest(item)
url = request_info.getUrl()
if url.getHost() in target_domains:
response = item.getResponse()
if response:
response_info = self._helpers.analyzeResponse(response)
headers = response_info.getHeaders()
if any("javascript" in header for header in headers):
js_files.add(str(url))
return js_files