-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy path5GC_API_parse.py
262 lines (204 loc) · 8.27 KB
/
5GC_API_parse.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
#
# 5GC API Parse
# A 5GC NF OpenAPI parser - Burp Suite Extension
# Author: Sebastien Dudek (@FlUxIuS) at https://penthertz.com
#
from burp import IBurpExtender, ITab
from burp import IMessageEditorController, IContextMenuFactory
from javax import swing
from java.awt import (
Font,
BorderLayout,
Color,
Desktop,
Button,
)
from java.awt.event import ActionListener
from javax.swing import (
JButton,
JFileChooser,
JMenuItem,
)
from javax.swing.text import DefaultHighlighter
from java.util import LinkedList
from java.net import URI
import sys
from urlparse import urlparse
from utils.OpenAPI3GPP import *
__AUTHOR__ = "Sebastien Dudek (FlUxIuS)"
__VERSION__ = "1.2"
SWAGGER_URL = "https://jdegre.github.io/editor/?url=https://raw.githubusercontent.com/jdegre/5GC_APIs/master/"
try:
from exceptions_fix import FixBurpExceptions
except ImportError:
pass
class CallbackActionListener(ActionListener):
def __init__(self, callback):
ActionListener.__init__(self)
self._callback = callback
def actionPerformed(self, event):
self._callback(event)
class BurpExtender(IBurpExtender, ITab, IMessageEditorController, IContextMenuFactory):
editboxes = []
def registerExtenderCallbacks(self, callbacks):
sys.stdout = callbacks.getStdout()
# Keep a reference to our callbacks object
self.callbacks = callbacks
# Set our extension name
self.callbacks.setExtensionName("5GC API Parse")
self.callbacks.registerContextMenuFactory(self)
self.helpers = callbacks.getHelpers();
# Create the tab
self.tab = swing.JPanel(BorderLayout())
# Create panel
textPanel = swing.JPanel()
# Create boxes
boxVertical = swing.Box.createVerticalBox()
boxHorizontal = swing.Box.createHorizontalBox()
boxHorizontalFile = swing.Box.createHorizontalBox()
boxHorizontalPort = swing.Box.createHorizontalBox()
# YAML file label
toptextLabel = swing.JLabel('5GC Network Function parser (version 1.2)')
boxHorizontal.add(toptextLabel)
author = swing.JLabel('By @FlUxIuS at https://penthertz.com')
# Set title font
toptextLabel.setFont(Font('Courier New', Font.BOLD, 16))
toptextLabel.setForeground(Color.RED)
# URL text area
self.textURL = swing.JTextArea('', 1, 100)
self.textURL.setLineWrap(True)
self.textURL.setText('https://target:8000/endpoint')
self.textAreaFile = swing.JTextArea('', 1, 100)
self.textAreaFile.setLineWrap(True)
buttonFile = Button('Select File', actionPerformed=self.selectFile)
boxHorizontalFile.add(self.textAreaFile)
boxHorizontalFile.add(buttonFile)
boxVertical.add(boxHorizontal)
portLabel = swing.JLabel('Port:')
boxHorizontalPort.add(portLabel)
self.textPort = swing.JTextArea('', 1, 10)
self.textPort.setLineWrap(True)
self.textPort.setText('8000')
boxHorizontalPort.add(self.textPort)
boxVertical.add(self.textURL)
boxVertical.add(boxHorizontalPort)
boxVertical.add(boxHorizontalFile)
self.buttonParseFile = Button('Parse 3GPP OpenAPI file', actionPerformed=self.parseFile)
boxVertical.add(self.buttonParseFile)
# add author to vert box
boxVertical.add(author)
# Add the text label and area to the text panel
textPanel.add(boxVertical)
# Created a tabbed pane to go in the center of the
# main tab, below the text area
self.tabbedPane = swing.JTabbedPane()
self.tab.add("Center", self.tabbedPane)
# Add the text panel to the top of the main tab
self.tab.add(textPanel, BorderLayout.NORTH)
# Add the custom tab to Burp's UI
callbacks.addSuiteTab(self)
return
def clearTabs(self, event):
"""
Clear all tabs
"""
self.editboxes = []
self.tab.remove(self.tabbedPane)
self.tabbedPane = swing.JTabbedPane()
self.tab.add("Center", self.tabbedPane)
def selectFile(self, event):
"""
SelectFile - Open file select popup
"""
chooser = JFileChooser()
retVal = chooser.showSaveDialog(None)
self.textAreaFile.setText(chooser.selectedFile.path)
# Implement ITab
def getTabCaption(self):
"""Return the text to be displayed on the tab"""
return "5GC API Parse"
def getUiComponent(self):
"""Passes the UI to burp"""
return self.tab
def parseFile(self, event):
"""
Parse OpenAPI even
"""
# First tab
yamlfile = self.textAreaFile.getText()
oapi = OpenAPI3GPP(yamlfile)
paths = oapi.listpaths()
parsedUrl = urlparse(self.textURL.getText())
for path in paths:
verbs = oapi.getEndPointVerbs(path)
for verb in verbs:
tag = oapi.getTags(path, verb)
desc = oapi.getEndPointSummary(path, verb)
params = oapi.dumpParameters(path, verb)
reqpath = urlparse(self.textURL.getText()).path
toreq = oapi.buildRequest(path, verb, reqpath, parsedUrl.netloc)
body = oapi.dumpRequestBody(path, verb)
#if len(body) == 0:
params += "\n\n"+body
self.createnewtab(tag, toreq, desc, params)
def sendToRepeater(self, event):
isHttps = False
parsedUrl = urlparse(self.textURL.getText())
if parsedUrl.scheme.lower() == "https":
isHttps = True
for name, b in self.editboxes:
self.callbacks.sendToRepeater(
parsedUrl.netloc.split(':')[0],
int(self.textPort.getText()),
isHttps,
b.getMessage(),
name
);
def createnewtab(self, name, content, desc, params):
"""
Creates tabs for each endpoints.
in(1): string name of the tab
in(2): request content
in(3): descripption string
in(4): params strings
"""
# Create boxes
boxVertical = swing.Box.createVerticalBox()
boxHorizontal = swing.Box.createHorizontalBox()
summary = swing.JLabel('Summary')
summary.setBorder(swing.BorderFactory.createEmptyBorder(10, 10, 10, 10))
summary.setFont(Font('Courier New', Font.BOLD, 16))
summary.setForeground(Color.RED)
summaryText = swing.JLabel(desc)
summaryText.setBorder(swing.BorderFactory.createEmptyBorder(10, 10, 10, 10))
boxVertical.add(summary)
boxVertical.add(summaryText)
boxVertical.add(boxHorizontal)
tabedit = self.callbacks.createMessageEditor(self, True)
self.editboxes.append((name, tabedit))
boxHorizontal.add(tabedit.getComponent())
self.tabbedPane.addTab(name, boxVertical)
tabedit.setMessage(content, True);
rightBox = swing.JPanel()
rightBox.layout = BorderLayout()
rightBox.border = swing.BorderFactory.createTitledBorder('Parameters')
rTextArea = swing.JTextArea('', 15, 100)
rTextArea.setLineWrap(False)
scrollTextArea = swing.JScrollPane(rTextArea)
rightBox.add(scrollTextArea)
boxHorizontal.add(rightBox)
SendTobutton = Button('Send * to repeater', actionPerformed=self.sendToRepeater)
boxVertical.add(SendTobutton)
rTextArea.setText(params)
urltobrowse = SWAGGER_URL + "/" + self.textAreaFile.getText().split("/")[-1]
btnswag = Button('Open similar API file\'s Swagger')
btnswag.addActionListener(
CallbackActionListener(lambda _: Desktop.getDesktop().browse(URI(urltobrowse)))
)
boxVertical.add(btnswag)
ClearAllbutton = Button('Clear all', actionPerformed=self.clearTabs)
boxVertical.add(ClearAllbutton)
try:
FixBurpExceptions()
except:
pass