mirror of
https://github.com/mvt-project/mvt.git
synced 2024-06-30 16:18:54 +00:00
Standardized to logging format
This commit is contained in:
parent
ec93c3d8b8
commit
88324c7c42
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import tarfile
|
import tarfile
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
@ -59,18 +58,20 @@ def decrypt_backup(ctx, destination, password, key_file, backup_path):
|
||||||
|
|
||||||
if key_file:
|
if key_file:
|
||||||
if PASSWD_ENV in os.environ:
|
if PASSWD_ENV in os.environ:
|
||||||
log.info(f"Ignoring {PASSWD_ENV} environment variable, using --key-file '{key_file}' instead")
|
log.info("Ignoring environment variable, using --key-file '%s' instead",
|
||||||
|
PASSWD_ENV, key_file)
|
||||||
|
|
||||||
backup.decrypt_with_key_file(key_file)
|
backup.decrypt_with_key_file(key_file)
|
||||||
elif password:
|
elif password:
|
||||||
log.info("Your password may be visible in the process table because it was supplied on the command line!")
|
log.info("Your password may be visible in the process table because it was supplied on the command line!")
|
||||||
|
|
||||||
if PASSWD_ENV in os.environ:
|
if PASSWD_ENV in os.environ:
|
||||||
log.info(f"Ignoring {PASSWD_ENV} environment variable, using --password argument instead")
|
log.info("Ignoring %s environment variable, using --password argument instead",
|
||||||
|
PASSWD_ENV)
|
||||||
|
|
||||||
backup.decrypt_with_password(password)
|
backup.decrypt_with_password(password)
|
||||||
elif PASSWD_ENV in os.environ:
|
elif PASSWD_ENV in os.environ:
|
||||||
log.info(f"Using password from {PASSWD_ENV} environment variable")
|
log.info("Using password from %s environment variable", PASSWD_ENV)
|
||||||
backup.decrypt_with_password(os.environ[PASSWD_ENV])
|
backup.decrypt_with_password(os.environ[PASSWD_ENV])
|
||||||
else:
|
else:
|
||||||
sekrit = Prompt.ask("Enter backup password", password=True)
|
sekrit = Prompt.ask("Enter backup password", password=True)
|
||||||
|
@ -99,9 +100,10 @@ def extract_key(password, backup_path, key_file):
|
||||||
log.info("Your password may be visible in the process table because it was supplied on the command line!")
|
log.info("Your password may be visible in the process table because it was supplied on the command line!")
|
||||||
|
|
||||||
if PASSWD_ENV in os.environ:
|
if PASSWD_ENV in os.environ:
|
||||||
log.info(f"Ignoring {PASSWD_ENV} environment variable, using --password argument instead")
|
log.info("Ignoring %s environment variable, using --password argument instead",
|
||||||
|
PASSWD_ENV)
|
||||||
elif PASSWD_ENV in os.environ:
|
elif PASSWD_ENV in os.environ:
|
||||||
log.info(f"Using password from {PASSWD_ENV} environment variable")
|
log.info("Using password from %s environment variable", PASSWD_ENV)
|
||||||
password = os.environ[PASSWD_ENV]
|
password = os.environ[PASSWD_ENV]
|
||||||
else:
|
else:
|
||||||
password = Prompt.ask("Enter backup password", password=True)
|
password = Prompt.ask("Enter backup password", password=True)
|
||||||
|
@ -123,7 +125,8 @@ def extract_key(password, backup_path, key_file):
|
||||||
@click.option("--list-modules", "-l", is_flag=True, help="Print list of available modules and exit")
|
@click.option("--list-modules", "-l", is_flag=True, help="Print list of available modules and exit")
|
||||||
@click.option("--module", "-m", help="Name of a single module you would like to run instead of all")
|
@click.option("--module", "-m", help="Name of a single module you would like to run instead of all")
|
||||||
@click.argument("BACKUP_PATH", type=click.Path(exists=True))
|
@click.argument("BACKUP_PATH", type=click.Path(exists=True))
|
||||||
def check_backup(iocs, output, fast, backup_path, list_modules, module):
|
@click.pass_context
|
||||||
|
def check_backup(ctx, iocs, output, fast, backup_path, list_modules, module):
|
||||||
if list_modules:
|
if list_modules:
|
||||||
log.info("Following is the list of available check-backup modules:")
|
log.info("Following is the list of available check-backup modules:")
|
||||||
for backup_module in BACKUP_MODULES:
|
for backup_module in BACKUP_MODULES:
|
||||||
|
@ -138,7 +141,7 @@ def check_backup(iocs, output, fast, backup_path, list_modules, module):
|
||||||
os.makedirs(output)
|
os.makedirs(output)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.critical("Unable to create output folder %s: %s", output, e)
|
log.critical("Unable to create output folder %s: %s", output, e)
|
||||||
sys.exit(-1)
|
ctx.exit(1)
|
||||||
|
|
||||||
if iocs:
|
if iocs:
|
||||||
# Pre-load indicators for performance reasons.
|
# Pre-load indicators for performance reasons.
|
||||||
|
@ -180,7 +183,8 @@ def check_backup(iocs, output, fast, backup_path, list_modules, module):
|
||||||
@click.option("--list-modules", "-l", is_flag=True, help="Print list of available modules and exit")
|
@click.option("--list-modules", "-l", is_flag=True, help="Print list of available modules and exit")
|
||||||
@click.option("--module", "-m", help="Name of a single module you would like to run instead of all")
|
@click.option("--module", "-m", help="Name of a single module you would like to run instead of all")
|
||||||
@click.argument("DUMP_PATH", type=click.Path(exists=True))
|
@click.argument("DUMP_PATH", type=click.Path(exists=True))
|
||||||
def check_fs(iocs, output, fast, dump_path, list_modules, module):
|
@click.pass_context
|
||||||
|
def check_fs(ctx, iocs, output, fast, dump_path, list_modules, module):
|
||||||
if list_modules:
|
if list_modules:
|
||||||
log.info("Following is the list of available check-fs modules:")
|
log.info("Following is the list of available check-fs modules:")
|
||||||
for fs_module in FS_MODULES:
|
for fs_module in FS_MODULES:
|
||||||
|
@ -195,7 +199,7 @@ def check_fs(iocs, output, fast, dump_path, list_modules, module):
|
||||||
os.makedirs(output)
|
os.makedirs(output)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.critical("Unable to create output folder %s: %s", output, e)
|
log.critical("Unable to create output folder %s: %s", output, e)
|
||||||
sys.exit(-1)
|
ctx.exit(1)
|
||||||
|
|
||||||
if iocs:
|
if iocs:
|
||||||
# Pre-load indicators for performance reasons.
|
# Pre-load indicators for performance reasons.
|
||||||
|
|
|
@ -81,10 +81,12 @@ class DecryptBackup:
|
||||||
possible = glob.glob(os.path.join(self.backup_path, "*", "Manifest.plist"))
|
possible = glob.glob(os.path.join(self.backup_path, "*", "Manifest.plist"))
|
||||||
if len(possible) == 1:
|
if len(possible) == 1:
|
||||||
newpath = os.path.dirname(possible[0])
|
newpath = os.path.dirname(possible[0])
|
||||||
log.warning(f"No Manifest.plist in {self.backup_path}, using {newpath} instead.")
|
log.warning("No Manifest.plist in %s, using %s instead.",
|
||||||
|
self.backup_path, newpath)
|
||||||
self.backup_path = newpath
|
self.backup_path = newpath
|
||||||
elif len(possible) > 1:
|
elif len(possible) > 1:
|
||||||
log.critical(f"No Manifest.plist in {self.backup_path}, and {len(possible)} Manifest.plist files in subdirs. Please choose one!")
|
log.critical("No Manifest.plist in %s, and %d Manifest.plist files in subdirs. Please choose one!",
|
||||||
|
self.backup_path, len(possible))
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
self._backup = iOSbackup(udid=os.path.basename(self.backup_path),
|
self._backup = iOSbackup(udid=os.path.basename(self.backup_path),
|
||||||
|
@ -94,7 +96,8 @@ class DecryptBackup:
|
||||||
if isinstance(e, KeyError) and len(e.args) > 0 and e.args[0] == b"KEY":
|
if isinstance(e, KeyError) and len(e.args) > 0 and e.args[0] == b"KEY":
|
||||||
log.critical("Failed to decrypt backup. Password is probably wrong.")
|
log.critical("Failed to decrypt backup. Password is probably wrong.")
|
||||||
elif isinstance(e, FileNotFoundError) and os.path.basename(e.filename) == "Manifest.plist":
|
elif isinstance(e, FileNotFoundError) and os.path.basename(e.filename) == "Manifest.plist":
|
||||||
log.critical(f"Failed to find a valid backup at {self.backup_path}. Did you point to the right backup path?")
|
log.critical("Failed to find a valid backup at %s. Did you point to the right backup path?",
|
||||||
|
self.backup_path)
|
||||||
else:
|
else:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
log.critical("Failed to decrypt backup. Did you provide the correct password? Did you point to the right backup path?")
|
log.critical("Failed to decrypt backup. Did you provide the correct password? Did you point to the right backup path?")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user