mvt/mvt/ios/modules/mixed/idstatuscache.py

123 lines
4.3 KiB
Python
Raw Normal View History

2021-07-16 08:05:01 +02:00
# Mobile Verification Toolkit (MVT)
2023-02-08 20:18:16 +01:00
# Copyright (c) 2021-2023 Claudio Guarnieri.
# 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 08:05:01 +02:00
2021-07-30 11:40:09 +02:00
import collections
2022-06-17 22:30:46 +02:00
import logging
import plistlib
from typing import Optional, Union
2021-07-16 08:05:01 +02:00
from mvt.common.utils import convert_mactime_to_iso
2021-07-16 08:05:01 +02:00
2021-08-15 13:14:18 +02:00
from ..base import IOSExtraction
2021-07-16 08:05:01 +02:00
IDSTATUSCACHE_BACKUP_IDS = [
"6b97989189901ceaa4e5be9b7f05fb584120e27b",
]
IDSTATUSCACHE_ROOT_PATHS = [
"private/var/mobile/Library/Preferences/com.apple.identityservices.idstatuscache.plist",
"private/var/mobile/Library/IdentityServices/idstatuscache.plist",
2021-07-16 08:05:01 +02:00
]
2021-11-19 15:27:51 +01:00
2021-07-16 08:05:01 +02:00
class IDStatusCache(IOSExtraction):
"""Extracts Apple Authentication information from idstatuscache.plist"""
def __init__(
self,
2022-08-17 15:52:17 +02:00
file_path: Optional[str] = None,
target_path: Optional[str] = None,
results_path: Optional[str] = None,
fast_mode: bool = False,
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,
fast_mode=fast_mode,
log=log,
results=results,
)
2021-07-16 08:05:01 +02:00
def serialize(self, record: dict) -> Union[dict, list]:
2021-07-16 08:05:01 +02:00
return {
"timestamp": record["isodate"],
"module": self.__class__.__name__,
"event": "lookup",
"data": f"Lookup of {record['user']} within {record['package']} "
f"(Status {record['idstatus']})",
2021-07-16 08:05:01 +02:00
}
2022-06-17 22:30:46 +02:00
def check_indicators(self) -> None:
2021-07-16 08:05:01 +02:00
if not self.indicators:
return
for result in self.results:
2021-08-16 10:50:35 +02:00
if result.get("user", "").startswith("mailto:"):
2021-07-16 08:05:01 +02:00
email = result["user"][7:].strip("'")
2022-01-23 15:01:49 +01:00
ioc = self.indicators.check_email(email)
if ioc:
result["matched_indicator"] = ioc
2021-07-16 08:05:01 +02:00
self.detected.append(result)
continue
2021-08-16 10:50:35 +02:00
if "\\x00\\x00" in result.get("user", ""):
self.log.warning(
"Found an ID Status Cache entry with suspicious patterns: %s",
result.get("user"),
)
2021-07-16 08:05:01 +02:00
self.detected.append(result)
2021-09-14 14:29:04 +02:00
def _extract_idstatuscache_entries(self, file_path):
with open(file_path, "rb") as handle:
file_plist = plistlib.load(handle)
2021-07-16 08:05:01 +02:00
id_status_cache_entries = []
for app in file_plist:
if not isinstance(file_plist[app], dict):
continue
for entry in file_plist[app]:
try:
lookup_date = file_plist[app][entry]["LookupDate"]
id_status = file_plist[app][entry]["IDStatus"]
except KeyError:
continue
id_status_cache_entries.append(
{
"package": app,
"user": entry.replace("\x00", "\\x00"),
"isodate": convert_mactime_to_iso(lookup_date),
"idstatus": id_status,
}
)
entry_counter = collections.Counter(
[entry["user"] for entry in id_status_cache_entries]
)
2021-07-16 08:05:01 +02:00
for entry in id_status_cache_entries:
2021-08-16 10:50:35 +02:00
# Add total count of occurrences to the status cache entry.
2021-07-16 08:05:01 +02:00
entry["occurrences"] = entry_counter[entry["user"]]
self.results.append(entry)
2022-06-17 22:30:46 +02:00
def run(self) -> None:
2021-09-13 20:02:48 +02:00
if self.is_backup:
self._find_ios_database(backup_ids=IDSTATUSCACHE_BACKUP_IDS)
self.log.info("Found IDStatusCache plist at path: %s", self.file_path)
2021-09-14 14:29:04 +02:00
self._extract_idstatuscache_entries(self.file_path)
2021-09-13 20:02:48 +02:00
elif self.is_fs_dump:
for idstatuscache_path in self._get_fs_files_from_patterns(
IDSTATUSCACHE_ROOT_PATHS
):
2021-09-13 20:02:48 +02:00
self.file_path = idstatuscache_path
self.log.info("Found IDStatusCache plist at path: %s", self.file_path)
2021-09-14 14:29:04 +02:00
self._extract_idstatuscache_entries(self.file_path)
2021-11-19 15:27:51 +01:00
self.log.info(
"Extracted a total of %d ID Status Cache entries", len(self.results)
)