From 2389d5e52d5a8c7d16edc7b68b9f10176e48b496 Mon Sep 17 00:00:00 2001 From: Hamza Z Date: Wed, 21 Jul 2021 13:35:46 +0200 Subject: [PATCH] Add Android TCP connection support --- mvt/android/cli.py | 2 +- mvt/android/modules/adb/base.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/mvt/android/cli.py b/mvt/android/cli.py index f8c37a8..38832e6 100644 --- a/mvt/android/cli.py +++ b/mvt/android/cli.py @@ -49,7 +49,7 @@ def cli(): help="Specify a path to a folder where you want to store JSON results") @click.option("--from-file", "-f", type=click.Path(exists=True), help="Instead of acquiring from phone, load an existing packages.json file for lookups (mainly for debug purposes)") -@click.option("--serial", "-s", type=str, help="Use the Android device with a given serial") +@click.option("--serial", "-s", type=str, help="Use the Android device with a given serial number") def download_apks(all_apks, virustotal, koodous, all_checks, output, from_file, serial): try: if from_file: diff --git a/mvt/android/modules/adb/base.py b/mvt/android/modules/adb/base.py index e39fcf9..ea0abe5 100644 --- a/mvt/android/modules/adb/base.py +++ b/mvt/android/modules/adb/base.py @@ -8,7 +8,7 @@ import sys import time import logging import tempfile -from adb_shell.adb_device import AdbDeviceUsb +from adb_shell.adb_device import AdbDeviceUsb, AdbDeviceTcp from adb_shell.auth.keygen import keygen, write_public_keyfile from adb_shell.auth.sign_pythonrsa import PythonRSASigner from adb_shell.exceptions import DeviceAuthError, AdbCommandFailureException @@ -58,7 +58,15 @@ class AndroidExtraction(MVTModule): signer = PythonRSASigner("", priv_key) - self.device = AdbDeviceUsb(serial=self.serial) + if self.serial is None or ":" not in self.serial: + self.device = AdbDeviceUsb(serial=self.serial) + else: + addr = self.serial.split(":") + + if len(addr) < 2: + raise ValueError("TCP serial number must follow the format: `address:port`") + + self.device = AdbDeviceTcp(addr[0], int(addr[1]), default_transport_timeout_s=9.) while True: try: