mirror of
https://github.com/mvt-project/mvt.git
synced 2026-12-01 08:03:56 +01:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0c1a2ac002 | ||
|
|
1087975d29 | ||
|
|
92683ef788 | ||
|
|
a02c7d8db0 |
No files matched your search
+2
-2
@@ -47,8 +47,8 @@ RUN apt-get update \
|
||||
&& mvt-ios --help > /dev/null
|
||||
|
||||
# Installing ABE
|
||||
ADD --checksum=sha256:3f42f011b6b567431ab8cd9d4ae5c36cf19a82da835168718d1735d995a3ba1a \
|
||||
https://github.com/nelenkov/android-backup-extractor/releases/download/v1.2.0/abe-v1.2.0.jar /opt/abe/abe.jar
|
||||
ADD --checksum=sha256:a20e07f8b2ea47620aff0267f230c3f1f495f097081fd709eec51cf2a2e11632 \
|
||||
https://github.com/nelenkov/android-backup-extractor/releases/download/master-20221109063121-8fdfc5e/abe.jar /opt/abe/abe.jar
|
||||
# Create alias for abe
|
||||
RUN echo 'alias abe="java -jar /opt/abe/abe.jar"' >> ~/.bashrc
|
||||
|
||||
|
||||
+2
-2
@@ -25,8 +25,8 @@ RUN apk add --no-cache --virtual .build-deps gcc musl-dev \
|
||||
&& apk del .build-deps gcc musl-dev && rm -rf ./mvt
|
||||
|
||||
# Installing ABE
|
||||
ADD --checksum=sha256:3f42f011b6b567431ab8cd9d4ae5c36cf19a82da835168718d1735d995a3ba1a \
|
||||
https://github.com/nelenkov/android-backup-extractor/releases/download/v1.2.0/abe-v1.2.0.jar /opt/abe/abe.jar
|
||||
ADD --checksum=sha256:a20e07f8b2ea47620aff0267f230c3f1f495f097081fd709eec51cf2a2e11632 \
|
||||
https://github.com/nelenkov/android-backup-extractor/releases/download/master-20221109063121-8fdfc5e/abe.jar /opt/abe/abe.jar
|
||||
# Create alias for abe
|
||||
RUN echo 'alias abe="java -jar /opt/abe/abe.jar"' >> ~/.bashrc
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
|
||||
# Mobile Verification Toolkit
|
||||
|
||||
|
||||
> [!IMPORTANT]
|
||||
> We recently merged the "v3" branch. This introduced breaking changes. If you relied on mvt output in other scripts They might have broken. More details: https://github.com/mvt-project/mvt/issues/757
|
||||
|
||||
[](https://pypi.org/project/mvt/)
|
||||
[](https://docs.mvt.re/en/latest/?badge=latest)
|
||||
|
||||
@@ -95,9 +95,7 @@ class CmdAndroidCheckAndroidQF(Command):
|
||||
elif os.path.isfile(self.target_path):
|
||||
self.__format = "zip"
|
||||
self.__zip = zipfile.ZipFile(self.target_path)
|
||||
self.__files = [
|
||||
entry.filename for entry in self.__zip.infolist() if not entry.is_dir()
|
||||
]
|
||||
self.__files = self.__zip.namelist()
|
||||
|
||||
self._load_acquisition_context()
|
||||
|
||||
@@ -261,7 +259,6 @@ class CmdAndroidCheckAndroidQF(Command):
|
||||
hashes=self.hashes,
|
||||
sub_command=True,
|
||||
custom_modules=self.custom_modules,
|
||||
module_name=self.module_name,
|
||||
)
|
||||
cmd.from_zip(bugreport)
|
||||
cmd.run()
|
||||
@@ -293,7 +290,6 @@ class CmdAndroidCheckAndroidQF(Command):
|
||||
hashes=self.hashes,
|
||||
sub_command=True,
|
||||
custom_modules=self.custom_modules,
|
||||
module_name=self.module_name,
|
||||
)
|
||||
try:
|
||||
cmd.from_ab(backup)
|
||||
@@ -380,7 +376,6 @@ class CmdAndroidCheckAndroidQF(Command):
|
||||
hashes=self.hashes,
|
||||
sub_command=True,
|
||||
custom_modules=self.custom_modules,
|
||||
module_name=self.module_name,
|
||||
)
|
||||
cmd.run()
|
||||
|
||||
|
||||
@@ -5,9 +5,8 @@
|
||||
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
import time
|
||||
from typing import Optional, TypeGuard
|
||||
from typing import Optional
|
||||
|
||||
from rich.progress import track
|
||||
|
||||
@@ -25,12 +24,6 @@ from mvt.common.virustotal import VTNoKey, VTQuotaExceeded, virustotal_lookup
|
||||
from .base import AndroidQFModule
|
||||
|
||||
|
||||
def _is_sha256(value: object) -> TypeGuard[str]:
|
||||
return (
|
||||
isinstance(value, str) and re.fullmatch(r"[0-9a-fA-F]{64}", value) is not None
|
||||
)
|
||||
|
||||
|
||||
class AQFPackages(AndroidQFModule):
|
||||
"""This module examines the installed packages in packages.json"""
|
||||
|
||||
@@ -104,7 +97,9 @@ class AQFPackages(AndroidQFModule):
|
||||
self._check_exact_indicators(result)
|
||||
|
||||
if self.module_options.get("virustotal", False):
|
||||
self.check_virustotal(delay=self.module_options.get("virustotal_delay", 0))
|
||||
self.check_virustotal(
|
||||
delay=self.module_options.get("virustotal_delay", 0)
|
||||
)
|
||||
|
||||
def _check_exact_indicators(self, result: ModuleAtomicResult) -> None:
|
||||
"""Check exact matches independently of package heuristics."""
|
||||
@@ -124,20 +119,16 @@ class AQFPackages(AndroidQFModule):
|
||||
|
||||
for package_file in package_files:
|
||||
if not isinstance(package_file, dict):
|
||||
self.log.warning(
|
||||
"Invalid file metadata for package %s", result.get("name")
|
||||
)
|
||||
self.log.warning("Invalid file metadata for package %s", result.get("name"))
|
||||
continue
|
||||
file_hash = package_file.get("sha256")
|
||||
if _is_sha256(file_hash):
|
||||
ioc_match = self.indicators.check_file_hash(file_hash)
|
||||
if ioc_match:
|
||||
self.alertstore.critical(
|
||||
ioc_match.message, "", result, matched_indicator=ioc_match.ioc
|
||||
)
|
||||
elif file_hash not in (None, ""):
|
||||
self.log.warning(
|
||||
"Invalid SHA-256 metadata for package %s", result.get("name")
|
||||
if file_hash is not None and not isinstance(file_hash, str):
|
||||
self.log.warning("Invalid SHA-256 metadata for package %s", result.get("name"))
|
||||
file_hash = None
|
||||
ioc_match = self.indicators.check_file_hash(file_hash or "")
|
||||
if ioc_match:
|
||||
self.alertstore.critical(
|
||||
ioc_match.message, "", result, matched_indicator=ioc_match.ioc
|
||||
)
|
||||
|
||||
if "certificate" not in package_file:
|
||||
@@ -145,9 +136,7 @@ class AQFPackages(AndroidQFModule):
|
||||
|
||||
certificate = package_file["certificate"]
|
||||
if not isinstance(certificate, dict):
|
||||
self.log.warning(
|
||||
"Invalid certificate metadata for package %s", result.get("name")
|
||||
)
|
||||
self.log.warning("Invalid certificate metadata for package %s", result.get("name"))
|
||||
continue
|
||||
|
||||
# The keys generated by AndroidQF have a leading uppercase character.
|
||||
@@ -156,11 +145,12 @@ class AQFPackages(AndroidQFModule):
|
||||
if not isinstance(certificate_hash, str):
|
||||
self.log.warning(
|
||||
"Missing or invalid %s certificate metadata for package %s",
|
||||
hash_type,
|
||||
result.get("name"),
|
||||
hash_type, result.get("name"),
|
||||
)
|
||||
continue
|
||||
ioc_match = self.indicators.check_app_certificate_hash(certificate_hash)
|
||||
ioc_match = self.indicators.check_app_certificate_hash(
|
||||
certificate_hash
|
||||
)
|
||||
if ioc_match:
|
||||
self.alertstore.critical(
|
||||
ioc_match.message,
|
||||
@@ -180,7 +170,7 @@ class AQFPackages(AndroidQFModule):
|
||||
|
||||
for package_file in package.get("files", []):
|
||||
file_hash = package_file.get("sha256")
|
||||
if not _is_sha256(file_hash):
|
||||
if not file_hash:
|
||||
continue
|
||||
|
||||
files_by_hash.setdefault(file_hash, []).append((package, package_file))
|
||||
|
||||
@@ -34,9 +34,7 @@ class AQFProcesses(ProcessesArtifact, AndroidQFModule):
|
||||
)
|
||||
|
||||
def run(self) -> None:
|
||||
ps_files = self._get_files_by_pattern(
|
||||
"*/processes.txt"
|
||||
) or self._get_files_by_pattern("*/ps.txt")
|
||||
ps_files = self._get_files_by_pattern("*/ps.txt")
|
||||
if not ps_files:
|
||||
return
|
||||
|
||||
|
||||
@@ -46,22 +46,8 @@ class AndroidQFModule(MVTModule):
|
||||
self.archive = archive
|
||||
self.files = files
|
||||
|
||||
def _get_files_by_pattern(self, pattern: str) -> List[str]:
|
||||
pattern = pattern.replace("\\", "/")
|
||||
patterns = [pattern]
|
||||
# ZIPs may store artifacts at their root, without the acquisition
|
||||
# directory prefix present in paths collected by from_dir().
|
||||
if pattern.startswith("*/"):
|
||||
patterns.append(pattern[2:])
|
||||
|
||||
return [
|
||||
file_path
|
||||
for file_path in self.files
|
||||
if any(
|
||||
fnmatch.fnmatch(file_path.replace("\\", "/"), candidate)
|
||||
for candidate in patterns
|
||||
)
|
||||
]
|
||||
def _get_files_by_pattern(self, pattern: str):
|
||||
return fnmatch.filter(self.files, pattern)
|
||||
|
||||
def _get_device_timezone(self):
|
||||
"""
|
||||
|
||||
@@ -9,10 +9,8 @@ import logging
|
||||
import os
|
||||
import re
|
||||
import shlex
|
||||
import stat
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Optional, Tuple
|
||||
|
||||
import requests
|
||||
@@ -530,20 +528,6 @@ class IndicatorsUpdates:
|
||||
|
||||
return yaml.safe_load(res.content)
|
||||
|
||||
@staticmethod
|
||||
def _ioc_file_name(ioc_url: str) -> str:
|
||||
return ioc_url.split("://", 1)[-1].replace("/", "_")
|
||||
|
||||
@staticmethod
|
||||
def _cached_file_id(path: Path) -> Optional[tuple[int, int]]:
|
||||
try:
|
||||
info = path.stat()
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
if stat.S_ISREG(info.st_mode):
|
||||
return info.st_dev, info.st_ino
|
||||
return None
|
||||
|
||||
def download_remote_ioc(self, ioc_url: str) -> Optional[str]:
|
||||
try:
|
||||
res = requests.get(ioc_url, timeout=15)
|
||||
@@ -559,7 +543,8 @@ class IndicatorsUpdates:
|
||||
)
|
||||
return None
|
||||
|
||||
ioc_path = os.path.join(MVT_INDICATORS_FOLDER, self._ioc_file_name(ioc_url))
|
||||
clean_file_name = ioc_url.lstrip("https://").replace("/", "_")
|
||||
ioc_path = os.path.join(MVT_INDICATORS_FOLDER, clean_file_name)
|
||||
|
||||
with open(ioc_path, "w", encoding="utf-8") as handle:
|
||||
handle.write(res.text)
|
||||
@@ -576,8 +561,6 @@ class IndicatorsUpdates:
|
||||
if not index:
|
||||
return
|
||||
|
||||
legacy_names: set[str] = set()
|
||||
protected_names: set[str] = set()
|
||||
for ioc in index.get("indicators", []):
|
||||
ioc_type = ioc.get("type", "")
|
||||
|
||||
@@ -599,36 +582,14 @@ class IndicatorsUpdates:
|
||||
)
|
||||
continue
|
||||
|
||||
# Keep every current name, including those of feeds that fail to refresh.
|
||||
protected_names.add(self._ioc_file_name(ioc_url))
|
||||
# Reproduce the old spelling for files already in the cache.
|
||||
legacy_name = ioc_url.lstrip("https://").replace("/", "_")
|
||||
ioc_local_path = self.download_remote_ioc(ioc_url)
|
||||
if not ioc_local_path:
|
||||
protected_names.add(legacy_name)
|
||||
continue
|
||||
|
||||
legacy_names.add(legacy_name)
|
||||
log.info(
|
||||
'Downloaded indicators "%s" to %s', ioc.get("name"), ioc_local_path
|
||||
)
|
||||
|
||||
obsolete_names = legacy_names - protected_names
|
||||
if obsolete_names:
|
||||
cache = Path(MVT_INDICATORS_FOLDER)
|
||||
# Different spellings can refer to the same file on this filesystem.
|
||||
protected_ids = {
|
||||
self._cached_file_id(cache / name)
|
||||
for name in protected_names
|
||||
if Path(name).name == name
|
||||
}
|
||||
for cached_file in cache.iterdir():
|
||||
if cached_file.name not in obsolete_names:
|
||||
continue
|
||||
file_id = self._cached_file_id(cached_file)
|
||||
if file_id is not None and file_id not in protected_ids:
|
||||
cached_file.unlink(missing_ok=True)
|
||||
|
||||
self.set_latest_update()
|
||||
|
||||
def _get_remote_file_latest_commit(
|
||||
|
||||
@@ -57,31 +57,46 @@ class Calls(IOSExtraction):
|
||||
return
|
||||
conn = self._open_sqlite_db(self.file_path)
|
||||
cur = conn.cursor()
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT
|
||||
ZDATE, ZDURATION, ZLOCATION, ZADDRESS, ZSERVICE_PROVIDER
|
||||
FROM ZCALLRECORD;
|
||||
"""
|
||||
)
|
||||
# names = [description[0] for description in cur.description]
|
||||
|
||||
for row in cur:
|
||||
self.results.append(
|
||||
{
|
||||
"isodate": convert_mactime_to_iso(row[0]),
|
||||
"duration": row[1],
|
||||
"location": row[2],
|
||||
"number": (
|
||||
row[3].decode("utf-8")
|
||||
if isinstance(row[3], bytes)
|
||||
else row[3]
|
||||
),
|
||||
"provider": row[4],
|
||||
}
|
||||
try:
|
||||
cur.execute("PRAGMA table_info(ZCALLRECORD);")
|
||||
columns = {column[1].upper() for column in cur}
|
||||
originated_column = "ZORIGINATED" if "ZORIGINATED" in columns else "NULL"
|
||||
answered_column = "ZANSWERED" if "ZANSWERED" in columns else "NULL"
|
||||
cur.execute(
|
||||
f"""
|
||||
SELECT
|
||||
ZDATE, ZDURATION, ZLOCATION, ZADDRESS, ZSERVICE_PROVIDER,
|
||||
{originated_column}, {answered_column}
|
||||
FROM ZCALLRECORD;
|
||||
"""
|
||||
)
|
||||
|
||||
cur.close()
|
||||
conn.close()
|
||||
for (
|
||||
date,
|
||||
duration,
|
||||
location,
|
||||
address,
|
||||
provider,
|
||||
originated,
|
||||
answered,
|
||||
) in cur:
|
||||
self.results.append(
|
||||
{
|
||||
"isodate": convert_mactime_to_iso(date),
|
||||
"duration": duration,
|
||||
"location": location,
|
||||
"number": (
|
||||
address.decode("utf-8")
|
||||
if isinstance(address, bytes)
|
||||
else address
|
||||
),
|
||||
"provider": provider,
|
||||
"originated": originated,
|
||||
"answered": answered,
|
||||
}
|
||||
)
|
||||
finally:
|
||||
cur.close()
|
||||
conn.close()
|
||||
|
||||
self.log.info("Extracted a total of %d calls", len(self.results))
|
||||
@@ -107,7 +107,7 @@ class SafariBrowserState(IOSExtraction):
|
||||
tabs.last_viewed_time,
|
||||
tab_sessions.session_data
|
||||
FROM tabs
|
||||
JOIN tab_sessions ON tabs.uuid = tab_sessions.tab_uuid
|
||||
LEFT JOIN tab_sessions ON tabs.uuid = tab_sessions.tab_uuid
|
||||
ORDER BY tabs.last_viewed_time;
|
||||
"""
|
||||
)
|
||||
@@ -139,7 +139,9 @@ class SafariBrowserState(IOSExtraction):
|
||||
except plistlib.InvalidFileException:
|
||||
pass
|
||||
|
||||
if "SessionHistoryEntries" in session_data.get("SessionHistory", {}):
|
||||
if "SessionHistoryEntries" in session_data.get(
|
||||
"SessionHistory", {}
|
||||
):
|
||||
for session_entry in session_data["SessionHistory"].get(
|
||||
"SessionHistoryEntries"
|
||||
):
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
# Mobile Verification Toolkit (MVT)
|
||||
# Copyright (c) 2026 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 zipfile
|
||||
|
||||
import pytest
|
||||
|
||||
from mvt.android.modules.androidqf.base import AndroidQFModule
|
||||
|
||||
|
||||
@pytest.mark.parametrize("prefix", ["", "./", "acquisition/", "outer/acquisition/"])
|
||||
@pytest.mark.parametrize(
|
||||
"pattern, filename",
|
||||
[
|
||||
("*/packages.json", "packages.json"),
|
||||
("*/getprop.txt", "getprop.txt"),
|
||||
("*/ps.txt", "ps.txt"),
|
||||
("*/settings_*.txt", "settings_global.txt"),
|
||||
("*/files.json", "files.json"),
|
||||
("*/logs/*", "logs/logcat.txt"),
|
||||
("*/mounts.json", "mounts.json"),
|
||||
("*/root_binaries.json", "root_binaries.json"),
|
||||
],
|
||||
)
|
||||
def test_artifact_lookup_preserves_archive_names(tmp_path, prefix, pattern, filename):
|
||||
member = prefix + filename
|
||||
with zipfile.ZipFile(tmp_path / "acquisition.zip", "w") as archive:
|
||||
archive.writestr(member, b"artifact")
|
||||
archive.writestr(prefix + "unrelated.txt", b"unrelated")
|
||||
module = AndroidQFModule()
|
||||
module.from_zip(archive, archive.namelist())
|
||||
|
||||
assert module._get_files_by_pattern(pattern) == [member]
|
||||
assert module._get_file_content(member) == b"artifact"
|
||||
|
||||
|
||||
def test_artifact_lookup_preserves_windows_paths():
|
||||
module = AndroidQFModule()
|
||||
module.from_dir("parent", [r"acquisition\logs\logcat.txt"])
|
||||
|
||||
assert module._get_files_by_pattern("*/logs/*") == [r"acquisition\logs\logcat.txt"]
|
||||
|
||||
|
||||
def test_artifact_lookup_preserves_order_without_duplicates():
|
||||
module = AndroidQFModule()
|
||||
module.files = [
|
||||
"acquisition/settings_global.txt",
|
||||
"settings_secure.txt",
|
||||
"./settings_system.txt",
|
||||
"not_settings_global.txt",
|
||||
"settings_global.txt.bak",
|
||||
]
|
||||
|
||||
assert module._get_files_by_pattern("*/settings_*.txt") == module.files[:3]
|
||||
assert module._get_files_by_pattern("settings_secure.txt") == [
|
||||
"settings_secure.txt"
|
||||
]
|
||||
assert module._get_files_by_pattern("*/missing.txt") == []
|
||||
@@ -115,43 +115,6 @@ class TestAndroidqfPackages:
|
||||
== "31037a27af59d4914906c01ad14a318eee2f3e31d48da8954dca62a99174e3fa"
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"collection, invalid_hash",
|
||||
[
|
||||
("files_md5", "a" * 32),
|
||||
("files_sha1", "a" * 40),
|
||||
("files_sha256", "g" * 64),
|
||||
],
|
||||
)
|
||||
def test_invalid_apk_sha256_preserves_other_matches(
|
||||
self, indicators_factory, collection, invalid_hash
|
||||
):
|
||||
cert_hash = "b" * 64
|
||||
valid_hash = "abcd" * 16
|
||||
module = AQFPackages(
|
||||
results=[
|
||||
{
|
||||
"name": "com.example.app",
|
||||
"installer": "com.android.vending",
|
||||
"files": [
|
||||
{"sha256": invalid_hash, "certificate": {"Sha256": cert_hash}},
|
||||
{"sha256": valid_hash.upper()},
|
||||
],
|
||||
}
|
||||
]
|
||||
)
|
||||
module.indicators = indicators_factory(
|
||||
files_sha256=[valid_hash], app_cert_hashes=[cert_hash]
|
||||
)
|
||||
module.indicators.ioc_collections[0][collection].append(invalid_hash)
|
||||
|
||||
module.check_indicators()
|
||||
|
||||
assert [a.matched_indicator.value for a in module.alertstore.alerts] == [
|
||||
cert_hash,
|
||||
valid_hash,
|
||||
]
|
||||
|
||||
def test_packages_certificate_hash_ioc(self, module, indicators_factory):
|
||||
module.indicators = indicators_factory(
|
||||
app_cert_hashes=[
|
||||
@@ -176,12 +139,10 @@ class TestAndroidqfPackages:
|
||||
def test_virustotal_delays_after_missing_result(self, monkeypatch):
|
||||
lookups = []
|
||||
sleeps = []
|
||||
missing_hash = "a" * 64
|
||||
found_hash = "b" * 64
|
||||
|
||||
def fake_virustotal_lookup(file_hash):
|
||||
lookups.append(file_hash)
|
||||
if file_hash == missing_hash:
|
||||
if file_hash == "missing_hash":
|
||||
return None
|
||||
return {
|
||||
"attributes": {
|
||||
@@ -204,9 +165,8 @@ class TestAndroidqfPackages:
|
||||
"disabled": False,
|
||||
"system": False,
|
||||
"files": [
|
||||
{"path": "/data/app/missing.apk", "sha256": missing_hash},
|
||||
{"path": "/data/app/found.apk", "sha256": found_hash},
|
||||
{"path": "/data/app/invalid.apk", "sha256": "c" * 32},
|
||||
{"path": "/data/app/missing.apk", "sha256": "missing_hash"},
|
||||
{"path": "/data/app/found.apk", "sha256": "found_hash"},
|
||||
],
|
||||
}
|
||||
],
|
||||
@@ -214,7 +174,7 @@ class TestAndroidqfPackages:
|
||||
|
||||
module.check_indicators()
|
||||
|
||||
assert lookups == [missing_hash, found_hash]
|
||||
assert lookups == ["missing_hash", "found_hash"]
|
||||
assert sleeps == [16]
|
||||
assert module.results[0]["files"][1]["virustotal"] == "1/1"
|
||||
assert len(module.alertstore.alerts) == 1
|
||||
@@ -273,16 +233,10 @@ def test_root_package_heuristic_preserves_exact_ioc_checks(
|
||||
def test_root_package_keeps_existing_heuristic_short_circuit(
|
||||
indicators_factory, with_indicators
|
||||
):
|
||||
module = AQFPackages(
|
||||
results=[
|
||||
{
|
||||
"name": "com.topjohnwu.magisk",
|
||||
"installer": "null",
|
||||
"system": False,
|
||||
"files": [],
|
||||
}
|
||||
]
|
||||
)
|
||||
module = AQFPackages(results=[{
|
||||
"name": "com.topjohnwu.magisk", "installer": "null", "system": False,
|
||||
"files": [],
|
||||
}])
|
||||
if with_indicators:
|
||||
module.indicators = indicators_factory(app_ids=["example.unrelated"])
|
||||
module.check_indicators()
|
||||
@@ -306,22 +260,18 @@ def test_root_package_incomplete_metadata_preserves_later_matches(
|
||||
indicators_factory, files, caplog
|
||||
):
|
||||
root_name = "com.topjohnwu.magisk"
|
||||
module = AQFPackages(
|
||||
results=[
|
||||
{"name": root_name, "files": files},
|
||||
{
|
||||
"name": "example.later",
|
||||
"installer": "com.android.vending",
|
||||
"system": False,
|
||||
"files": [
|
||||
{
|
||||
"sha256": "a" * 64,
|
||||
"certificate": {"Sha256": "b" * 64},
|
||||
}
|
||||
],
|
||||
},
|
||||
]
|
||||
)
|
||||
module = AQFPackages(results=[
|
||||
{"name": root_name, "files": files},
|
||||
{
|
||||
"name": "example.later",
|
||||
"installer": "com.android.vending",
|
||||
"system": False,
|
||||
"files": [{
|
||||
"sha256": "a" * 64,
|
||||
"certificate": {"Sha256": "b" * 64},
|
||||
}],
|
||||
},
|
||||
])
|
||||
module.indicators = indicators_factory(
|
||||
app_ids=[root_name, "example.later"],
|
||||
files_sha256=["a" * 64],
|
||||
@@ -332,14 +282,9 @@ def test_root_package_incomplete_metadata_preserves_later_matches(
|
||||
|
||||
matches = [alert for alert in module.alertstore.alerts if alert.matched_indicator]
|
||||
assert {alert.matched_indicator.value for alert in matches} == {
|
||||
root_name,
|
||||
"example.later",
|
||||
"a" * 64,
|
||||
"b" * 64,
|
||||
root_name, "example.later", "a" * 64, "b" * 64,
|
||||
}
|
||||
assert any(
|
||||
"rooting/jailbreaking" in alert.message for alert in module.alertstore.alerts
|
||||
)
|
||||
assert any("rooting/jailbreaking" in alert.message for alert in module.alertstore.alerts)
|
||||
assert "metadata" in caplog.text
|
||||
if isinstance(files, list) and any(
|
||||
isinstance(item, dict)
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
import json
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from mvt.common import indicators, updates
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def updater_and_cache(tmp_path, monkeypatch):
|
||||
cache = tmp_path / "indicators"
|
||||
cache.mkdir()
|
||||
monkeypatch.setattr(updates, "MVT_DATA_FOLDER", str(tmp_path))
|
||||
monkeypatch.setattr(updates, "MVT_INDICATORS_FOLDER", str(cache))
|
||||
monkeypatch.setattr(indicators, "MVT_INDICATORS_FOLDER", str(cache))
|
||||
monkeypatch.setattr(indicators.settings, "STIX2", None)
|
||||
return updates.IndicatorsUpdates(), cache
|
||||
|
||||
|
||||
def _mock_downloads(monkeypatch, updater, responses):
|
||||
monkeypatch.setattr(
|
||||
updater,
|
||||
"get_remote_index",
|
||||
lambda: {"indicators": [{"download_url": url} for url in responses]},
|
||||
)
|
||||
monkeypatch.setattr(updates.requests, "get", lambda url, *, timeout: responses[url])
|
||||
|
||||
|
||||
def _bundle(domain):
|
||||
return json.dumps(
|
||||
{
|
||||
"objects": [
|
||||
{
|
||||
"type": "indicator",
|
||||
"id": "indicator--test",
|
||||
"pattern": f"[domain-name:value = '{domain}']",
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("scheme", ["http", "https"])
|
||||
def test_refresh_retires_legacy_download(scheme, updater_and_cache, monkeypatch):
|
||||
updater, cache = updater_and_cache
|
||||
legacy = cache / "ools.example_iocs.stix2"
|
||||
legacy.write_text(_bundle("retired.example"), encoding="utf-8")
|
||||
unrelated = cache / "other.stix2"
|
||||
unrelated.write_text(_bundle("other.example"), encoding="utf-8")
|
||||
_mock_downloads(
|
||||
monkeypatch,
|
||||
updater,
|
||||
{
|
||||
f"{scheme}://tools.example/iocs.stix2": SimpleNamespace(
|
||||
status_code=200, text=_bundle("current.example")
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
updater.update()
|
||||
updater.update()
|
||||
|
||||
assert not legacy.exists()
|
||||
assert (cache / "tools.example_iocs.stix2").is_file()
|
||||
loaded = indicators.Indicators()
|
||||
loaded.load_indicators_files([])
|
||||
assert {ioc.value for ioc in loaded.get_iocs("domains")} == {
|
||||
"current.example",
|
||||
"other.example",
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("other_host", "status_code", "expected_legacy"),
|
||||
[
|
||||
("ools.example", 200, "other feed"),
|
||||
("ools.example", 503, "cached feed"),
|
||||
("stools.example", 503, "cached feed"),
|
||||
("stools.example", 200, None),
|
||||
],
|
||||
)
|
||||
def test_refresh_handles_legacy_filename_collisions(
|
||||
other_host, status_code, expected_legacy, updater_and_cache, monkeypatch
|
||||
):
|
||||
updater, cache = updater_and_cache
|
||||
legacy = cache / "ools.example_iocs.stix2"
|
||||
legacy.write_text("cached feed", encoding="utf-8")
|
||||
_mock_downloads(
|
||||
monkeypatch,
|
||||
updater,
|
||||
{
|
||||
"https://tools.example/iocs.stix2": SimpleNamespace(
|
||||
status_code=200, text="refreshed feed"
|
||||
),
|
||||
f"https://{other_host}/iocs.stix2": SimpleNamespace(
|
||||
status_code=status_code, text="other feed"
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
updater.update()
|
||||
|
||||
assert (cache / "tools.example_iocs.stix2").read_text(encoding="utf-8") == (
|
||||
"refreshed feed"
|
||||
)
|
||||
if expected_legacy is None:
|
||||
assert not legacy.exists()
|
||||
else:
|
||||
assert legacy.read_text(encoding="utf-8") == expected_legacy
|
||||
|
||||
|
||||
@pytest.mark.parametrize("other_status", [200, 503])
|
||||
def test_refresh_uses_filesystem_case_rules(
|
||||
updater_and_cache, monkeypatch, other_status
|
||||
):
|
||||
updater, cache = updater_and_cache
|
||||
# These are the two paths the previous version wrote, in index order.
|
||||
legacy = cache / "ools.example_IOCs.stix2"
|
||||
other = cache / "ools.example_iocs.stix2"
|
||||
legacy.write_text(_bundle("retired.example"), encoding="utf-8")
|
||||
other.write_text(_bundle("cached-other.example"), encoding="utf-8")
|
||||
shared_file = legacy.samefile(other)
|
||||
_mock_downloads(
|
||||
monkeypatch,
|
||||
updater,
|
||||
{
|
||||
"https://tools.example/IOCs.stix2": SimpleNamespace(
|
||||
status_code=200, text=_bundle("current.example")
|
||||
),
|
||||
"https://ools.example/iocs.stix2": SimpleNamespace(
|
||||
status_code=other_status, text=_bundle("updated-other.example")
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
updater.update()
|
||||
|
||||
assert legacy.exists() == shared_file
|
||||
loaded = indicators.Indicators()
|
||||
loaded.load_indicators_files([])
|
||||
assert {ioc.value for ioc in loaded.get_iocs("domains")} == {
|
||||
"current.example",
|
||||
"updated-other.example" if other_status == 200 else "cached-other.example",
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
# Mobile Verification Toolkit (MVT)
|
||||
# Copyright (c) 2021-2026 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 sqlite3
|
||||
|
||||
import pytest
|
||||
|
||||
from mvt.common.module import run_module
|
||||
from mvt.ios.modules.mixed.calls import Calls
|
||||
|
||||
|
||||
@pytest.mark.parametrize("has_flags", [True, False])
|
||||
def test_calls_reads_optional_call_flags(tmp_path, has_flags):
|
||||
db_path = tmp_path / "CallHistory.storedata"
|
||||
conn = sqlite3.connect(db_path)
|
||||
try:
|
||||
conn.execute(
|
||||
"""
|
||||
CREATE TABLE ZCALLRECORD (
|
||||
ZDATE REAL, ZDURATION REAL, ZLOCATION TEXT, ZADDRESS BLOB,
|
||||
ZSERVICE_PROVIDER TEXT
|
||||
)
|
||||
"""
|
||||
)
|
||||
conn.execute(
|
||||
"INSERT INTO ZCALLRECORD VALUES (?, ?, ?, ?, ?)",
|
||||
(700000000, 42, "Berlin", b"+491234", "carrier"),
|
||||
)
|
||||
if has_flags:
|
||||
conn.execute("ALTER TABLE ZCALLRECORD ADD COLUMN ZORIGINATED INTEGER")
|
||||
conn.execute("ALTER TABLE ZCALLRECORD ADD COLUMN ZANSWERED INTEGER")
|
||||
conn.execute("UPDATE ZCALLRECORD SET ZORIGINATED = 1, ZANSWERED = 0")
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
module = Calls(file_path=str(db_path))
|
||||
run_module(module)
|
||||
|
||||
assert len(module.results) == 1
|
||||
record = module.results[0]
|
||||
assert record["number"] == "+491234"
|
||||
assert record["originated"] == (1 if has_flags else None)
|
||||
assert record["answered"] == (0 if has_flags else None)
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
import logging
|
||||
import shutil
|
||||
import sqlite3
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -74,3 +75,39 @@ class TestSafariBrowserStateModule:
|
||||
assert len(m.alertstore.alerts) == 1
|
||||
assert len(m.results) == 1
|
||||
assert m.results[0]["tab_url"] == "https://en.wikipedia.org/wiki/NSO_Group"
|
||||
|
||||
def test_detection_for_tab_without_session_row(self, tmp_path, indicator_file):
|
||||
url = "https://en.wikipedia.org/wiki/NSO_Group"
|
||||
db_path = tmp_path / "private/var/mobile/Library/Safari/BrowserState.db"
|
||||
db_path.parent.mkdir(parents=True)
|
||||
conn = sqlite3.connect(db_path)
|
||||
try:
|
||||
conn.executescript(
|
||||
"""
|
||||
CREATE TABLE tabs (
|
||||
uuid TEXT, title TEXT, url TEXT, user_visible_url TEXT,
|
||||
last_viewed_time REAL
|
||||
);
|
||||
CREATE TABLE tab_sessions (tab_uuid TEXT, session_data BLOB);
|
||||
"""
|
||||
)
|
||||
conn.execute(
|
||||
"INSERT INTO tabs VALUES ('tab-1', 'Example', ?, ?, 700000000)",
|
||||
(url, url),
|
||||
)
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
module = SafariBrowserState(target_path=str(tmp_path))
|
||||
module.is_fs_dump = True
|
||||
indicators = Indicators(log=logging.getLogger())
|
||||
indicators.parse_stix2(indicator_file)
|
||||
indicators.ioc_collections[0]["domains"].append("en.wikipedia.org")
|
||||
module.indicators = indicators
|
||||
run_module(module)
|
||||
|
||||
assert len(module.results) == 1
|
||||
assert module.results[0]["tab_url"] == url
|
||||
assert module.results[0]["session_data"] == []
|
||||
assert len(module.alertstore.alerts) == 1
|
||||
@@ -10,7 +10,6 @@ import shutil
|
||||
import tempfile
|
||||
import zipfile
|
||||
|
||||
import pytest
|
||||
from click.testing import CliRunner
|
||||
|
||||
from mvt.android.cli import check_androidqf
|
||||
@@ -24,71 +23,7 @@ from .utils import get_artifact_folder
|
||||
TEST_BACKUP_PASSWORD = "123456"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"layout", ["directory", "", "./", "acquisition/", "outer/acquisition/"]
|
||||
)
|
||||
def test_androidqf_property_detection_across_layouts(
|
||||
tmp_path, indicators_factory, monkeypatch, layout
|
||||
):
|
||||
monkeypatch.setattr(settings, "NETWORK_ACCESS_ALLOWED", False)
|
||||
content = (
|
||||
"[persist.sys.timezone]: [Europe/Berlin]\n"
|
||||
"[test.suspicious.property]: [enabled]\n"
|
||||
)
|
||||
if layout == "directory":
|
||||
target = tmp_path / "acquisition"
|
||||
target.mkdir()
|
||||
(target / "getprop.txt").write_text(content)
|
||||
else:
|
||||
target = tmp_path / "acquisition.zip"
|
||||
with zipfile.ZipFile(target, "w") as archive:
|
||||
archive.writestr(layout + "getprop.txt", content)
|
||||
|
||||
command = CmdAndroidCheckAndroidQF(
|
||||
target_path=str(target),
|
||||
module_name="AQFGetProp",
|
||||
iocs=indicators_factory(android_property_names=["test.suspicious.property"]),
|
||||
)
|
||||
command.run()
|
||||
|
||||
assert len(command.executed) == 1
|
||||
module = command.executed[0]
|
||||
assert module.results == [
|
||||
{"name": "persist.sys.timezone", "value": "Europe/Berlin"},
|
||||
{"name": "test.suspicious.property", "value": "enabled"},
|
||||
]
|
||||
assert module._get_device_timezone() == "Europe/Berlin"
|
||||
assert len(command.alertstore.alerts) == 1
|
||||
assert command.alertstore.alerts[0].event == module.results[1]
|
||||
|
||||
|
||||
class TestCheckAndroidqfCommand:
|
||||
@pytest.mark.parametrize("use_zip", [False, True], ids=["folder", "zip"])
|
||||
def test_androidqf_process_list_and_log_files(self, tmp_path, use_zip):
|
||||
archive_path = tmp_path / "acquisition.zip"
|
||||
with zipfile.ZipFile(archive_path, "w") as archive:
|
||||
archive.writestr("processes.txt", "USER PID NAME\nroot 1 init\n")
|
||||
archive.writestr("logs/proc/kmsg", "")
|
||||
archive.writestr("logs/data/anr/", "")
|
||||
target = archive_path if use_zip else tmp_path / "acquisition"
|
||||
if not use_zip:
|
||||
archive.extractall(target)
|
||||
|
||||
command = CmdAndroidCheckAndroidQF(
|
||||
target_path=str(target),
|
||||
disable_version_check=True,
|
||||
disable_indicator_check=True,
|
||||
)
|
||||
command.run()
|
||||
|
||||
records = {type(module).__name__: module.results for module in command.executed}
|
||||
assert records["AQFProcesses"] == [
|
||||
{"user": "root", "pid": 1, "command": "init"}
|
||||
]
|
||||
timestamps = records["AQFLogTimestamps"]
|
||||
assert len(timestamps) == 1
|
||||
assert timestamps[0]["path"].replace("\\", "/").endswith("logs/proc/kmsg")
|
||||
|
||||
def test_log_timestamps_module_is_registered(self):
|
||||
assert AQFLogTimestamps in ANDROIDQF_MODULES
|
||||
|
||||
|
||||
Reference in new issue
Block a user