-
Notifications
You must be signed in to change notification settings - Fork 0
/
lectricus_gui.py
350 lines (265 loc) · 12 KB
/
lectricus_gui.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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
"""
lectricus_gui.py: GUI frontend for Lectricus
"""
import wx
import random
import plistlib
import lectricus
import threading
import subprocess
from pathlib import Path
class LectricusFrame(wx.Frame):
def __init__(self, *args, **kw):
super(LectricusFrame, self).__init__(*args, **kw)
self.vulnerable_apps = None
self.unused_names = []
self.unused_icons = []
self.demo_mode = self._demo_mode_status()
if self.demo_mode is True:
self._load_names()
self._load_icons()
self.SetMenuBar(wx.MenuBar())
self.InitUI()
self.Centre()
def _demo_mode_status(self) -> bool:
"""
Check if demo mode is enabled
"""
return Path("/tmp/lectricus_demo").exists()
def _load_names(self):
"""
Load names from wordlist.txt
"""
with open("/tmp/lectricus_demo/wordlist.txt", "r") as f:
self.unused_names = f.readlines()
def _load_icons(self):
"""
Grab list of icons from icons directory
"""
self.unused_icons = [str(icon) for icon in Path("/tmp/lectricus_demo/icons").glob("*.png")]
def _randomized_app_name(self) -> str:
"""
Generate randomized application name
"""
words = self.unused_names
if len(words) == 0:
self._load_names()
words = self.unused_names
first_name = random.choice(words)
words.remove(first_name)
last_name = random.choice(words)
words.remove(last_name)
return f"/Applications/{first_name.strip().capitalize()} {last_name.strip().capitalize()}.app"
def _randomize_app_icon(self) -> str:
"""
Randomize application icon
"""
icons = self.unused_icons
if len(icons) == 0:
self._load_icons()
icons = self.unused_icons
icon = random.choice(icons)
icons.remove(icon)
return icon
def _friendly_host_os_to_sys(self, os: str) -> str:
"""
Resolve friendly OS name to system name
"""
os = os.split(" ")[-1]
if os == "macOS":
return "darwin"
if os == "Windows":
return "win32"
if os == "Linux":
return "linux"
raise ValueError(f"Invalid OS: {os}")
def _get_vulnerable_apps(self):
self.vulnerable_apps = lectricus.BinarySearch(
platform=self._friendly_host_os_to_sys(self.os_dropdown.GetStringSelection()),
search_paths=[self.directory_dropdown.GetPath()]
).apps
def _export_vulnerable_apps(self, location: str, format: str):
lectricus.ExportVulnerableApplications(location=location, format=format, binary_search_results=self.vulnerable_apps).export()
def OnExport(self, e):
dlg = wx.FileDialog(
parent=self,
message="Choose a file",
defaultDir=str(Path("~/Desktop").expanduser()),
defaultFile="vulnerability-breakdown",
wildcard="PLIST (*.plist)|*.plist|XML (*.xml)|*.xml|JSON (*.json)|*.json|CSV (*.csv)|*.csv",
style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT
)
if dlg.ShowModal() == wx.ID_OK:
filters = ["plist", "xml", "json", "csv"]
self._export_vulnerable_apps(dlg.GetPath(), filters[dlg.GetFilterIndex()])
dlg.Destroy()
subprocess.run(["/usr/bin/open", "--reveal", dlg.GetPath()])
def _resolve_icon_from_path(self, path: str) -> str:
"""
Resolve application icon from path
"""
os = self._friendly_host_os_to_sys(self.os_dropdown.GetStringSelection())
if os == "darwin":
return self._resolve_macos_icon(path)
raise NotImplementedError(f"Icon resolution for {os} is not implemented")
def _resolve_macos_icon(self, input_path: str) -> str:
"""
Resolve macOS application icon
"""
default_icon = "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericApplicationIcon.icns"
info_plist = Path(input_path) / "Contents" / "Info.plist"
if not info_plist.is_file():
return default_icon
plist = plistlib.load(open(info_plist, "rb"))
if "CFBundleIconFile" not in plist:
return default_icon
icon_path = plist["CFBundleIconFile"]
if not icon_path:
return default_icon
icon_path = Path(input_path) / "Contents" / "Resources" / icon_path
if not icon_path.is_file():
return default_icon
return str(icon_path)
def _icon_to_bitmap(self, icon: str, size: tuple = (32, 32)) -> wx.Bitmap:
"""
Convert icon to bitmap
"""
return wx.Bitmap(wx.Bitmap(icon, wx.BITMAP_TYPE_ICON).ConvertToImage().Rescale(size[0], size[1], wx.IMAGE_QUALITY_HIGH))
def OnList(self, e: wx.Event):
# Create new Model Frame with indeterminate progress bar
frame = wx.Dialog(self, -1, "Listing vulnerable applications")
title = wx.StaticText(frame, label="Searching for vulnerable applications")
title.SetFont(wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.BOLD))
title.SetPosition((-1, 15))
title.Center(wx.HORIZONTAL)
subtitle = wx.StaticText(frame, label="Please wait...")
subtitle.SetPosition((-1, title.GetPosition()[1] + 20))
subtitle.Center(wx.HORIZONTAL)
gauge = wx.Gauge(frame, -1, subtitle.GetPosition()[1] + 20, (20, 50), (250, 25))
gauge.Center(wx.HORIZONTAL)
gauge.Pulse()
frame.SetSize((-1, gauge.GetPosition()[1] + 80))
frame.ShowWindowModal()
wx.Yield()
thread = threading.Thread(target=self._get_vulnerable_apps)
thread.start()
while thread.is_alive():
wx.Yield()
# Close the Model Frame
frame.Destroy()
# Create new Model Frame with list of vulnerable applications
frame = wx.Dialog(self, -1, "Vulnerable applications")
frame.SetSize((890, -1))
title = wx.StaticText(frame, label="Vulnerable applications")
title.SetFont(wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.BOLD))
title.SetPosition((-1, 15))
title.Center(wx.HORIZONTAL)
vulnerable_apps = 0
for category, apps in self.vulnerable_apps.items():
if category in [lectricus.Classification.CORRECTLY_CONFIGURED_FUSES.value, lectricus.Classification.NO_KNOWN_VULNERABILITIES.value]:
continue
vulnerable_apps += len(apps)
subtitle = wx.StaticText(frame, label=f"Number of vulnerable applications: {vulnerable_apps}")
subtitle.SetPosition((-1, title.GetPosition()[1] + 20))
subtitle.Center(wx.HORIZONTAL)
position = title.GetPosition()[1] + 50
id = wx.NewIdRef()
list = wx.ListCtrl(frame, id, (20, position), style=wx.LC_REPORT | wx.BORDER_SUNKEN)
list.SetSize((850, 600))
list.Center(wx.HORIZONTAL)
list.InsertColumn(0, "Path", width=350)
list.InsertColumn(1, "Vulnerability", width=250)
list.InsertColumn(2, "Electron Version", width=100)
list.InsertColumn(3, "Chromium Version", width=130)
# Build bit map bundle, and handle demo mode if applicable
app_icon_cache = {
# "app": {
# "bundle": wx.BitmapBundle,
# "raw": str
#}
}
for category, apps in self.vulnerable_apps.items():
for app in apps:
# Mask true application in demo mode
if self.demo_mode is True and category not in [lectricus.Classification.CORRECTLY_CONFIGURED_FUSES.value, lectricus.Classification.NO_KNOWN_VULNERABILITIES.value]:
_original_app = app["app"]
_new_app = self._randomized_app_name()
app["app"] = _new_app
app["framework"] = app["framework"].replace(_original_app, _new_app)
icon = self._randomize_app_icon()
else:
icon = self._resolve_icon_from_path(app["app"])
if app["app"] not in app_icon_cache:
app_icon_cache[app["app"]] = {
"bundle": wx.BitmapBundle.FromBitmaps([self._icon_to_bitmap(icon), self._icon_to_bitmap(icon, (64, 64))]),
}
list.SetSmallImages([app_icon_cache[app["app"]]["bundle"] for category, apps in self.vulnerable_apps.items() for app in apps])
for category, apps in self.vulnerable_apps.items():
for app in apps:
index = list.InsertItem(list.GetItemCount(), app["app"])
list.SetItemImage(index, list.GetItemCount() - 1)
list.SetItem(index, 1, category)
list.SetItem(index, 2, app["electron_version"])
list.SetItem(index, 3, app["chromium_version"])
# Get position of last item
if list.GetItemCount() == 0:
position = list.GetPosition()[1] + 20
else:
position = list.GetItemRect(list.GetItemCount() - 1).GetBottom() + 20
if position > 600:
position = 600
list.SetSize((-1, position))
position += 90
export_button = wx.Button(frame, label="Export report to file")
export_button.Bind(wx.EVT_BUTTON, self.OnExport)
export_button.SetPosition((-1, position))
export_button.Center(wx.HORIZONTAL)
return_button = wx.Button(frame, label="Return")
return_button.Bind(wx.EVT_BUTTON, lambda e: frame.Destroy())
return_button.SetPosition((-1, export_button.GetPosition()[1] + 30))
return_button.Center(wx.HORIZONTAL)
frame.SetSize((-1, return_button.GetPosition()[1] + 70))
frame.ShowWindowModal()
wx.Yield()
def InitUI(self):
self.SetSize((400, 200))
self.title = wx.StaticText(self, label="Lectricus")
self.title.SetFont(wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.BOLD))
self.title.SetPosition((-1, 10))
self.title.Center(wx.HORIZONTAL)
self.subtitle = wx.StaticText(self, label="Detect misconfigured Electron applications")
self.subtitle.SetPosition((-1, self.title.GetPosition()[1] + 20))
self.subtitle.Center(wx.HORIZONTAL)
# Dropdown to select directory to search for vulnerable applications
self.directory_dropdown = wx.DirPickerCtrl(self, message="Search Directory", path="/Applications")
self.directory_dropdown.SetSize((194, -1))
self.directory_dropdown.SetPosition((-1, self.subtitle.GetPosition()[1] + 30))
self.directory_dropdown.Center(wx.HORIZONTAL)
# Dropdown to configure OS (darwin, win32, linux)
self.os_dropdown = wx.Choice(self, choices=["Search Schema: macOS", "Search Schema: Windows", "Search Schema: Linux"])
self.os_dropdown.SetSize((194, -1))
self.os_dropdown.SetSelection(0)
self.os_dropdown.SetPosition((-1, self.directory_dropdown.GetPosition()[1] + 30))
self.os_dropdown.Center(wx.HORIZONTAL)
# Button to list vulnerable applications
self.list_button = wx.Button(self, label="List vulnerable applications")
self.list_button.Bind(wx.EVT_BUTTON, self.OnList)
self.list_button.SetSize((194, -1))
self.list_button.SetPosition((-1, self.os_dropdown.GetPosition()[1] + 30))
self.list_button.Center(wx.HORIZONTAL)
self.list_button.SetDefault()
# RIPEDA Consulting
self.ripeda = wx.StaticText(self, label=f"Engineered by {lectricus.__author__}")
self.ripeda.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL))
self.ripeda.SetPosition((-1, self.list_button.GetPosition()[1] + 40))
self.ripeda.Center(wx.HORIZONTAL)
self.SetTitle(f"Lectricus v{lectricus.__version__}")
self.Centre()
self.SetSize((-1, self.ripeda.GetPosition()[1] + 60))
self.Show(True)
def main():
app = wx.App()
LectricusFrame(None, style=wx.DEFAULT_FRAME_STYLE & ~(wx.RESIZE_BORDER | wx.MAXIMIZE_BOX))
app.MainLoop()
if __name__ == "__main__":
main()