Compare commits

..
6 changed files with 156 additions and 92 deletions

No files matched your search

+9 -88
View File
@@ -14,10 +14,10 @@ env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
# Build each architecture natively, then publish the combined image manifests.
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
build-and-push-image:
runs-on: ${{ matrix.architecture.runner }}
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
@@ -26,15 +26,7 @@ jobs:
id-token: write
#
strategy:
fail-fast: false
matrix:
architecture:
- platform: linux/amd64
runner: ubuntu-24.04
name: amd64
- platform: linux/arm64
runner: ubuntu-24.04-arm
name: arm64
platform:
- dockerfile: "Dockerfile"
tag-suffix: ""
@@ -69,95 +61,24 @@ jobs:
type=raw,enable=${{ github.ref_type == 'tag' }},value=${{ github.ref_name }},suffix=${{ matrix.platform.tag-suffix }}
type=sha,suffix=${{ matrix.platform.tag-suffix }}
type=sha,format=long,suffix=${{ matrix.platform.tag-suffix }}
# Register emulators so Buildx can build the ARM64 images on the AMD64 runner.
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
# This step sets up some additional capabilities to generate the provenance and sbom attestations
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# Push by digest so architecture builds do not overwrite shared image tags.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v7
with:
file: ${{ matrix.platform.dockerfile }}
context: .
platforms: ${{ matrix.architecture.platform }}
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
provenance: mode=max
sbom: true
- name: Export image digest
env:
DIGEST: ${{ steps.push.outputs.digest }}
run: |
mkdir -p "${RUNNER_TEMP}/digests"
touch "${RUNNER_TEMP}/digests/${DIGEST#sha256:}"
- name: Upload image digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.platform.dockerfile }}-${{ matrix.architecture.name }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1
publish-manifests:
needs: build-and-push-image
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
strategy:
matrix:
platform:
- dockerfile: "Dockerfile"
tag-suffix: ""
- dockerfile: "Dockerfile.ios"
tag-suffix: "-ios"
- dockerfile: "Dockerfile.android"
tag-suffix: "-android"
steps:
- name: Download image digests
uses: actions/download-artifact@v4
with:
pattern: digests-${{ matrix.platform.dockerfile }}-*
path: ${{ runner.temp }}/digests
merge-multiple: true
- name: Log in to the Container registry
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=false
tags: |
type=raw,value=latest,enable={{ is_default_branch }},suffix=${{ matrix.platform.tag-suffix }}
type=raw,enable=${{ github.event_name == 'release' || github.ref_type == 'tag' }},value=stable,suffix=${{ matrix.platform.tag-suffix }}
type=raw,enable=${{ github.event_name == 'release' }},value=${{ github.event.release.tag_name }},suffix=${{ matrix.platform.tag-suffix }}
type=raw,enable=${{ github.ref_type == 'tag' }},value=${{ github.ref_name }},suffix=${{ matrix.platform.tag-suffix }}
type=sha,suffix=${{ matrix.platform.tag-suffix }}
type=sha,format=long,suffix=${{ matrix.platform.tag-suffix }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Publish multi-platform image
working-directory: ${{ runner.temp }}/digests
env:
METADATA_JSON: ${{ steps.meta.outputs.json }}
run: |
mapfile -t tags < <(jq -r '.tags[]' <<< "$METADATA_JSON")
tag_args=()
for tag in "${tags[@]}"; do
tag_args+=(--tag "$tag")
done
images=()
for digest in *; do
images+=("${REGISTRY}/${IMAGE_NAME}@sha256:${digest}")
done
test "${#images[@]}" -eq 2
docker buildx imagetools create "${tag_args[@]}" "${images[@]}"
docker buildx imagetools inspect "${tags[0]}"
+3 -1
View File
@@ -95,7 +95,9 @@ class CmdAndroidCheckAndroidQF(Command):
elif os.path.isfile(self.target_path):
self.__format = "zip"
self.__zip = zipfile.ZipFile(self.target_path)
self.__files = self.__zip.namelist()
self.__files = [
entry.filename for entry in self.__zip.infolist() if not entry.is_dir()
]
self._load_acquisition_context()
@@ -34,7 +34,9 @@ class AQFProcesses(ProcessesArtifact, AndroidQFModule):
)
def run(self) -> None:
ps_files = self._get_files_by_pattern("*/ps.txt")
ps_files = self._get_files_by_pattern(
"*/processes.txt"
) or self._get_files_by_pattern("*/ps.txt")
if not ps_files:
return
+16 -2
View File
@@ -46,8 +46,22 @@ class AndroidQFModule(MVTModule):
self.archive = archive
self.files = files
def _get_files_by_pattern(self, pattern: str):
return fnmatch.filter(self.files, pattern)
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_device_timezone(self):
"""
+60
View File
@@ -0,0 +1,60 @@
# 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") == []
+65
View File
@@ -10,6 +10,7 @@ import shutil
import tempfile
import zipfile
import pytest
from click.testing import CliRunner
from mvt.android.cli import check_androidqf
@@ -23,7 +24,71 @@ 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