From 86b217a926b51d97d9cfb6c29f69e4ed7dac6180 Mon Sep 17 00:00:00 2001 From: Janik Besendorf Date: Fri, 11 Sep 2026 11:14:53 +0200 Subject: [PATCH 1/7] Recommend pymobiledevice3 for iOS acquisition --- docs/docker.md | 4 ++- docs/ios/backup/libimobiledevice.md | 18 +--------- docs/ios/backup/pymobiledevice3.md | 37 +++++++++++++++++++++ docs/ios/install.md | 51 +++++++++++------------------ mkdocs.yml | 5 +-- 5 files changed, 64 insertions(+), 51 deletions(-) create mode 100644 docs/ios/backup/pymobiledevice3.md diff --git a/docs/docker.md b/docs/docker.md index 453c245f..9082b92b 100644 --- a/docs/docker.md +++ b/docs/docker.md @@ -1,4 +1,6 @@ -Using Docker simplifies having all the required dependencies and tools (including most recent versions of [libimobiledevice](https://libimobiledevice.org)) readily installed. Note that this requires a Linux host, as Docker for Windows and Mac [doesn't support passing through USB devices](https://docs.docker.com/desktop/faqs/#can-i-pass-through-a-usb-device-to-a-container). +Using Docker simplifies running MVT with its dependencies readily installed. Note that this requires a Linux host, as Docker for Windows and Mac [doesn't support passing through USB devices](https://docs.docker.com/desktop/faqs/#can-i-pass-through-a-usb-device-to-a-container). + +For iOS acquisition, we recommend [installing pymobiledevice3](ios/install.md) on the host and [creating a backup](ios/backup/pymobiledevice3.md) before analyzing it with MVT. The Docker images currently include libimobiledevice, not pymobiledevice3. Install Docker following the [official documentation](https://docs.docker.com/get-docker/). diff --git a/docs/ios/backup/libimobiledevice.md b/docs/ios/backup/libimobiledevice.md index d72868a5..39eacee7 100644 --- a/docs/ios/backup/libimobiledevice.md +++ b/docs/ios/backup/libimobiledevice.md @@ -1,19 +1,3 @@ # Backup with libimobiledevice -If you have correctly [installed libimobiledevice](../install.md) you can easily generate an iTunes backup using the `idevicebackup2` tool included in the suite. First, you might want to ensure that backup encryption is enabled (**note: encrypted backup contain more data than unencrypted backups**): - -```bash -idevicebackup2 -i encryption on -``` - -Note that if a backup password was previously set on this device, you might need to use the same or change it. You can try changing password using `idevicebackup2 -i changepw`, or by turning off encryption (`idevicebackup2 -i encryption off`) and turning it back on again. - -If you are not able to recover or change the password, you should try to disable encryption and obtain an unencrypted backup. - -If all else fails, as a *last resort* you can try resetting the password by [resetting all the settings through the iPhone's Settings app](https://support.apple.com/en-us/HT205220), via `Settings » General » Reset » Reset All Settings`. Note that resetting the settings through the iPhone's Settings app will wipe some of the files that contain useful forensic traces, so try the options explained above first. - -Once ready, you can proceed performing the backup: - -```bash -idevicebackup2 backup --full /path/to/backup/ -``` +We now recommend pymobiledevice3 for iOS backups. See [Backup with pymobiledevice3](pymobiledevice3.md) for the current instructions. diff --git a/docs/ios/backup/pymobiledevice3.md b/docs/ios/backup/pymobiledevice3.md new file mode 100644 index 00000000..73c6a2a5 --- /dev/null +++ b/docs/ios/backup/pymobiledevice3.md @@ -0,0 +1,37 @@ +# Backup with pymobiledevice3 + +After [installing pymobiledevice3](../install.md) and pairing your device, you can generate an iTunes-compatible backup using its `backup2` commands. + +## Enable backup encryption + +We recommend encrypted backups because they contain more data than unencrypted backups. If encryption is not already enabled, enable it with: + +```bash +pymobiledevice3 backup2 encryption on 'YOUR_BACKUP_PASSWORD' +``` + +Replace `YOUR_BACKUP_PASSWORD` with a strong password and keep it safe: you will need it to decrypt the backup for analysis. Passwords supplied on the command line may be saved in shell history or visible to other processes. + +If a backup password was previously set, use that password. To change a known password: + +```bash +pymobiledevice3 backup2 change-password 'CURRENT_PASSWORD' 'NEW_PASSWORD' +``` + +You can also disable encryption with `pymobiledevice3 backup2 encryption off 'CURRENT_PASSWORD'` and then enable it again. Disabling encryption requires the current password; it is not a way to bypass an unknown password. + +!!! warning + If you cannot recover the password, resetting it through [Reset All Settings in the iPhone's Settings app](https://support.apple.com/en-us/HT205220) should be a last resort. Resetting settings can remove files containing useful forensic traces. + +## Create a backup + +Choose a new destination directory to avoid overwriting an earlier acquisition: + +```bash +mkdir -p /path/to/backup/ +pymobiledevice3 backup2 backup --full /path/to/backup/ +``` + +The backup is saved in a subdirectory named after the device's UDID, such as `/path/to/backup/udid/`. Follow [Check a Backup with mvt-ios](check.md) to decrypt and analyze that directory. + +For additional options, see the [pymobiledevice3 backup2 reference](https://doronz88.github.io/pymobiledevice3/cli/backup2/). diff --git a/docs/ios/install.md b/docs/ios/install.md index 1898f3f5..d5e1574f 100644 --- a/docs/ios/install.md +++ b/docs/ios/install.md @@ -1,55 +1,44 @@ -# Install libimobiledevice +# Install pymobiledevice3 -Before proceeding with doing any acquisition of iOS devices we recommend installing [libimobiledevice](https://libimobiledevice.org/) utilities. These utilities will become useful when extracting crash logs and generating iTunes backups. Because the utilities and its libraries are subject to frequent changes in response to new versions of iOS, you might want to consider compiling libimobiledevice utilities from sources. Otherwise, if available, you can try installing packages available in your distribution: +Before acquiring data from an iOS device, we recommend installing [pymobiledevice3](https://github.com/doronz88/pymobiledevice3). It provides command-line tools for generating iTunes-compatible backups and extracting crash logs. + +## Installation + +Install `pipx` following the [MVT installation instructions](../install.md), then run: ```bash -sudo apt install libimobiledevice-utils +pipx install pymobiledevice3 ``` -On Mac, you can try installing it from brew: +To update an existing installation: ```bash -brew install --HEAD libimobiledevice +pipx upgrade pymobiledevice3 ``` -If you have a reasonably recent version of libimobiledevice in your package manager, it might work straight out of the box. Try connecting your iOS device to your computer via USB and run: +On Linux, you also need `usbmuxd` to communicate with devices over USB. On Debian and Ubuntu, install it with: ```bash -ideviceinfo +sudo apt install usbmuxd ``` -If you encounter unexpected issues, uninstall the packages and try compiling libimobiledevcice from sources. +macOS includes the required USB device service. For other platforms and additional requirements, see the [pymobiledevice3 installation documentation](https://doronz88.github.io/pymobiledevice3/installation/). -## Compile libimobiledevice from sources +## Verify connectivity -!!! warning - The following instructions are a best effort. The installation from source requires several steps, and it is likely some have been forgotten here and that won't work for you. You will likely need to fiddle around a bit before getting this right. - -Make sure you have uninstalled all the libimobiledevice tools from your package manage: +Connect the iOS device to your computer with a USB cable and unlock it. Accept the **Trust This Computer** prompt and enter the device passcode if requested. Then run: ```bash -sudo apt remove --purge libimobiledevice-utils libimobiledevice-dev libimobiledevice6 libplist-dev libplist3 libusbmuxd-dev libusbmuxd-tools libusbmuxd4 libusbmuxd6 usbmuxd +pymobiledevice3 usbmux list +pymobiledevice3 lockdown info ``` -Firstly you need to install [libplist](https://github.com/libimobiledevice/libplist). Then you can install [libusbmuxd](https://github.com/libimobiledevice/libusbmuxd). - -Now you should be able to to download and install the actual suite of tools at [https://github.com/libimobiledevice/libimobiledevice](https://github.com/libimobiledevice/libimobiledevice). - -You can now also build and install [usbmuxd](https://github.com/libimobiledevice/usbmuxd). - -## Making sure everything works fine. - -Once the idevice tools are available you can check if everything works fine by connecting your iOS device and running: +These commands should list the connected device and display its details. If pairing is needed, run: ```bash -ideviceinfo +pymobiledevice3 lockdown pair ``` -This should show many details on the connected iOS device. If you are connecting the device to your laptop for the first time, it will require to unlock and enter the PIN code on the mobile device. If it complains that no device is connected and the mobile device is indeed plugged in through the USB cable, you might need to do this first, although typically the pairing is automatically done when connecting the device: +If no device is found, check the USB connection, make sure the device is unlocked, and, on Linux, check that `usbmuxd` is running. See the [upstream troubleshooting guide](https://doronz88.github.io/pymobiledevice3/guides/troubleshooting/) for further help. -```bash -sudo usbmuxd -f -v -idevicepair pair -``` - -Again, it will ask to unlock the phone and enter the PIN code. +Once connected, follow the [backup instructions](backup/pymobiledevice3.md). diff --git a/mkdocs.yml b/mkdocs.yml index 66def17e..4cbdb47b 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -5,6 +5,7 @@ copyright: Copyright © 2021-2023 MVT Project Developers site_description: Mobile Verification Toolkit Documentation not_in_nav: | android/adb.md + ios/backup/libimobiledevice.md markdown_extensions: - attr_list - admonition @@ -34,10 +35,10 @@ nav: - Using Docker: "docker.md" - MVT for iOS: - iOS Forensic Methodology: "ios/methodology.md" - - Install libimobiledevice: "ios/install.md" + - Install pymobiledevice3: "ios/install.md" - Check an iTunes Backup: - Backup with iTunes app: "ios/backup/itunes.md" - - Backup with libimobiledevice: "ios/backup/libimobiledevice.md" + - Backup with pymobiledevice3: "ios/backup/pymobiledevice3.md" - Check a Backup with mvt-ios: "ios/backup/check.md" - Check a Filesystem Dump: - Dumping the filesystem: "ios/filesystem/dump.md" From d0cf303aa27ae7b0427af080c30e9b853456f5d2 Mon Sep 17 00:00:00 2001 From: Janik Besendorf Date: Fri, 11 Sep 2026 11:21:57 +0200 Subject: [PATCH 2/7] Replace libimobiledevice with pymobiledevice3 in Docker images --- Dockerfile | 129 +++++--------------------------------------- Dockerfile.ios | 144 ++++++++----------------------------------------- docs/docker.md | 25 +++++++-- 3 files changed, 57 insertions(+), 241 deletions(-) diff --git a/Dockerfile b/Dockerfile index 138edc7e..a83ef115 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,107 +1,3 @@ -# Base image for building libraries -# --------------------------------- -FROM ubuntu:22.04 AS build-base - -ARG DEBIAN_FRONTEND=noninteractive - -# Install build tools and dependencies -RUN apt-get update \ - && apt-get install -y \ - build-essential \ - git \ - autoconf \ - automake \ - libtool-bin \ - pkg-config \ - libcurl4-openssl-dev \ - libusb-1.0-0-dev \ - libssl-dev \ - udev \ - && rm -rf /var/lib/apt/lists/* - - -# libplist -# -------- -FROM build-base AS build-libplist - -# Build -RUN git clone https://github.com/libimobiledevice/libplist && cd libplist \ - && ./autogen.sh && make -j "$(nproc)" && make install DESTDIR=/build \ - && cd .. && rm -rf libplist - - -# libimobiledevice-glue -# --------------------- -FROM build-base AS build-libimobiledevice-glue - -# Install dependencies -COPY --from=build-libplist /build / - -# Build -RUN git clone https://github.com/libimobiledevice/libimobiledevice-glue && cd libimobiledevice-glue \ - && ./autogen.sh && make -j "$(nproc)" && make install DESTDIR=/build \ - && cd .. && rm -rf libimobiledevice-glue - - -# libtatsu -# -------- -FROM build-base AS build-libtatsu - -# Install dependencies -COPY --from=build-libplist /build / - -# Build -RUN git clone https://github.com/libimobiledevice/libtatsu && cd libtatsu \ - && ./autogen.sh && make -j "$(nproc)" && make install DESTDIR=/build \ - && cd .. && rm -rf libtatsu - - -# libusbmuxd -# ---------- -FROM build-base AS build-libusbmuxd - -# Install dependencies -COPY --from=build-libplist /build / -COPY --from=build-libimobiledevice-glue /build / - -# Build -RUN git clone https://github.com/libimobiledevice/libusbmuxd && cd libusbmuxd \ - && ./autogen.sh && make -j "$(nproc)" && make install DESTDIR=/build \ - && cd .. && rm -rf libusbmuxd - - -# libimobiledevice -# ---------------- -FROM build-base AS build-libimobiledevice - -# Install dependencies -COPY --from=build-libplist /build / -COPY --from=build-libtatsu /build / -COPY --from=build-libimobiledevice-glue /build / -COPY --from=build-libusbmuxd /build / - -# Build -RUN git clone https://github.com/libimobiledevice/libimobiledevice && cd libimobiledevice \ - && ./autogen.sh --enable-debug && make -j "$(nproc)" && make install DESTDIR=/build \ - && cd .. && rm -rf libimobiledevice - - -# usbmuxd -# ------- -FROM build-base AS build-usbmuxd - -# Install dependencies -COPY --from=build-libplist /build / -COPY --from=build-libimobiledevice-glue /build / -COPY --from=build-libusbmuxd /build / -COPY --from=build-libimobiledevice /build / - -# Build -RUN git clone https://github.com/libimobiledevice/usbmuxd && cd usbmuxd \ - && ./autogen.sh --sysconfdir=/etc --localstatedir=/var --runstatedir=/run && make -j "$(nproc)" && make install DESTDIR=/build \ - && cd .. && rm -rf usbmuxd && mv /build/lib /build/usr/lib - - # Create main image FROM ubuntu:24.04 AS main COPY --from=ghcr.io/astral-sh/uv:0.11.8 /uv /uvx /usr/local/bin/ @@ -112,7 +8,7 @@ LABEL org.opencontainers.image.source="https://github.com/mvt-project/mvt" LABEL org.opencontainers.image.title="Mobile Verification Toolkit" LABEL org.opencontainers.image.description="MVT is a forensic tool to look for signs of infection in smartphone devices." LABEL org.opencontainers.image.licenses="MVT License 1.1" -LABEL org.opencontainers.image.base.name=docker.io/library/ubuntu:22.04 +LABEL org.opencontainers.image.base.name=docker.io/library/ubuntu:24.04 # Install runtime dependencies ARG DEBIAN_FRONTEND=noninteractive @@ -125,7 +21,6 @@ RUN apt-get update \ git \ jq \ less \ - libcurl4 \ libimage-exiftool-perl \ libssl3 \ libusb-1.0-0 \ @@ -136,18 +31,20 @@ RUN apt-get update \ sqlite3 \ tree \ unzip \ - xxd -COPY --from=build-libplist /build / -COPY --from=build-libimobiledevice-glue /build / -COPY --from=build-libtatsu /build / -COPY --from=build-libusbmuxd /build / -COPY --from=build-libimobiledevice /build / -COPY --from=build-usbmuxd /build / + xxd \ + && rm -rf /var/lib/apt/lists/* -# Install mvt using the locally checked out source +# Install MVT and pymobiledevice3. Native build dependencies are needed on ARM64. +ARG PYMOBILEDEVICE3_VERSION=11.12.4 COPY . mvt/ -RUN uv pip install --system --break-system-packages --no-cache ./mvt \ - && rm -rf mvt +RUN apt-get update \ + && apt-get install -y --no-install-recommends build-essential python3-dev libssl-dev \ + && uv pip install --system --break-system-packages --no-cache ./mvt "pymobiledevice3==${PYMOBILEDEVICE3_VERSION}" \ + && apt-get purge -y --auto-remove build-essential python3-dev libssl-dev \ + && rm -rf mvt /var/lib/apt/lists/* \ + && pymobiledevice3 --help > /dev/null \ + && pymobiledevice3 backup2 --help > /dev/null \ + && mvt-ios --help > /dev/null # Installing ABE ADD --checksum=sha256:a20e07f8b2ea47620aff0267f230c3f1f495f097081fd709eec51cf2a2e11632 \ diff --git a/Dockerfile.ios b/Dockerfile.ios index fccbe45b..90ef4e4c 100644 --- a/Dockerfile.ios +++ b/Dockerfile.ios @@ -1,110 +1,6 @@ -# Base image for building libraries -# --------------------------------- -FROM ubuntu:22.04 AS build-base - -ARG DEBIAN_FRONTEND=noninteractive - -# Install build tools and dependencies -RUN apt-get update \ - && apt-get install -y \ - build-essential \ - git \ - autoconf \ - automake \ - libtool-bin \ - pkg-config \ - libcurl4-openssl-dev \ - libusb-1.0-0-dev \ - libssl-dev \ - udev \ - && rm -rf /var/lib/apt/lists/* - - -# libplist -# -------- -FROM build-base AS build-libplist - -# Build -RUN git clone https://github.com/libimobiledevice/libplist && cd libplist \ - && ./autogen.sh && make -j "$(nproc)" && make install DESTDIR=/build \ - && cd .. && rm -rf libplist - - -# libimobiledevice-glue -# --------------------- -FROM build-base AS build-libimobiledevice-glue - -# Install dependencies -COPY --from=build-libplist /build / - -# Build -RUN git clone https://github.com/libimobiledevice/libimobiledevice-glue && cd libimobiledevice-glue \ - && ./autogen.sh && make -j "$(nproc)" && make install DESTDIR=/build \ - && cd .. && rm -rf libimobiledevice-glue - - -# libtatsu -# -------- -FROM build-base AS build-libtatsu - -# Install dependencies -COPY --from=build-libplist /build / - -# Build -RUN git clone https://github.com/libimobiledevice/libtatsu && cd libtatsu \ - && ./autogen.sh && make -j "$(nproc)" && make install DESTDIR=/build \ - && cd .. && rm -rf libtatsu - - -# libusbmuxd -# ---------- -FROM build-base AS build-libusbmuxd - -# Install dependencies -COPY --from=build-libplist /build / -COPY --from=build-libimobiledevice-glue /build / - -# Build -RUN git clone https://github.com/libimobiledevice/libusbmuxd && cd libusbmuxd \ - && ./autogen.sh && make -j "$(nproc)" && make install DESTDIR=/build \ - && cd .. && rm -rf libusbmuxd - - -# libimobiledevice -# ---------------- -FROM build-base AS build-libimobiledevice - -# Install dependencies -COPY --from=build-libplist /build / -COPY --from=build-libtatsu /build / -COPY --from=build-libimobiledevice-glue /build / -COPY --from=build-libusbmuxd /build / - -# Build -RUN git clone https://github.com/libimobiledevice/libimobiledevice && cd libimobiledevice \ - && ./autogen.sh --enable-debug && make -j "$(nproc)" && make install DESTDIR=/build \ - && cd .. && rm -rf libimobiledevice - - -# usbmuxd -# ------- -FROM build-base AS build-usbmuxd - -# Install dependencies -COPY --from=build-libplist /build / -COPY --from=build-libimobiledevice-glue /build / -COPY --from=build-libusbmuxd /build / -COPY --from=build-libimobiledevice /build / - -# Build -RUN git clone https://github.com/libimobiledevice/usbmuxd && cd usbmuxd \ - && ./autogen.sh --sysconfdir=/etc --localstatedir=/var --runstatedir=/run && make -j "$(nproc)" && make install DESTDIR=/build \ - && cd .. && rm -rf usbmuxd && mv /build/lib /build/usr/lib - - # Main image # ---------- -FROM python:3.10.14-alpine3.20 AS main +FROM ubuntu:24.04 AS main COPY --from=ghcr.io/astral-sh/uv:0.11.8 /uv /uvx /usr/local/bin/ LABEL org.opencontainers.image.url="https://mvt.re" @@ -113,26 +9,30 @@ LABEL org.opencontainers.image.source="https://github.com/mvt-project/mvt" LABEL org.opencontainers.image.title="Mobile Verification Toolkit (iOS)" LABEL org.opencontainers.image.description="MVT is a forensic tool to look for signs of infection in smartphone devices." LABEL org.opencontainers.image.licenses="MVT License 1.1" -LABEL org.opencontainers.image.base.name=docker.io/library/python:3.10.14-alpine3.20 +LABEL org.opencontainers.image.base.name=docker.io/library/ubuntu:24.04 # Install runtime dependencies -RUN apk add --no-cache \ - gcompat \ - libcurl \ +ARG DEBIAN_FRONTEND=noninteractive +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + ca-certificates \ + git \ libssl3 \ - libusb \ - sqlite -COPY --from=build-libplist /build / -COPY --from=build-libimobiledevice-glue /build / -COPY --from=build-libtatsu /build / -COPY --from=build-libusbmuxd /build / -COPY --from=build-libimobiledevice /build / -COPY --from=build-usbmuxd /build / + libusb-1.0-0 \ + python3 \ + sqlite3 \ + && rm -rf /var/lib/apt/lists/* -# Install mvt using the locally checked out source -COPY ./ mvt -RUN apk add --no-cache --virtual .build-deps git gcc musl-dev \ - && uv pip install --system --no-cache ./mvt \ - && apk del .build-deps git gcc musl-dev && rm -rf ./mvt +# Install MVT and pymobiledevice3. Native build dependencies are needed on ARM64. +ARG PYMOBILEDEVICE3_VERSION=11.12.4 +COPY . mvt/ +RUN apt-get update \ + && apt-get install -y --no-install-recommends build-essential python3-dev libssl-dev \ + && uv pip install --system --break-system-packages --no-cache ./mvt "pymobiledevice3==${PYMOBILEDEVICE3_VERSION}" \ + && apt-get purge -y --auto-remove build-essential python3-dev libssl-dev \ + && rm -rf mvt /var/lib/apt/lists/* \ + && pymobiledevice3 --help > /dev/null \ + && pymobiledevice3 backup2 --help > /dev/null \ + && mvt-ios --help > /dev/null ENTRYPOINT [ "/usr/local/bin/mvt-ios" ] diff --git a/docs/docker.md b/docs/docker.md index 9082b92b..10d9cd09 100644 --- a/docs/docker.md +++ b/docs/docker.md @@ -1,6 +1,6 @@ Using Docker simplifies running MVT with its dependencies readily installed. Note that this requires a Linux host, as Docker for Windows and Mac [doesn't support passing through USB devices](https://docs.docker.com/desktop/faqs/#can-i-pass-through-a-usb-device-to-a-container). -For iOS acquisition, we recommend [installing pymobiledevice3](ios/install.md) on the host and [creating a backup](ios/backup/pymobiledevice3.md) before analyzing it with MVT. The Docker images currently include libimobiledevice, not pymobiledevice3. +The main and iOS Docker images include pymobiledevice3 for [creating iOS backups](ios/backup/pymobiledevice3.md). You do not need to install it separately on the host. Older image tags may still include libimobiledevice instead; build from the updated source if pymobiledevice3 is unavailable. Install Docker following the [official documentation](https://docs.docker.com/get-docker/). @@ -39,12 +39,31 @@ If a prompt is spawned successfully, you can close it with `exit`. On the Linux host, install and start [usbmuxd](https://github.com/libimobiledevice/usbmuxd), then connect and unlock the iOS device. The daemon exposes the device through the `/var/run/usbmuxd` socket. -Bind that socket into the container to let MVT communicate with the device: +Bind that socket into the container to let pymobiledevice3 communicate with the device. Also mount a local directory so acquired backups persist after the container exits: ```bash -docker run -it \ +mkdir -p "$PWD/cases" +docker run --rm -it \ --mount type=bind,source=/var/run/usbmuxd,target=/var/run/usbmuxd \ + --mount type=bind,source="$PWD/cases",target=/home/cases \ ghcr.io/mvt-project/mvt ``` +Inside the container, verify connectivity: + +```bash +pymobiledevice3 lockdown info +``` + +Accept the trust prompt on the unlocked device if requested. Then follow the [backup instructions](ios/backup/pymobiledevice3.md), using a destination under `/home/cases`, such as `/home/cases/backup`. + +The iOS-only image defaults to running `mvt-ios`. To use pymobiledevice3 instead, override its entrypoint: + +```bash +docker run --rm -it \ + --mount type=bind,source=/var/run/usbmuxd,target=/var/run/usbmuxd \ + --entrypoint pymobiledevice3 \ + ghcr.io/mvt-project/mvt:latest-ios lockdown info +``` + If you built the image from source, replace `ghcr.io/mvt-project/mvt` with `mvt`. From 60d1b414fee6ce1cd72a22c65418825667b4b017 Mon Sep 17 00:00:00 2001 From: Forest Savage <96553407+forest-savage1234@users.noreply.github.com> Date: Tue, 29 Sep 2026 21:13:11 -0800 Subject: [PATCH 3/7] Correct the Python minimum in installation documentation --- docs/install.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/install.md b/docs/install.md index c024338c..7c5ee6ee 100644 --- a/docs/install.md +++ b/docs/install.md @@ -1,6 +1,6 @@ # Installation -Before proceeding, please note that MVT requires Python 3.6+ to run. While it should be available on most operating systems, please make sure of that before proceeding. +Before proceeding, please note that MVT requires Python 3.10 or newer to run. While it should be available on most operating systems, please make sure of that before proceeding. ## Dependencies on Linux From 3a462e1e2c4b56542c0d55a1966e923f7559b925 Mon Sep 17 00:00:00 2001 From: "va@resident" Date: Tue, 6 Oct 2026 15:29:41 +0500 Subject: [PATCH 4/7] Fix spurious ADB state parse error on devices without stored keys Since #957 the parsed body keeps the closing brace of debugging_manager and the blank lines before it. The brace popped two levels, and a blank line after system_keys raised IndexError. Don't pop when the indentation drops on a closing brace, and skip blank lines outside multiline values. Fixes #967. --- src/mvt/android/artifacts/dumpsys_adb.py | 10 ++- tests/android/test_artifact_dumpsys_adb.py | 79 ++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/src/mvt/android/artifacts/dumpsys_adb.py b/src/mvt/android/artifacts/dumpsys_adb.py index c57cf8d6..2e493c27 100644 --- a/src/mvt/android/artifacts/dumpsys_adb.py +++ b/src/mvt/android/artifacts/dumpsys_adb.py @@ -33,7 +33,12 @@ class DumpsysADBArtifact(AndroidArtifact): line = line.removesuffix(b"\r") # Track the level of indentation indent = len(line) - len(line.lstrip()) - if indent < cur_indent: + # A closing brace is dedented from the block it closes, and the + # brace handler below pops that block. Popping on the dedent as + # well would close two levels for one brace. A blank line has no + # indentation to compare: it ends a multiline value (handled + # below) and is otherwise skipped. + if indent < cur_indent and line.strip() not in (b"", b"}"): # If the current line is less indented than the previous one, back out if len(stack) <= 1: # Dedenting below the outermost level means this is not the @@ -72,6 +77,9 @@ class DumpsysADBArtifact(AndroidArtifact): stack.pop() current_dict = stack[-1] + if not line.strip(): + continue + if key == "}": if len(stack) <= 1: self.log.error( diff --git a/tests/android/test_artifact_dumpsys_adb.py b/tests/android/test_artifact_dumpsys_adb.py index 0e5b59f4..b85c3973 100644 --- a/tests/android/test_artifact_dumpsys_adb.py +++ b/tests/android/test_artifact_dumpsys_adb.py @@ -209,6 +209,85 @@ class TestDumpsysADBArtifact: assert len(da_adb.results) == 1 assert da_adb.results[0]["user_keys"][0]["user"] == user.decode() + def test_state_without_keys_is_parsed_without_error(self, caplog): + # Shape printed by every device with no stored ADB keys (Samsung + # SM-A525F, Android 12). The block's closing brace is dedented from + # the last entry and must close exactly one level. + da_adb = DumpsysADBArtifact() + da_adb.parse( + b"ADB MANAGER STATE (dumpsys adb):\n" + b"{\n" + b" debugging_manager={\n" + b" connected_to_adb=false\n" + b" }\n" + b"}\n" + b"--------- 0.015s was the duration of dumpsys adb\n" + ) + + assert len(da_adb.results) == 1 + assert da_adb.results[0]["connected_to_adb"] is False + assert not [r for r in caplog.records if r.levelname == "ERROR"] + + def test_nested_block_as_last_entry_is_parsed_without_error(self, caplog): + # Shape printed by Pixel devices with no stored ADB keys. + da_adb = DumpsysADBArtifact() + da_adb.parse( + b"ADB MANAGER STATE (dumpsys adb):\n" + b"{\n" + b" debugging_manager={\n" + b" connected_to_adb=false\n" + b" adb_wifi={\n" + b" enabled=false\n" + b" tls_port=0\n" + b" }\n" + b" }\n" + b"}\n" + ) + + assert len(da_adb.results) == 1 + assert da_adb.results[0]["connected_to_adb"] is False + assert da_adb.results[0]["adb_wifi"]["tls_port"] == b"0" + assert not [r for r in caplog.records if r.levelname == "ERROR"] + + def test_entry_after_nested_block_stays_in_debugging_manager(self): + da_adb = DumpsysADBArtifact() + da_adb.parse( + b"ADB MANAGER STATE (dumpsys adb):\n" + b"{\n" + b" debugging_manager={\n" + b" adb_wifi={\n" + b" enabled=false\n" + b" }\n" + b" connected_to_adb=true\n" + b" }\n" + b"}\n" + ) + + assert len(da_adb.results) == 1 + assert da_adb.results[0]["connected_to_adb"] is True + + def test_blank_line_after_single_line_value_does_not_raise(self): + # `system_keys` is the content of /adb_keys and ends with a newline, + # so a blank line follows it. It is not a multiline field, so the + # blank line is not a multiline terminator either. + da_adb = DumpsysADBArtifact() + da_adb.parse( + b"ADB MANAGER STATE (dumpsys adb):\n" + b"{\n" + b" debugging_manager={\n" + b" connected_to_adb=true\n" + b" user_keys=QUJDRA== host@example\n" + b"\n" + b" system_keys=RUZHSA== system@example\n" + b"\n" + b" }\n" + b"}\n" + ) + + assert len(da_adb.results) == 1 + assert da_adb.results[0]["user_keys"][0]["user"] == "host@example" + assert da_adb.results[0]["system_keys"] == "RUZHSA== system@example" + def test_unbalanced_state_is_reported_rather_than_raising(self): da_adb = DumpsysADBArtifact() da_adb.parse( From 10f739d66949e017db42ef2ac2455cf6c9db3fef Mon Sep 17 00:00:00 2001 From: Muhammad Mohid Shafiq Date: Thu, 8 Oct 2026 19:35:29 +0500 Subject: [PATCH 5/7] Keep settings history timestamps on 29 February dumpsys prints the settings change history without a year, so _resolve_timestamp() parsed the value with strptime("%m-%d ...") and only then replaced the year. strptime() parses a value without a year in 1900, which has no 29 February, so every change made on a leap day raised ValueError and lost its timestamp, dropping it from the timeline and from the alert of a dangerous setting. Parse the value together with a year instead, starting from the year the section was dumped and going back until the date exists and is not later than the dump. Eight years always reach a leap year. This also removes the DeprecationWarning Python 3.13 raises for parsing a day of month without a year (python/cpython#70647). --- src/mvt/android/artifacts/settings.py | 21 +++++++++------ tests/android/test_artifact_settings.py | 35 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/mvt/android/artifacts/settings.py b/src/mvt/android/artifacts/settings.py index 39257c06..8237ee34 100644 --- a/src/mvt/android/artifacts/settings.py +++ b/src/mvt/android/artifacts/settings.py @@ -255,19 +255,24 @@ class Settings(AndroidArtifact): dumpsys prints the change history without a year, so it is resolved against the time the section was dumped: the most recent matching date at or before that time. + + The year is parsed together with the value, because strptime() would + otherwise parse it in 1900, which has no 29 February. Going back eight + years always reaches a leap year. """ if section_end is None: return None - try: - partial = datetime.strptime(value, "%m-%d %H:%M:%S.%f") - timestamp = partial.replace(year=section_end.year) - if timestamp > section_end: - timestamp = partial.replace(year=section_end.year - 1) - except ValueError: - return None + for year in range(section_end.year, section_end.year - 8, -1): + try: + timestamp = datetime.strptime(f"{year}-{value}", "%Y-%m-%d %H:%M:%S.%f") + except ValueError: + continue - return convert_datetime_to_iso(timestamp) + if timestamp <= section_end: + return convert_datetime_to_iso(timestamp) + + return None def _parse_history( self, line: str, section_end: Optional[datetime] diff --git a/tests/android/test_artifact_settings.py b/tests/android/test_artifact_settings.py index 2192c12b..f114cab7 100644 --- a/tests/android/test_artifact_settings.py +++ b/tests/android/test_artifact_settings.py @@ -3,6 +3,8 @@ # Use of this software is governed by the MVT License 1.1 that can be found at # https://license.mvt.re/1.1/ +from typing import Optional + from mvt.android.artifacts.settings import Settings from ..utils import get_artifact @@ -21,6 +23,21 @@ def find(settings: Settings, name: str) -> list: return [result for result in settings.results if result["name"] == name] +def resolve_history_time(time: str, section_end: str) -> Optional[str]: + settings = Settings() + settings.parse( + "SECURE SETTINGS (user 0)\n" + "_id:240 name:accessibility_enabled pkg:android value:1\n" + "\tHistory (accessibility_enabled)\n" + f"\t\ttime:{time} mode:update oldValue:0 newValue:1 " + "package:com.example.helper\n" + "\n" + "--------- 0.019s was the duration of dumpsys settings, " + f"ending at: {section_end}\n" + ) + return settings.results[0]["history"][0]["timestamp"] + + class TestSettingsArtifact: def test_parsing(self): settings = parse_bugreport_settings() @@ -159,6 +176,24 @@ class TestSettingsArtifact: } ] + def test_leap_day_history_keeps_its_timestamp(self): + assert ( + resolve_history_time("02-29 22:41:07.980", "2024-03-05 23:14:28") + == "2024-02-29 22:41:07.980000" + ) + + def test_leap_day_history_resolved_to_the_last_leap_year(self): + # The most recent 29 February at or before the dump can be several + # years back when the dump was taken in a year without one. + assert ( + resolve_history_time("02-29 22:41:07.980", "2025-03-01 10:00:00") + == "2024-02-29 22:41:07.980000" + ) + assert ( + resolve_history_time("02-29 22:41:07.980", "2024-01-10 10:00:00") + == "2020-02-29 22:41:07.980000" + ) + def test_dangerous_setting_is_detected_with_the_changing_package(self): settings = parse_bugreport_settings() settings.check_indicators() From 1e05f438d7c952300b646372d6f894da96358e8c Mon Sep 17 00:00:00 2001 From: besendorf Date: Fri, 9 Oct 2026 03:48:37 -0700 Subject: [PATCH 6/7] Include the eighth prior year when resolving settings leap days Adjust the year range for leap year calculation to account for century years. --- src/mvt/android/artifacts/settings.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/mvt/android/artifacts/settings.py b/src/mvt/android/artifacts/settings.py index 8237ee34..91b357d6 100644 --- a/src/mvt/android/artifacts/settings.py +++ b/src/mvt/android/artifacts/settings.py @@ -257,13 +257,14 @@ class Settings(AndroidArtifact): at or before that time. The year is parsed together with the value, because strptime() would - otherwise parse it in 1900, which has no 29 February. Going back eight - years always reaches a leap year. + otherwise parse it in 1900, which has no 29 February. The most recent + matching leap day can be eight years earlier when a century year is + not a leap year and the current year's leap day is still in the future. """ if section_end is None: return None - for year in range(section_end.year, section_end.year - 8, -1): + for year in range(section_end.year, section_end.year - 9, -1): try: timestamp = datetime.strptime(f"{year}-{value}", "%Y-%m-%d %H:%M:%S.%f") except ValueError: From aac41ec8c24b8e64571018d5bf6bfa0bf1a4c9d7 Mon Sep 17 00:00:00 2001 From: besendorf Date: Fri, 9 Oct 2026 03:49:54 -0700 Subject: [PATCH 7/7] Test settings leap-day resolution across a skipped century Ensure a February 29 history entry in a January 2104 dump resolves to 2096, since 2100 is not a leap year. --- tests/android/test_artifact_settings.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/android/test_artifact_settings.py b/tests/android/test_artifact_settings.py index f114cab7..239490a2 100644 --- a/tests/android/test_artifact_settings.py +++ b/tests/android/test_artifact_settings.py @@ -194,6 +194,14 @@ class TestSettingsArtifact: == "2020-02-29 22:41:07.980000" ) + def test_leap_day_history_before_a_leap_day_after_a_skipped_century(self): + # 2100 is not a leap year, so before 29 February 2104 the most + # recent matching date is eight years earlier, in 2096. + assert ( + resolve_history_time("02-29 22:41:07.980", "2104-01-10 10:00:00") + == "2096-02-29 22:41:07.980000" + ) + def test_dangerous_setting_is_detected_with_the_changing_package(self): settings = parse_bugreport_settings() settings.check_indicators()