-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load Android device timezone info and add additional file modificatio…
…n logs (#567) * Use local timestamp for Files module timeline. Most other Android timestamps appear to be local time. The results timeline is more useful if all the timestamps are consistent. I would prefer to use UTC, but that would mean converting all the other timestamps to UTC as well. We probably do not have sufficient information to do that accurately, especially if the device is moving between timezones.. * Add file timestamp modules to add logs into timeline * Handle case were we cannot load device timezone * Fix crash if prop file does not exist * Move _get_file_modification_time to BugReportModule * Add backport for timezone and fix Tombstone module to use local time. * Fix import for backported Zoneinfo * Fix ruff error
- Loading branch information
Showing
13 changed files
with
260 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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,43 @@ | ||
# Mobile Verification Toolkit (MVT) | ||
# Copyright (c) 2021-2023 The MVT Authors. | ||
# Use of this software is governed by the MVT License 1.1 that can be found at | ||
# https://license.mvt.re/1.1/ | ||
from typing import Union | ||
|
||
from .artifact import AndroidArtifact | ||
|
||
|
||
class FileTimestampsArtifact(AndroidArtifact): | ||
def serialize(self, record: dict) -> Union[dict, list]: | ||
records = [] | ||
|
||
for ts in set( | ||
[ | ||
record.get("access_time"), | ||
record.get("changed_time"), | ||
record.get("modified_time"), | ||
] | ||
): | ||
if not ts: | ||
continue | ||
|
||
macb = "" | ||
macb += "M" if ts == record.get("modified_time") else "-" | ||
macb += "A" if ts == record.get("access_time") else "-" | ||
macb += "C" if ts == record.get("changed_time") else "-" | ||
macb += "-" | ||
|
||
msg = record["path"] | ||
if record.get("context"): | ||
msg += f" ({record['context']})" | ||
|
||
records.append( | ||
{ | ||
"timestamp": ts, | ||
"module": self.__class__.__name__, | ||
"event": macb, | ||
"data": msg, | ||
} | ||
) | ||
|
||
return records |
This file contains 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 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 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 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 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,65 @@ | ||
# Mobile Verification Toolkit (MVT) | ||
# Copyright (c) 2021-2023 The MVT Authors. | ||
# Use of this software is governed by the MVT License 1.1 that can be found at | ||
# https://license.mvt.re/1.1/ | ||
|
||
import os | ||
import datetime | ||
import logging | ||
from typing import Optional | ||
|
||
from mvt.common.utils import convert_datetime_to_iso | ||
from .base import AndroidQFModule | ||
from mvt.android.artifacts.file_timestamps import FileTimestampsArtifact | ||
|
||
|
||
class LogsFileTimestamps(FileTimestampsArtifact, AndroidQFModule): | ||
"""This module extracts records from battery daily updates.""" | ||
|
||
slug = "logfile_timestamps" | ||
|
||
def __init__( | ||
self, | ||
file_path: Optional[str] = None, | ||
target_path: Optional[str] = None, | ||
results_path: Optional[str] = None, | ||
module_options: Optional[dict] = None, | ||
log: logging.Logger = logging.getLogger(__name__), | ||
results: Optional[list] = None, | ||
) -> None: | ||
super().__init__( | ||
file_path=file_path, | ||
target_path=target_path, | ||
results_path=results_path, | ||
module_options=module_options, | ||
log=log, | ||
results=results, | ||
) | ||
|
||
def _get_file_modification_time(self, file_path: str) -> dict: | ||
if self.archive: | ||
file_timetuple = self.archive.getinfo(file_path).date_time | ||
return datetime.datetime(*file_timetuple) | ||
else: | ||
file_stat = os.stat(os.path.join(self.parent_path, file_path)) | ||
return datetime.datetime.fromtimestamp(file_stat.st_mtime) | ||
|
||
def run(self) -> None: | ||
filesystem_files = self._get_files_by_pattern("*/logs/*") | ||
|
||
self.results = [] | ||
for file in filesystem_files: | ||
# Only the modification time is available in the zip file metadata. | ||
# The timezone is the local timezone of the machine the phone. | ||
modification_time = self._get_file_modification_time(file) | ||
self.results.append( | ||
{ | ||
"path": file, | ||
"modified_time": convert_datetime_to_iso(modification_time), | ||
} | ||
) | ||
|
||
self.log.info( | ||
"Extracted a total of %d filesystem timestamps from AndroidQF logs directory.", | ||
len(self.results), | ||
) |
This file contains 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 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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
import fnmatch | ||
import logging | ||
import os | ||
|
||
from typing import List, Optional | ||
from zipfile import ZipFile | ||
|
||
|
This file contains 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,55 @@ | ||
# Mobile Verification Toolkit (MVT) | ||
# Copyright (c) 2021-2023 The MVT Authors. | ||
# Use of this software is governed by the MVT License 1.1 that can be found at | ||
# https://license.mvt.re/1.1/ | ||
|
||
import logging | ||
from typing import Optional | ||
|
||
from mvt.common.utils import convert_datetime_to_iso | ||
from .base import BugReportModule | ||
from mvt.android.artifacts.file_timestamps import FileTimestampsArtifact | ||
|
||
|
||
class BugReportTimestamps(FileTimestampsArtifact, BugReportModule): | ||
"""This module extracts records from battery daily updates.""" | ||
|
||
slug = "bugreport_timestamps" | ||
|
||
def __init__( | ||
self, | ||
file_path: Optional[str] = None, | ||
target_path: Optional[str] = None, | ||
results_path: Optional[str] = None, | ||
module_options: Optional[dict] = None, | ||
log: logging.Logger = logging.getLogger(__name__), | ||
results: Optional[list] = None, | ||
) -> None: | ||
super().__init__( | ||
file_path=file_path, | ||
target_path=target_path, | ||
results_path=results_path, | ||
module_options=module_options, | ||
log=log, | ||
results=results, | ||
) | ||
|
||
def run(self) -> None: | ||
filesystem_files = self._get_files_by_pattern("FS/*") | ||
|
||
self.results = [] | ||
for file in filesystem_files: | ||
# Only the modification time is available in the zip file metadata. | ||
# The timezone is the local timezone of the machine the phone. | ||
modification_time = self._get_file_modification_time(file) | ||
self.results.append( | ||
{ | ||
"path": file, | ||
"modified_time": convert_datetime_to_iso(modification_time), | ||
} | ||
) | ||
|
||
self.log.info( | ||
"Extracted a total of %d filesystem timestamps from bugreport.", | ||
len(self.results), | ||
) |
This file contains 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 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 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