2022-02-02 00:09:53 +01:00
|
|
|
# Mobile Verification Toolkit (MVT)
|
2022-05-08 14:53:50 +02:00
|
|
|
# Copyright (c) 2021-2022 Claudio Guarnieri.
|
2022-02-02 00:09:53 +01:00
|
|
|
# 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
|
2022-08-16 13:39:55 +02:00
|
|
|
from typing import Optional
|
2022-02-02 00:09:53 +01:00
|
|
|
|
2022-02-02 21:58:11 +01:00
|
|
|
from mvt.android.parsers import parse_dumpsys_activity_resolver_table
|
2022-02-02 22:00:48 +01:00
|
|
|
|
2022-02-02 00:09:53 +01:00
|
|
|
from .base import BugReportModule
|
|
|
|
|
|
|
|
|
|
|
|
class Activities(BugReportModule):
|
|
|
|
"""This module extracts details on receivers for risky activities."""
|
|
|
|
|
2022-08-16 13:39:55 +02:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
file_path: Optional[str] = "",
|
|
|
|
target_path: Optional[str] = "",
|
|
|
|
results_path: Optional[str] = "",
|
|
|
|
fast_mode: Optional[bool] = False,
|
|
|
|
log: logging.Logger = logging.getLogger(__name__),
|
|
|
|
results: Optional[list] = []
|
|
|
|
) -> None:
|
2022-06-15 17:41:19 +02:00
|
|
|
super().__init__(file_path=file_path, target_path=target_path,
|
|
|
|
results_path=results_path, fast_mode=fast_mode,
|
2022-02-02 00:09:53 +01:00
|
|
|
log=log, results=results)
|
|
|
|
|
|
|
|
self.results = results if results else {}
|
|
|
|
|
2022-06-17 22:30:46 +02:00
|
|
|
def check_indicators(self) -> None:
|
2022-02-02 00:09:53 +01:00
|
|
|
if not self.indicators:
|
|
|
|
return
|
|
|
|
|
|
|
|
for intent, activities in self.results.items():
|
|
|
|
for activity in activities:
|
|
|
|
ioc = self.indicators.check_app_id(activity["package_name"])
|
|
|
|
if ioc:
|
|
|
|
activity["matched_indicator"] = ioc
|
|
|
|
self.detected.append({intent: activity})
|
|
|
|
continue
|
|
|
|
|
2022-06-17 22:30:46 +02:00
|
|
|
def run(self) -> None:
|
2022-02-04 13:34:40 +01:00
|
|
|
content = self._get_dumpstate_file()
|
2022-02-02 00:09:53 +01:00
|
|
|
if not content:
|
2022-08-16 13:39:55 +02:00
|
|
|
self.log.error("Unable to find dumpstate file. "
|
|
|
|
"Did you provide a valid bug report archive?")
|
2022-02-02 00:09:53 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
lines = []
|
2022-02-02 15:47:55 +01:00
|
|
|
in_package = False
|
2022-02-03 19:40:36 +01:00
|
|
|
for line in content.decode(errors="ignore").splitlines():
|
2022-02-02 00:09:53 +01:00
|
|
|
if line.strip() == "DUMP OF SERVICE package:":
|
2022-02-02 15:47:55 +01:00
|
|
|
in_package = True
|
2022-02-02 00:09:53 +01:00
|
|
|
continue
|
|
|
|
|
2022-02-02 15:47:55 +01:00
|
|
|
if not in_package:
|
2022-02-02 00:09:53 +01:00
|
|
|
continue
|
|
|
|
|
2022-02-03 19:55:18 +01:00
|
|
|
if line.strip().startswith("------------------------------------------------------------------------------"):
|
2022-02-02 00:09:53 +01:00
|
|
|
break
|
|
|
|
|
|
|
|
lines.append(line)
|
|
|
|
|
2022-02-02 21:58:11 +01:00
|
|
|
self.results = parse_dumpsys_activity_resolver_table("\n".join(lines))
|
2022-02-03 19:55:18 +01:00
|
|
|
|
|
|
|
self.log.info("Extracted activities for %d intents", len(self.results))
|