|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import TYPE_CHECKING |
| 4 | + |
| 5 | +from dissect.util.ts import webkittimestamp |
| 6 | + |
| 7 | +from dissect.target.helpers.descriptor_extensions import UserRecordDescriptorExtension |
| 8 | +from dissect.target.helpers.record import create_extended_descriptor |
| 9 | +from dissect.target.plugin import export |
| 10 | +from dissect.target.plugins.apps.browser.browser import ( |
| 11 | + GENERIC_COOKIE_FIELDS, |
| 12 | + GENERIC_DOWNLOAD_RECORD_FIELDS, |
| 13 | + GENERIC_EXTENSION_RECORD_FIELDS, |
| 14 | + GENERIC_HISTORY_RECORD_FIELDS, |
| 15 | + GENERIC_PASSWORD_RECORD_FIELDS, |
| 16 | + BrowserPlugin, |
| 17 | +) |
| 18 | +from dissect.target.plugins.apps.browser.chromium import ( |
| 19 | + CHROMIUM_DOWNLOAD_RECORD_FIELDS, |
| 20 | + ChromiumMixin, |
| 21 | +) |
| 22 | + |
| 23 | +if TYPE_CHECKING: |
| 24 | + from collections.abc import Iterator |
| 25 | + |
| 26 | + |
| 27 | +OPERA_EXTENSION_RECORD_FIELDS = [ |
| 28 | + ("boolean", "blacklisted"), |
| 29 | +] |
| 30 | + |
| 31 | + |
| 32 | +class OperaPlugin(ChromiumMixin, BrowserPlugin): |
| 33 | + """Opera (Stable and Opera GX) browser plugin.""" |
| 34 | + |
| 35 | + __namespace__ = "opera" |
| 36 | + |
| 37 | + DIRS = ( |
| 38 | + # Windows (Stable) |
| 39 | + "AppData/Roaming/Opera Software/Opera Stable/Default", |
| 40 | + "AppData/Roaming/Opera Software/Opera Stable/_side_profiles/*/Default", |
| 41 | + "AppData/Local/Opera Software/Opera Stable/Default", |
| 42 | + "AppData/Local/Opera Software/Opera Stable/_side_profiles/*/Default", |
| 43 | + # Windows (GX) |
| 44 | + "AppData/Roaming/Opera Software/Opera GX Stable/Default", |
| 45 | + "AppData/Roaming/Opera Software/Opera GX Stable/_side_profiles/*/Default", |
| 46 | + "AppData/Local/Opera Software/Opera GX Stable/Default", |
| 47 | + "AppData/Local/Opera Software/Opera GX Stable/_side_profiles/*/Default", |
| 48 | + # MacOS (Stable) |
| 49 | + "Library/Application Support/com.operasoftware.Opera/Default", |
| 50 | + "Library/Application Support/com.operasoftware.Opera/_side_profiles/*/Default", |
| 51 | + # MacOS (GX) |
| 52 | + "Library/Application Support/com.operasoftware.OperaGX/_side_profiles/*/Default", |
| 53 | + "Library/Application Support/com.operasoftware.OperaGX/Default", |
| 54 | + ) |
| 55 | + |
| 56 | + BrowserHistoryRecord = create_extended_descriptor([UserRecordDescriptorExtension])( |
| 57 | + "application/browser/opera/history", |
| 58 | + GENERIC_HISTORY_RECORD_FIELDS, |
| 59 | + ) |
| 60 | + |
| 61 | + BrowserCookieRecord = create_extended_descriptor([UserRecordDescriptorExtension])( |
| 62 | + "application/browser/opera/cookie", |
| 63 | + GENERIC_COOKIE_FIELDS, |
| 64 | + ) |
| 65 | + |
| 66 | + BrowserDownloadRecord = create_extended_descriptor([UserRecordDescriptorExtension])( |
| 67 | + "application/browser/opera/download", |
| 68 | + GENERIC_DOWNLOAD_RECORD_FIELDS + CHROMIUM_DOWNLOAD_RECORD_FIELDS, |
| 69 | + ) |
| 70 | + |
| 71 | + BrowserExtensionRecord = create_extended_descriptor([UserRecordDescriptorExtension])( |
| 72 | + "application/browser/opera/extension", |
| 73 | + GENERIC_EXTENSION_RECORD_FIELDS + OPERA_EXTENSION_RECORD_FIELDS, |
| 74 | + ) |
| 75 | + |
| 76 | + BrowserPasswordRecord = create_extended_descriptor([UserRecordDescriptorExtension])( |
| 77 | + "application/browser/opera/password", |
| 78 | + GENERIC_PASSWORD_RECORD_FIELDS, |
| 79 | + ) |
| 80 | + |
| 81 | + @export(record=BrowserHistoryRecord) |
| 82 | + def history(self) -> Iterator[BrowserHistoryRecord]: |
| 83 | + """Return browser history records for Opera (and Opera GX).""" |
| 84 | + yield from super().history("opera") |
| 85 | + |
| 86 | + @export(record=BrowserCookieRecord) |
| 87 | + def cookies(self) -> Iterator[BrowserCookieRecord]: |
| 88 | + """Return browser cookie records for Opera (and Opera GX).""" |
| 89 | + yield from super().cookies("opera") |
| 90 | + |
| 91 | + @export(record=BrowserDownloadRecord) |
| 92 | + def downloads(self) -> Iterator[BrowserDownloadRecord]: |
| 93 | + """Return browser download records for Opera (and Opera GX).""" |
| 94 | + yield from super().downloads("opera") |
| 95 | + |
| 96 | + @export(record=BrowserExtensionRecord) |
| 97 | + def extensions(self) -> Iterator[BrowserExtensionRecord]: |
| 98 | + """Iterates over all installed extensions for Opera (and Opera GX). |
| 99 | +
|
| 100 | + Yields: |
| 101 | +
|
| 102 | + .. code-block:: text |
| 103 | +
|
| 104 | + Records with the following fields: |
| 105 | + blacklisted (boolean): Extension blacklisted by Opera/Opera GX. |
| 106 | + ts_install (datetime): Extension install timestamp. |
| 107 | + ts_update (datetime): Extension update timestamp. |
| 108 | + browser (string): The browser from which the records are generated. |
| 109 | + id (string): Extension unique identifier. |
| 110 | + name (string): Name of the extension. |
| 111 | + short_name (string): Short name of the extension. |
| 112 | + default_title (string): Default title of the extension. |
| 113 | + description (string): Description of the extension. |
| 114 | + version (string): Version of the extension. |
| 115 | + ext_path (path): Relative path of the extension. |
| 116 | + from_webstore (boolean): Extension from webstore. |
| 117 | + permissions (string[]): Permissions of the extension. |
| 118 | + manifest (varint): Version of the extensions' manifest. |
| 119 | + source: (path): The source file of the download record. |
| 120 | + """ |
| 121 | + for user, json_file, content in self._iter_json("Secure Preferences"): |
| 122 | + try: |
| 123 | + extensions = content.get("extensions").get("opsettings") |
| 124 | + for extension_id, extension_data in extensions.items(): |
| 125 | + # Opera includes a bunch of empty (prefilled) blacklisted extensions with only one key called |
| 126 | + # 'blacklist_state'. If no other metadata is present, it's not installed. Filtering based on if |
| 127 | + # the extension itself is blacklisted is a no-go as you can still install blacklisted extensions. |
| 128 | + blacklisted = bool(extension_data.get("blacklist_state", 0)) |
| 129 | + if blacklisted and len(extension_data.keys()) == 1: |
| 130 | + continue |
| 131 | + |
| 132 | + ts_install = extension_data.get("first_install_time") or extension_data.get("install_time") |
| 133 | + ts_update = extension_data.get("last_update_time") |
| 134 | + |
| 135 | + if ts_install: |
| 136 | + ts_install = webkittimestamp(ts_install) |
| 137 | + if ts_update: |
| 138 | + ts_update = webkittimestamp(ts_update) |
| 139 | + |
| 140 | + if ext_path := extension_data.get("path"): |
| 141 | + ext_path = self.target.fs.path(ext_path) |
| 142 | + |
| 143 | + manifest = extension_data.get("manifest") |
| 144 | + if manifest: |
| 145 | + name = manifest.get("name") |
| 146 | + short_name = manifest.get("short_name") |
| 147 | + description = manifest.get("description") |
| 148 | + ext_version = manifest.get("version") |
| 149 | + ext_permissions = manifest.get("permissions") |
| 150 | + manifest_version = manifest.get("manifest_version") |
| 151 | + |
| 152 | + if manifest.get("browser_action"): |
| 153 | + default_title = manifest.get("browser_action").get("default_title") |
| 154 | + else: |
| 155 | + default_title = None |
| 156 | + |
| 157 | + else: |
| 158 | + name = None |
| 159 | + short_name = None |
| 160 | + default_title = None |
| 161 | + description = None |
| 162 | + ext_version = None |
| 163 | + ext_permissions = None |
| 164 | + manifest_version = None |
| 165 | + |
| 166 | + yield self.BrowserExtensionRecord( |
| 167 | + blacklisted=blacklisted, |
| 168 | + ts_install=ts_install, |
| 169 | + ts_update=ts_update, |
| 170 | + browser=self.__namespace__, |
| 171 | + extension_id=extension_id, |
| 172 | + name=name, |
| 173 | + short_name=short_name, |
| 174 | + default_title=default_title, |
| 175 | + description=description, |
| 176 | + version=ext_version, |
| 177 | + ext_path=ext_path, |
| 178 | + from_webstore=extensions.get(extension_id).get("from_webstore"), |
| 179 | + permissions=ext_permissions, |
| 180 | + manifest_version=manifest_version, |
| 181 | + source=json_file, |
| 182 | + _target=self.target, |
| 183 | + _user=user.user, |
| 184 | + ) |
| 185 | + except (AttributeError, KeyError) as e: |
| 186 | + self.target.log.warning("No browser extensions found in: %s", json_file) |
| 187 | + self.target.log.debug("", exc_info=e) |
| 188 | + |
| 189 | + @export(record=BrowserPasswordRecord) |
| 190 | + def passwords(self) -> Iterator[BrowserPasswordRecord]: |
| 191 | + """Return browser password records for Opera (and Opera GX).""" |
| 192 | + yield from super().passwords("opera") |
0 commit comments