-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBurpExportsObjects.py
More file actions
164 lines (132 loc) · 5.66 KB
/
BurpExportsObjects.py
File metadata and controls
164 lines (132 loc) · 5.66 KB
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
from burp import IBurpExtender, IRequestInfo, IContextMenuFactory
from java.io import PrintWriter
from javax.swing import JMenu, JMenuItem, JFileChooser
# File I/O
from java.io import File, FileOutputStream
# Path
from java.net import URI
class BurpExtender(IBurpExtender, IRequestInfo, IContextMenuFactory):
def registerExtenderCallbacks(self, callbacks):
self._actionName = "Export Objects"
self._helers = callbacks.getHelpers()
self._callbacks = callbacks
self._helpers = callbacks.getHelpers()
callbacks.setExtensionName("Export Objects")
callbacks.registerContextMenuFactory(self)
# obtain our output and error streams
self._stderr = PrintWriter(callbacks.getStderr(), True)
self._stdout = PrintWriter(callbacks.getStdout(), True)
# write a message to the Burp alerts tab
callbacks.issueAlert("Installed Export Objects.")
def createMenuItems(self, invocation):
menu = JMenu(self._actionName)
self._menu_item = JMenuItem("Export",
None,
actionPerformed=lambda x,
inv=invocation: self.Action(inv),)
menu.add(self._menu_item)
return [menu]
def Action(self, invocation):
try:
http_traffic = invocation.getSelectedMessages()
traffic_length = len(http_traffic)
counter = 0
self._output_dir = u"/tmp"
# choose output directory
filechooser = JFileChooser()
filechooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)
selected = filechooser.showSaveDialog(self._menu_item)
if selected == JFileChooser.APPROVE_OPTION:
f = filechooser.getSelectedFile()
self._output_dir = f.getAbsolutePath()
self._stdout.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
while len(http_traffic) > 0:
counter += 1
target_traffic = http_traffic.pop()
analyzedRequest = self._helpers.analyzeRequest(
target_traffic
)
analyzedResponse = self._helpers.analyzeResponse(
target_traffic.getResponse()
)
status_code = analyzedResponse.getStatusCode()
mime_type = analyzedResponse.getStatedMimeType()
url = analyzedRequest.getUrl()
body_offset = analyzedResponse.getBodyOffset()
# Skip empty response.
if len(target_traffic.getResponse()[body_offset:]) <= 0:
self._stdout.printf("[%d/%d]\n", counter, traffic_length)
self._stdout.println("[-] %s's response is empty.", url)
continue
# resolve filename from url.
file_name = self.extract_filename(url)
# check extention.
if not self.has_extention(file_name):
ex = self.guess_extention(mime_type,
target_traffic.getResponse())
file_name = file_name + "." + ex
file_path = self._output_dir + u"/" + file_name.encode('utf-8')
self._stdout.printf("[%d/%d]\n", counter, traffic_length)
self._stdout.printf("url: %s\n", url)
self._stdout.printf("status_code: %d\n", status_code)
self._stdout.printf("mime_type: %s\n", mime_type)
self._stdout.printf("body_offset: %d\n", body_offset)
# extract object
self.extract_obj(file_path,
target_traffic.getResponse(),
body_offset)
self._stdout.printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n")
except Exception as e:
self._stderr.println("[!] In Action.")
self._stderr.println(e)
def extract_filename(self, url):
uri = url.toURI()
path = uri.getPath().encode('utf-8')
file_name = path.split(u"/")[-1]
return file_name
def has_extention(self, file_name):
return len(file_name.split(".")) > 1
def guess_extention(self, mime, res):
if mime == u"JPEG":
return u"jpg"
elif mime == u"GIF":
return u"gif"
elif mime == u"PNG":
return u"png"
elif mime == u"HTML":
return u"html"
elif mime == u"JSON":
return u"json"
elif mime == u"XML":
return u"xml"
elif mime == u"scrip":
# Only javascript is supported.
return u"js"
elif mime == u"text":
return u"txt"
elif mime == u"image":
return u"ico"
else:
return u""
def extract_obj(self, file_path, res, offset):
try:
f = File(file_path)
# check same name file.
counter = 0
while True:
# The same file name is not exists.
if not f.exists():
break
# Count up the file name.
counter += 1
stem = u"".join(file_path.split(u".")[:-1])
ex = file_path.split(u".")[-1]
_file_path = u"{}({}).{}".format(stem, counter, ex)
f = File(_file_path)
fos = FileOutputStream(f)
fos.write(res[offset:])
self._stdout.printf("save as \"%s\".\n\n", f.getPath())
fos.close()
except Exception as e:
self._stderr.println("[!] In extract_obj.")
self._stderr.println(e)