mirror of
https://github.com/mvt-project/mvt.git
synced 2026-09-03 16:41:05 +02:00
* Add a platform-neutral mvt command Several MVT commands have nothing to do with the acquisition of one platform, yet they were reachable only through mvt-ios and mvt-android. Asking which version is installed or downloading the public indicators meant picking one of the two platform commands arbitrarily, and each of those tasks had to be written, documented and maintained twice. Add a third console script, mvt, hosting the commands which belong to no platform: version and download-iocs for now, with completion following in a later commit. Commands installed in the new mvt.cli_plugins entry-point group are registered on mvt, and on mvt only, so that a command package chooses the CLI each of its commands is added to: mvt.ios.cli_plugins for mvt-ios, mvt.android.cli_plugins for mvt-android and mvt.cli_plugins for mvt. A command wanted on both platform CLIs is registered in both platform groups; no group adds a command to every CLI. The MVT_CUSTOM_COMMANDS variable loads command files and folders into mvt the way the platform variables already do for mvt-ios and mvt-android. Run on its own, mvt prints the banner and its help instead of a usage error. The help text reminds that the forensic analysis of an acquisition runs through mvt-ios and mvt-android, so that the command which knows nothing about acquisitions says where they are analysed. version and download-iocs stay on mvt-ios and mvt-android for now, so that no documented invocation stops working. They are to be dropped from the platform CLIs in a later release, once mvt has been available long enough for the change to be announced. Unlike mvt-ios and mvt-android, which point at their subpackages, the console script points at mvt.cli:main and the mvt package re-exports nothing of it. Importing mvt has to stay cheap and free of side effects: it is the package plugins import from, and pulling in Click, the CLI and everything the commands import merely because something imported mvt would work against that. While here, give the version command of both platform CLIs the context settings every other command already has, so that "mvt-ios version -h" prints its help instead of failing on an unknown option. * Reduce indent for MVT CLI header * Move shell completion to the mvt command and generate one script for every MVT command Setting up shell completion had nothing to do with the acquisition of one platform, yet it was a command of mvt-ios and mvt-android, each generating the script of the program it ran under only. Completion now leaves the platform CLIs for mvt, which emits one script covering mvt, mvt-ios and mvt-android, installed as a single file loaded when the shell starts. Click names the completion function of each program after the program, so the three scripts concatenate without colliding, and fish takes the file in conf.d rather than one named after a single command. With one script there is nothing left for the platform commands to generate, so their completion command goes, and with it the banner suppression which was keyed on the command name: mvt-ios and mvt-android now print the banner for every command they have. The long help line says which commands the completion covers, so a short_help keeps "mvt --help" from truncating it. * Point the README and the command docs at plugin packages Loading a command by path is for local development; a package is how a command is distributed. The README's summary of what extends MVT now names plugin packages and nothing else, and the section on loading a command file says what it is for: keeping a command being written loadable without reinstalling its package after every change.
96 lines
3.0 KiB
Python
96 lines
3.0 KiB
Python
# 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
|
|
import os
|
|
|
|
import pytest
|
|
|
|
from mvt.common.cli_plugins import (
|
|
MVT_ANDROID_CUSTOM_COMMANDS_ENV,
|
|
MVT_CUSTOM_COMMANDS_ENV,
|
|
MVT_IOS_CUSTOM_COMMANDS_ENV,
|
|
)
|
|
from mvt.common.indicators import Indicators
|
|
|
|
from .artifacts.generate_stix import generate_test_stix_file
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
def indicator_file(request, tmp_path_factory):
|
|
indicator_dir = tmp_path_factory.mktemp("indicators")
|
|
stix_path = indicator_dir / "indicators.stix2"
|
|
generate_test_stix_file(stix_path)
|
|
return str(stix_path)
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
def clean_test_env(request, tmp_path_factory):
|
|
try:
|
|
del os.environ["MVT_STIX2"]
|
|
except KeyError:
|
|
pass
|
|
|
|
|
|
@pytest.fixture()
|
|
def indicators_factory(indicator_file):
|
|
def f(
|
|
domains=[],
|
|
emails=[],
|
|
file_names=[],
|
|
file_paths=[],
|
|
processes=[],
|
|
app_ids=[],
|
|
app_cert_hashes=[],
|
|
android_property_names=[],
|
|
files_sha256=[],
|
|
):
|
|
ind = Indicators(log=logging.getLogger())
|
|
ind.parse_stix2(indicator_file)
|
|
|
|
ind.ioc_collections[0]["domains"].extend(domains)
|
|
ind.ioc_collections[0]["emails"].extend(emails)
|
|
ind.ioc_collections[0]["file_names"].extend(file_names)
|
|
ind.ioc_collections[0]["file_paths"].extend(file_paths)
|
|
ind.ioc_collections[0]["processes"].extend(processes)
|
|
ind.ioc_collections[0]["app_ids"].extend(app_ids)
|
|
ind.ioc_collections[0]["android_property_names"].extend(android_property_names)
|
|
ind.ioc_collections[0]["files_sha256"].extend(files_sha256)
|
|
ind.ioc_collections[0]["app_cert_hashes"].extend(app_cert_hashes)
|
|
|
|
return ind
|
|
|
|
return f
|
|
|
|
|
|
@pytest.fixture()
|
|
def restore_cli_commands(monkeypatch):
|
|
"""Keep the external commands a test registers out of the next test.
|
|
|
|
Each CLI group is a module-level object shared by every test, so a test
|
|
registering plugin or environment commands on one has to put it back. The
|
|
groups are imported here rather than at the top of the file, so that
|
|
collecting the tests does not import three CLIs for the sake of one
|
|
fixture.
|
|
"""
|
|
from mvt.android.cli import cli as android_cli
|
|
from mvt.cli import cli as neutral_cli
|
|
from mvt.ios.cli import cli as ios_cli
|
|
|
|
groups = (neutral_cli, ios_cli, android_cli)
|
|
for variable in (
|
|
MVT_CUSTOM_COMMANDS_ENV,
|
|
MVT_IOS_CUSTOM_COMMANDS_ENV,
|
|
MVT_ANDROID_CUSTOM_COMMANDS_ENV,
|
|
):
|
|
monkeypatch.delenv(variable, raising=False)
|
|
originals = [dict(group.commands) for group in groups]
|
|
yield
|
|
for group, commands in zip(groups, originals):
|
|
group.commands.clear()
|
|
group.commands.update(commands)
|
|
if hasattr(group, "_mvt_external_command_sources"):
|
|
delattr(group, "_mvt_external_command_sources")
|