2021-07-16 06:05:01 +00:00
|
|
|
# Mobile Verification Toolkit (MVT)
|
2021-08-01 19:11:08 +00:00
|
|
|
# Copyright (c) 2021 The MVT Project Authors.
|
|
|
|
# Use of this software is governed by the MVT License 1.1 that can be found at
|
|
|
|
# https://license.mvt.re/1.1/
|
2021-07-16 06:05:01 +00:00
|
|
|
|
2021-07-30 09:40:09 +00:00
|
|
|
import datetime
|
2021-07-16 06:05:01 +00:00
|
|
|
import io
|
|
|
|
import os
|
2021-08-14 16:50:11 +00:00
|
|
|
import plistlib
|
2021-07-16 06:05:01 +00:00
|
|
|
import sqlite3
|
2021-07-30 09:40:09 +00:00
|
|
|
|
2021-08-01 17:50:25 +00:00
|
|
|
from mvt.common.module import DatabaseNotFoundError
|
2021-08-01 17:53:20 +00:00
|
|
|
from mvt.common.utils import convert_timestamp_to_iso
|
2021-07-16 06:05:01 +00:00
|
|
|
|
2021-08-15 11:14:18 +00:00
|
|
|
from ..base import IOSExtraction
|
2021-07-16 06:05:01 +00:00
|
|
|
|
2021-07-30 09:40:09 +00:00
|
|
|
|
2021-07-16 06:05:01 +00:00
|
|
|
class Manifest(IOSExtraction):
|
|
|
|
"""This module extracts information from a backup Manifest.db file."""
|
|
|
|
|
|
|
|
def __init__(self, file_path=None, base_folder=None, output_folder=None,
|
|
|
|
fast_mode=False, log=None, results=[]):
|
|
|
|
super().__init__(file_path=file_path, base_folder=base_folder,
|
|
|
|
output_folder=output_folder, fast_mode=fast_mode,
|
|
|
|
log=log, results=results)
|
|
|
|
|
|
|
|
def _get_key(self, dictionary, key):
|
2021-08-15 17:07:45 +00:00
|
|
|
"""Unserialized plist objects can have keys which are str or byte types
|
2021-07-16 06:05:01 +00:00
|
|
|
This is a helper to try fetch a key as both a byte or string type.
|
2021-09-10 13:18:13 +00:00
|
|
|
|
2021-11-19 14:27:51 +00:00
|
|
|
:param dictionary:
|
|
|
|
:param key:
|
2021-09-10 13:18:13 +00:00
|
|
|
|
2021-07-16 06:05:01 +00:00
|
|
|
"""
|
|
|
|
return dictionary.get(key.encode("utf-8"), None) or dictionary.get(key, None)
|
|
|
|
|
2021-08-28 10:33:27 +00:00
|
|
|
@staticmethod
|
|
|
|
def _convert_timestamp(timestamp_or_unix_time_int):
|
2021-08-15 17:07:45 +00:00
|
|
|
"""Older iOS versions stored the manifest times as unix timestamps.
|
2021-09-10 13:18:13 +00:00
|
|
|
|
2021-11-19 14:27:51 +00:00
|
|
|
:param timestamp_or_unix_time_int:
|
2021-09-10 13:18:13 +00:00
|
|
|
|
2021-08-15 17:07:45 +00:00
|
|
|
"""
|
2021-07-16 06:05:01 +00:00
|
|
|
if isinstance(timestamp_or_unix_time_int, datetime.datetime):
|
|
|
|
return convert_timestamp_to_iso(timestamp_or_unix_time_int)
|
|
|
|
else:
|
|
|
|
timestamp = datetime.datetime.utcfromtimestamp(timestamp_or_unix_time_int)
|
|
|
|
return convert_timestamp_to_iso(timestamp)
|
|
|
|
|
|
|
|
def serialize(self, record):
|
|
|
|
records = []
|
2021-08-15 17:07:45 +00:00
|
|
|
if "modified" not in record or "status_changed" not in record:
|
2021-07-26 23:23:22 +00:00
|
|
|
return
|
2021-08-15 17:07:45 +00:00
|
|
|
for ts in set([record["created"], record["modified"], record["status_changed"]]):
|
2021-07-16 06:05:01 +00:00
|
|
|
macb = ""
|
|
|
|
macb += "M" if ts == record["modified"] else "-"
|
|
|
|
macb += "-"
|
2021-08-15 17:07:45 +00:00
|
|
|
macb += "C" if ts == record["status_changed"] else "-"
|
2021-07-16 06:05:01 +00:00
|
|
|
macb += "B" if ts == record["created"] else "-"
|
|
|
|
|
|
|
|
records.append({
|
|
|
|
"timestamp": ts,
|
|
|
|
"module": self.__class__.__name__,
|
|
|
|
"event": macb,
|
2021-08-15 17:07:45 +00:00
|
|
|
"data": f"{record['relative_path']} - {record['domain']}"
|
2021-07-16 06:05:01 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return records
|
|
|
|
|
|
|
|
def check_indicators(self):
|
|
|
|
if not self.indicators:
|
|
|
|
return
|
|
|
|
|
|
|
|
for result in self.results:
|
2021-11-19 14:27:51 +00:00
|
|
|
if "relative_path" not in result:
|
2021-07-16 06:05:01 +00:00
|
|
|
continue
|
2021-08-15 17:07:45 +00:00
|
|
|
if not result["relative_path"]:
|
2021-07-16 06:05:01 +00:00
|
|
|
continue
|
|
|
|
|
2021-07-26 23:23:22 +00:00
|
|
|
if result["domain"]:
|
2021-08-15 17:07:45 +00:00
|
|
|
if os.path.basename(result["relative_path"]) == "com.apple.CrashReporter.plist" and result["domain"] == "RootDomain":
|
2021-07-26 23:23:22 +00:00
|
|
|
self.log.warning("Found a potentially suspicious \"com.apple.CrashReporter.plist\" file created in RootDomain")
|
|
|
|
self.detected.append(result)
|
|
|
|
continue
|
|
|
|
|
2022-01-18 14:50:31 +00:00
|
|
|
if self.indicators.check_file_path("/" + result["relative_path"]):
|
2021-08-15 17:07:45 +00:00
|
|
|
self.log.warning("Found a known malicious file at path: %s", result["relative_path"])
|
2021-07-16 06:05:01 +00:00
|
|
|
self.detected.append(result)
|
|
|
|
continue
|
|
|
|
|
2021-08-15 17:07:45 +00:00
|
|
|
relPath = result["relative_path"].lower()
|
2021-07-16 06:05:01 +00:00
|
|
|
for ioc in self.indicators.ioc_domains:
|
|
|
|
if ioc.lower() in relPath:
|
|
|
|
self.log.warning("Found mention of domain \"%s\" in a backup file with path: %s",
|
|
|
|
ioc, relPath)
|
|
|
|
self.detected.append(result)
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
manifest_db_path = os.path.join(self.base_folder, "Manifest.db")
|
|
|
|
if not os.path.isfile(manifest_db_path):
|
2021-09-01 11:41:21 +00:00
|
|
|
raise DatabaseNotFoundError("unable to find backup's Manifest.db")
|
2021-07-16 06:05:01 +00:00
|
|
|
|
|
|
|
self.log.info("Found Manifest.db database at path: %s", manifest_db_path)
|
|
|
|
|
|
|
|
conn = sqlite3.connect(manifest_db_path)
|
|
|
|
cur = conn.cursor()
|
|
|
|
|
|
|
|
cur.execute("SELECT * FROM Files;")
|
|
|
|
names = [description[0] for description in cur.description]
|
|
|
|
|
|
|
|
for file_entry in cur:
|
2021-08-15 17:05:15 +00:00
|
|
|
file_data = {}
|
2021-07-16 06:05:01 +00:00
|
|
|
for index, value in enumerate(file_entry):
|
|
|
|
file_data[names[index]] = value
|
|
|
|
|
|
|
|
cleaned_metadata = {
|
2021-08-15 17:07:45 +00:00
|
|
|
"file_id": file_data["fileID"],
|
2021-07-16 06:05:01 +00:00
|
|
|
"domain": file_data["domain"],
|
2021-08-15 17:07:45 +00:00
|
|
|
"relative_path": file_data["relativePath"],
|
2021-07-16 06:05:01 +00:00
|
|
|
"flags": file_data["flags"],
|
|
|
|
"created": "",
|
|
|
|
}
|
|
|
|
|
|
|
|
if file_data["file"]:
|
|
|
|
try:
|
2021-08-14 16:50:11 +00:00
|
|
|
file_plist = plistlib.load(io.BytesIO(file_data["file"]))
|
2021-07-16 06:05:01 +00:00
|
|
|
file_metadata = self._get_key(file_plist, "$objects")[1]
|
|
|
|
cleaned_metadata.update({
|
|
|
|
"created": self._convert_timestamp(self._get_key(file_metadata, "Birth")),
|
|
|
|
"modified": self._convert_timestamp(self._get_key(file_metadata, "LastModified")),
|
2021-08-15 17:07:45 +00:00
|
|
|
"status_changed": self._convert_timestamp(self._get_key(file_metadata, "LastStatusChange")),
|
2021-07-16 06:05:01 +00:00
|
|
|
"mode": oct(self._get_key(file_metadata, "Mode")),
|
|
|
|
"owner": self._get_key(file_metadata, "UserID"),
|
|
|
|
"size": self._get_key(file_metadata, "Size"),
|
|
|
|
})
|
2021-11-19 14:27:51 +00:00
|
|
|
except Exception:
|
2021-08-20 15:15:35 +00:00
|
|
|
self.log.exception("Error reading manifest file metadata for file with ID %s and relative path %s",
|
|
|
|
file_data["fileID"], file_data["relativePath"])
|
2021-07-16 06:05:01 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
self.results.append(cleaned_metadata)
|
|
|
|
|
|
|
|
cur.close()
|
|
|
|
conn.close()
|
|
|
|
|
|
|
|
self.log.info("Extracted a total of %d file metadata items", len(self.results))
|