-
Notifications
You must be signed in to change notification settings - Fork 71
Add Cellebrite UFDX and UFD loader #1086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6ed446e
add cellebrite loader
JSCU-CNI ff0df9c
fix linter
JSCU-CNI 621fcf2
Apply suggestions from code review
JSCU-CNI ae47083
implement review comments
JSCU-CNI 196aa1f
Merge branch 'main' into feature/add-ufdx-loader
JSCU-CNI 26cdb86
Apply suggestions from code review
JSCU-CNI c45d2fa
Apply suggestions from code review
JSCU-CNI 22fb9fa
Merge branch 'main' into feature/add-ufdx-loader
Schamper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from dataclasses import dataclass | ||
| from pathlib import Path | ||
| from uuid import UUID | ||
|
|
||
| from defusedxml import ElementTree as ET | ||
|
|
||
| from dissect.target.filesystem import LayerFilesystem | ||
| from dissect.target.filesystems.zip import ZipFilesystem | ||
| from dissect.target.helpers import configutil | ||
| from dissect.target.loader import Loader | ||
| from dissect.target.target import Target | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| @dataclass | ||
| class Extraction: | ||
| type: str | None | ||
| path: Path | ||
|
|
||
|
|
||
| @dataclass | ||
| class DeviceInfo: | ||
| vendor: str | ||
| model: str | ||
| fguid: UUID | None = None | ||
| guid: UUID | None = None | ||
| os: str | None = None | ||
|
|
||
|
|
||
| @dataclass | ||
| class Ufdx: | ||
| path: Path | None = None | ||
| evidence: UUID | None = None | ||
| device: DeviceInfo | None = None | ||
| extractions: list[Extraction] | None = None | ||
|
|
||
|
|
||
| @dataclass | ||
| class Dump: | ||
| type: str | ||
| path: Path | ||
|
|
||
|
|
||
| @dataclass | ||
| class Keychain: | ||
| type: str | ||
| path: Path | ||
|
|
||
|
|
||
| @dataclass | ||
| class Ufd: | ||
| path: Path | ||
| device: DeviceInfo | ||
| dumps: list[Dump] | None = None | ||
|
|
||
|
|
||
| class CellebriteLoader(Loader): | ||
| """Load Cellebrite UFED exports (``.ufdx`` and ``.ufd``). | ||
|
|
||
| References: | ||
| - https://corp.digitalcorpora.org/corpora/mobile | ||
| """ | ||
|
|
||
| def __init__(self, path: Path, **kwargs): | ||
| super().__init__(path) | ||
|
|
||
| self.ufdx = None | ||
| self.ufd = [] | ||
| self.ffs = None | ||
|
|
||
| # Parse xml to find .ufd path | ||
| if path.suffix == ".ufdx": | ||
| try: | ||
| tree = ET.fromstring(path.read_text()) | ||
|
|
||
| self.ufdx = Ufdx( | ||
| path=path, | ||
| evidence=tree.get("EvidenceID"), | ||
| device=DeviceInfo(**{k.lower(): v for k, v in tree.find("DeviceInfo").attrib.items()}), | ||
| extractions=[], | ||
| ) | ||
|
|
||
| base_path = path.resolve().parent | ||
| for extraction in tree.findall("Extractions/Extraction"): | ||
| self.ufdx.extractions.append( | ||
| Extraction( | ||
| type=extraction.get("TransferType"), | ||
| path=base_path.joinpath(extraction.get("Path").replace("\\", "/")), | ||
| ) | ||
| ) | ||
|
|
||
| except ET.ParseError as e: | ||
| raise ValueError(f"Invalid XML in {path}: {str(e)}") | ||
|
|
||
| elif path.suffix == ".ufd": | ||
| self.ufdx = Ufdx(extractions=[Extraction(type=None, path=path.resolve())]) | ||
|
|
||
| else: | ||
| raise ValueError(f"Unknown suffix {path.suffix} for {path}") | ||
|
|
||
| # Not implemented: parse ufd ini to find ffs, could replace ``Extraction()`` with ``Ufd()``. | ||
|
|
||
| for extraction in self.ufdx.extractions: | ||
| if not extraction.path.is_file(): | ||
| log.warning("Extraction %s does not exist", extraction.path) | ||
| continue | ||
|
|
||
| config = configutil.parse(extraction.path, hint="ini") | ||
| device = {k.lower(): v for k, v in config.get("DeviceInfo").items()} | ||
| device["model"] += f" ({device['devicemodel']})" | ||
| del device["devicemodel"] | ||
|
|
||
| ufd = Ufd( | ||
| path=extraction.path, | ||
| device=DeviceInfo(**device), | ||
| dumps=[], | ||
| ) | ||
|
|
||
| for type, dump in config.get("Dumps").items(): | ||
| dump_path = ufd.path.resolve().parent.joinpath(dump) | ||
| ufd.dumps.append(Dump(type=type, path=dump_path)) | ||
|
|
||
| self.ufd.append(ufd) | ||
|
|
||
| @staticmethod | ||
| def detect(path: Path) -> bool: | ||
| return path.is_file() and path.suffix in [".ufdx", ".ufd"] | ||
|
|
||
| def map(self, target: Target) -> None: | ||
| for ufd in self.ufd: | ||
| for dump in ufd.dumps: | ||
| # Keychain dumps are inside the same FFS zip file, so we let the CellebriteFilesystem handle mounting | ||
| # that so we prevent an extra file handle being opened. | ||
| if dump.type != "FileDump": | ||
| log.warning("Ignoring Cellebrite dump %s of type %s", dump.path.name, dump.type) | ||
| continue | ||
|
|
||
| if (size := dump.path.lstat().st_size) > 1_000_000_000: | ||
| log.warning( | ||
| "Cellebrite filesystem dump %s is %s GB, this might take a while..", | ||
| dump.path.name, | ||
| size // 1024 // 1024 // 1024, | ||
| ) | ||
|
|
||
| target.filesystems.add(CellebriteFilesystem(dump.path)) | ||
|
|
||
|
|
||
| class CellebriteFilesystem(LayerFilesystem): | ||
| """Cellebrite ``FileDump`` filesystem implementation.""" | ||
|
|
||
| __type__ = "cellebrite" | ||
|
|
||
| def __init__(self, path: Path, base: str | None = None, **kwargs): | ||
| super().__init__(**kwargs) | ||
| self.source = path | ||
|
|
||
| if path.suffix == ".zip": | ||
| fs = ZipFilesystem(path.open("rb"), base=base) | ||
| else: | ||
| raise ValueError(f"Unsupported Cellebrite dump type {path.name}") | ||
|
|
||
| # We add the full file system from ``/filesystem1`` as a layer to the root ``/`` and | ||
| # mount found extras and extraction metadata, such as keychain dumps to folders in ``/$fs$/fs0``, | ||
| # to keep this information accessible for device specific plugins. | ||
| for fs_dir, dest in [ | ||
| ("/filesystem1", "/"), | ||
| ("/extra", "/$fs$/fs0/extra"), | ||
| ("/metadata1", "/$fs$/fs0/metadata"), | ||
| ]: | ||
| if fs.path(fs_dir).exists(): | ||
| # Mounts the ZipFilesystem at the provided fs_dir base. This way we can | ||
| # (ab)use a single zip file handle for multiple filesystem layers. | ||
| self.append_layer().mount(dest, fs, base=fs_dir) | ||
|
|
||
| def __repr__(self) -> str: | ||
| return f"<{self.__class__.__name__} {self.source}>" | ||
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/_data/loaders/cellebrite/EXTRACTION_FFS 01/EXTRACTION_FFS.ufd
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
tests/_data/loaders/cellebrite/EXTRACTION_FFS 01/EXTRACTION_FFS.zip
Git LFS file not shown
Git LFS file not shown
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.