mvt/mvt/ios/modules/mixed/whatsapp.py

83 lines
2.9 KiB
Python
Raw Normal View History

2021-07-16 06:05:01 +00:00
# Mobile Verification Toolkit (MVT)
# Copyright (c) 2021 The MVT Project Authors.
# Use of this software is governed by the MVT License 1.1 that can be found at
# https://license.mvt.re/1.1/
2021-07-16 06:05:01 +00:00
import logging
2021-07-30 09:40:09 +00:00
import sqlite3
2021-07-16 06:05:01 +00:00
2021-07-30 09:40:09 +00:00
from mvt.common.utils import (check_for_links, convert_mactime_to_unix,
convert_timestamp_to_iso)
2021-07-16 06:05:01 +00:00
2021-08-15 11:14:18 +00:00
from ..base import IOSExtraction
2021-07-16 06:05:01 +00:00
log = logging.getLogger(__name__)
WHATSAPP_BACKUP_IDS = [
"7c7fba66680ef796b916b067077cc246adacf01d",
]
WHATSAPP_ROOT_PATHS = [
"private/var/mobile/Containers/Shared/AppGroup/*/ChatStorage.sqlite",
]
2021-11-19 14:27:51 +00:00
2021-07-16 06:05:01 +00:00
class Whatsapp(IOSExtraction):
"""This module extracts all WhatsApp messages containing links."""
def __init__(self, file_path=None, base_folder=None, output_folder=None,
fast_mode=False, log=None, results=[]):
super().__init__(file_path=file_path, base_folder=base_folder,
output_folder=output_folder, fast_mode=fast_mode,
log=log, results=results)
def serialize(self, record):
2021-08-16 08:50:35 +00:00
text = record.get("ZTEXT", "").replace("\n", "\\n")
2021-07-16 06:05:01 +00:00
return {
2021-08-16 08:50:35 +00:00
"timestamp": record.get("isodate"),
2021-07-16 06:05:01 +00:00
"module": self.__class__.__name__,
"event": "message",
2021-08-16 08:50:35 +00:00
"data": f"{text} from {record.get('ZFROMJID', 'Unknown')}",
2021-07-16 06:05:01 +00:00
}
def check_indicators(self):
if not self.indicators:
return
for message in self.results:
2021-08-16 08:50:35 +00:00
message_links = check_for_links(message.get("ZTEXT", ""))
2021-07-16 06:05:01 +00:00
if self.indicators.check_domains(message_links):
self.detected.append(message)
def run(self):
2021-08-16 08:50:35 +00:00
self._find_ios_database(backup_ids=WHATSAPP_BACKUP_IDS,
root_paths=WHATSAPP_ROOT_PATHS)
2021-07-16 06:05:01 +00:00
log.info("Found WhatsApp database at path: %s", self.file_path)
conn = sqlite3.connect(self.file_path)
cur = conn.cursor()
cur.execute("SELECT * FROM ZWAMESSAGE;")
names = [description[0] for description in cur.description]
for message in cur:
2021-08-15 17:05:15 +00:00
new_message = {}
2021-07-16 06:05:01 +00:00
for index, value in enumerate(message):
new_message[names[index]] = value
2021-08-16 08:50:35 +00:00
if not new_message.get("ZTEXT", None):
2021-07-16 06:05:01 +00:00
continue
# We convert Mac's silly timestamp again.
2021-08-16 08:50:35 +00:00
new_message["isodate"] = convert_timestamp_to_iso(convert_mactime_to_unix(new_message.get("ZMESSAGEDATE")))
2021-07-16 06:05:01 +00:00
# Extract links from the WhatsApp message.
message_links = check_for_links(new_message["ZTEXT"])
2021-07-22 21:21:31 +00:00
# If we find messages, or if there's an empty message we add it to the list.
2021-07-16 06:05:01 +00:00
if new_message["ZTEXT"] and (message_links or new_message["ZTEXT"].strip() == ""):
self.results.append(new_message)
cur.close()
conn.close()
log.info("Extracted a total of %d WhatsApp messages containing links", len(self.results))