-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
96 lines (71 loc) · 2.49 KB
/
main.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
from burp import IBurpExtender, IContextMenuFactory, IHttpRequestResponse
from adapters.javascript_parser import JavascriptParser
from python_parser import PythonParser
from java.io import PrintWriter
from java.util import ArrayList
from javax.swing import JMenuItem
from java.awt import Toolkit
from java.awt.datatransfer import StringSelection
from javax.swing import JOptionPane
import json
import subprocess
import tempfile
import threading
import time
import re
from request_tree import RequestTree
VERSION="1.0.0"
EXT_NAME="Copy Request"
class BurpExtender(IBurpExtender, IContextMenuFactory, IHttpRequestResponse):
def toString(self):
return EXT_NAME + " v" + VERSION
def registerExtenderCallbacks(self, callbacks):
callbacks.setExtensionName(EXT_NAME)
stdout = PrintWriter(callbacks.getStdout(), True)
stderr = PrintWriter(callbacks.getStderr(), True)
self.stdout = stdout
self.stderr = stderr
self.helpers = callbacks.getHelpers()
self.callbacks = callbacks
callbacks.registerContextMenuFactory(self)
# Load parsers
self.pythonParser = PythonParser(callbacks)
print("BurpExtender::registerExtenderCallbacks: " + self.toString() + " loaded successfully!")
def createMenuItems(self, invocation):
self.context = invocation
menu_list = ArrayList()
menu_list.add(JMenuItem("as javascript fetch",
actionPerformed=self.copy_js))
menu_list.add(JMenuItem("as python requests (Not yet)",
actionPerformed=self.copy_python))
return menu_list
def copy_js(self, event):
requests = self.getRequestsData()
request_trees = []
for request in requests:
rt = RequestTree(request, self.callbacks)
request_trees.append(rt)
JavascriptParser(request_trees, self.callbacks)
def copy_python(self, event):
data = self.getRequestsData()
self.pythonParser.parse(data)
def getRequestsData(self):
http_traffic = self.context.getSelectedMessages()
requests = []
for message in http_traffic:
http_request = message.getRequest()
http_response = message.getResponse()
url = message.getUrl()
request_data = self.bytesToString(http_request)
response_data = self.bytesToString(http_response)
requests.append({
"request_data": request_data,
"response_data": response_data,
"url": url
})
return requests
def bytesToString(self, data):
if data is None:
return None
data = self.helpers.bytesToString(data).replace('\r\n', '\n')
return data