Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Addition of a timer to virustotal checks #593

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/mvt/android/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
HELP_MSG_HASHES,
HELP_MSG_CHECK_IOCS,
HELP_MSG_STIX2,
HELP_MSG_DELAY_CHECKS,
)
from mvt.common.logo import logo
from mvt.common.updates import IndicatorsUpdates
Expand Down Expand Up @@ -78,13 +79,14 @@ def version():
@click.option("--serial", "-s", type=str, help=HELP_MSG_SERIAL)
@click.option("--all-apks", "-a", is_flag=True, help=HELP_MSG_DOWNLOAD_ALL_APKS)
@click.option("--virustotal", "-V", is_flag=True, help=HELP_MSG_VIRUS_TOTAL)
@click.option("--delay", "-d", type=int, default=16, help=HELP_MSG_DELAY_CHECKS)
@click.option("--output", "-o", type=click.Path(exists=False), help=HELP_MSG_APK_OUTPUT)
@click.option(
"--from-file", "-f", type=click.Path(exists=True), help=HELP_MSG_APKS_FROM_FILE
)
@click.option("--verbose", "-v", is_flag=True, help=HELP_MSG_VERBOSE)
@click.pass_context
def download_apks(ctx, all_apks, virustotal, output, from_file, serial, verbose):
def download_apks(ctx, all_apks, virustotal, output, from_file, serial, verbose, delay):
set_verbose_logging(verbose)
try:
if from_file:
Expand Down Expand Up @@ -114,7 +116,11 @@ def download_apks(ctx, all_apks, virustotal, output, from_file, serial, verbose)

if virustotal:
m = Packages()
m.check_virustotal(packages_to_lookup)
if delay:
m.check_virustotal(packages_to_lookup, delay)
else:
delay = 0
m.check_virustotal(packages_to_lookup, delay)
except KeyboardInterrupt:
print("")
ctx.exit(1)
Expand Down
10 changes: 8 additions & 2 deletions src/mvt/android/modules/adb/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# https://license.mvt.re/1.1/

import logging
import time
from typing import Optional, Union

from rich.console import Console
Expand Down Expand Up @@ -109,7 +110,7 @@ def check_indicators(self) -> None:
self.detected.append(result)

@staticmethod
def check_virustotal(packages: list) -> None:
def check_virustotal(packages: list, delay: int) -> None:
hashes = []
for package in packages:
for file in package.get("files", []):
Expand All @@ -132,6 +133,8 @@ def check_virustotal(packages: list) -> None:
if not results:
continue

time.sleep(delay)

positives = results["attributes"]["last_analysis_stats"]["malicious"]
total = len(results["attributes"]["last_analysis_results"])

Expand Down Expand Up @@ -303,7 +306,10 @@ def run(self) -> None:
)

if not self.module_options.get("fast_mode", None):
self.check_virustotal(packages_to_lookup)
if "delay" not in locals():
delay = 0

self.check_virustotal(packages_to_lookup, delay)

self.log.info(
"Extracted at total of %d installed package names", len(self.results)
Expand Down
1 change: 1 addition & 0 deletions src/mvt/common/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Extract all packages installed on the phone, including system packages"
)
HELP_MSG_VIRUS_TOTAL = "Check packages on VirusTotal"
HELP_MSG_DELAY_CHECKS = "Throttle virustotal checks to not exhaust the queries limit"
HELP_MSG_APK_OUTPUT = "Specify a path to a folder where you want to store the APKs"
HELP_MSG_APKS_FROM_FILE = (
"Instead of acquiring APKs from a phone, load an existing packages.json file for "
Expand Down