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

refactor: replace argparse with click and pyfiglet with const 🪥 #35

Merged
merged 2 commits into from
Jan 8, 2024
Merged
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
8 changes: 8 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,13 @@ jobs:
run: |
.\dist\ms_teams_parser.exe -f ".\forensicsim-data\jane_doe_old_teams\IndexedDB\https_teams.microsoft.com_0.indexeddb.leveldb" -o "jane_doe.json"
.\dist\ms_teams_parser.exe -f ".\forensicsim-data\john_doe_old_teams\IndexedDB\https_teams.microsoft.com_0.indexeddb.leveldb" -o "john_doe.json"
- name: Test calling script 📞
run: |
python utils/dump_leveldb.py --help
python utils/dump_localstorage.py --help
python utils/dump_sessionstorage.py --help
# python utils/populate_teams.py --help
# python utils/populate_teams_2.py --help
# python utils/populate_skype.py --help
# - name: Calculate diff 👽
# run: git diff --no-index --word-diff expected_output/john_doe.json current_output.json
2 changes: 1 addition & 1 deletion main.spec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ block_cipher = None

a = Analysis(['utils\\main.py'],
binaries=[],
datas=[('c:/hostedtoolcache/windows/python/3.9.13/x64/lib/site-packages/pyfiglet', 'pyfiglet')],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
Expand Down
8 changes: 5 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
chardet~=4.0.0
pyfiglet~=0.8.post1
colorama~=0.4.4
beautifulsoup4~=4.9.3
chardet~=4.0.0
click~=8.0.1
colorama~=0.4.4
pause~=0.3
pyautogui~=0.9.54
pywinauto~=0.6.8
35 changes: 35 additions & 0 deletions utils/consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
XTRACT_HEADER = """
_____ _ _
| ___|__ _ __ ___ _ __ ___(_) ___ ___ (_)_ __ ___
| |_ / _ \| '__/ _ \ '_ \/ __| |/ __/ __| | | '_ ` _ \\
| _| (_) | | | __/ | | \__ \ | (__\__ \_| | | | | | |
|_| \___/|_| \___|_| |_|___/_|\___|___(_)_|_| |_| |_|
__ ___ _ _____ _
\ \/ / |_ _ __ __ _ ___| |_ |_ _|__ ___ | |
\ /| __| '__/ _` |/ __| __| | |/ _ \ / _ \| |
/ \| |_| | | (_| | (__| |_ | | (_) | (_) | |
/_/\_\\\\__|_| \__,_|\___|\__| |_|\___/ \___/|_|
"""
UTIL_HEADER = """
_____ _ _ _ _ _ _ _
| ___|__ _ __ ___ _ __ ___(_) ___ ___ (_)_ __ ___ | | | | |_(_) |
| |_ / _ \| '__/ _ \ '_ \/ __| |/ __/ __| | | '_ ` _ \ | | | | __| | |
| _| (_) | | | __/ | | \__ \ | (__\__ \_| | | | | | | | |_| | |_| | |
|_| \___/|_| \___|_| |_|___/_|\___|___(_)_|_| |_| |_| \___/ \__|_|_|

"""

DUMP_HEADER = """
_____ _ _
| ___|__ _ __ ___ _ __ ___(_) ___ ___ (_)_ __ ___
| |_ / _ \| '__/ _ \ '_ \/ __| |/ __/ __| | | '_ ` _ \
| _| (_) | | | __/ | | \__ \ | (__\__ \_| | | | | | |
|_| \___/|_| \___|_| |_|___/_|\___|___(_)_|_| |_| |_|

____ _____ _
| _ \ _ _ _ __ ___ _ __ |_ _|__ ___ | |
| | | | | | | '_ ` _ \| '_ \ | |/ _ \ / _ \| |
| |_| | |_| | | | | | | |_) | | | (_) | (_) | |
|____/ \__,_|_| |_| |_| .__/ |_|\___/ \___/|_|
|_|
"""
73 changes: 31 additions & 42 deletions utils/dump_leveldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,56 +24,45 @@

from pathlib import Path

import argparse
import pyfiglet
import pyfiglet.fonts
import click

import shared
from consts import DUMP_HEADER
from shared import parse_db, write_results_to_json


def process_db(filepath, output_path):
def process_db(input_path, output_path):
# Do some basic error handling
if not filepath.endswith("leveldb"):
raise Exception("Expected a leveldb folder. Path: {}".format(filepath))

p = Path(filepath)
if not p.exists():
raise Exception("Given file path does not exists. Path: {}".format(filepath))

if not p.is_dir():
raise Exception("Given file path is not a folder. Path: {}".format(filepath))
if not input_path.parts[-1].endswith(".leveldb"):
raise ValueError(f"Expected a leveldb folder. Path: {input_path}")

# convert the database to a python list with nested dictionaries
extracted_values = shared.parse_db(filepath, True)
extracted_values = parse_db(input_path, do_not_filter=True)

# write the output to a json file
shared.write_results_to_json(extracted_values, output_path)


def run(args):
process_db(args.filepath, args.outputpath)


def parse_cmdline():
description = "Forensics.im Dump Tool"
parser = argparse.ArgumentParser(description=description)
required_group = parser.add_argument_group("required arguments")
required_group.add_argument(
"-f", "--filepath", required=True, help="File path to the IndexedDB."
)
required_group.add_argument(
"-o", "--outputpath", required=True, help="File path to the processed output."
)
args = parser.parse_args()
return args


def cli():
header = pyfiglet.figlet_format("Forensics.im Dump Tool")
print(header)
args = parse_cmdline()
run(args)
write_results_to_json(extracted_values, output_path)


@click.command()
@click.option(
"-f",
"--filepath",
type=click.Path(
exists=True, readable=True, writable=False, dir_okay=True, path_type=Path
),
required=True,
help="File path to the IndexedDB.",
)
@click.option(
"-o",
"--outputpath",
type=click.Path(writable=True, path_type=Path),
required=True,
help="File path to the processed output.",
)
def process_cmd(filepath, outputpath):
click.echo(DUMP_HEADER)
process_db(filepath, outputpath)


if __name__ == "__main__":
cli()
process_cmd()
80 changes: 32 additions & 48 deletions utils/dump_localstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,54 +24,38 @@

from pathlib import Path

import argparse
import pyfiglet
import pyfiglet.fonts

import shared


def process_db(filepath, output_path):
# Do some basic error handling

p = Path(filepath)
if not p.exists():
raise Exception("Given file path does not exists. Path: {}".format(filepath))

if not p.is_dir():
raise Exception("Given file path is not a folder. Path: {}".format(filepath))

# convert the database to a python list with nested dictionaries
extracted_values = shared.parse_localstorage(p)

# write the output to a json file
shared.write_results_to_json(extracted_values, output_path)


def run(args):
process_db(args.filepath, args.outputpath)


def parse_cmdline():
description = "Forensics.im Dump Local Storage"
parser = argparse.ArgumentParser(description=description)
required_group = parser.add_argument_group("required arguments")
required_group.add_argument(
"-f", "--filepath", required=True, help="File path to the IndexedDB."
)
required_group.add_argument(
"-o", "--outputpath", required=True, help="File path to the processed output."
)
args = parser.parse_args()
return args


def cli():
header = pyfiglet.figlet_format("Forensics.im Dump Tool")
print(header)
args = parse_cmdline()
run(args)
import click

from shared import parse_localstorage, write_results_to_json
from consts import DUMP_HEADER


def process_db(filepath: Path, output_path: Path):
extracted_values = parse_localstorage(filepath)
write_results_to_json(extracted_values, output_path)


@click.command()
@click.option(
"-f",
"--filepath",
type=click.Path(
exists=True, readable=True, writable=False, dir_okay=True, path_type=Path
),
required=True,
help="File path to the IndexedDB.",
)
@click.option(
"-o",
"--outputpath",
type=click.Path(writable=True, path_type=Path),
required=True,
help="File path to the processed output.",
)
def process_cmd(filepath: Path, outputpath: Path):
click.echo(DUMP_HEADER)
process_db(filepath, outputpath)


if __name__ == "__main__":
cli()
process_cmd()
81 changes: 32 additions & 49 deletions utils/dump_sessionstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,55 +24,38 @@

from pathlib import Path

import argparse
import pyfiglet
import pyfiglet.fonts

import shared


def process_db(filepath, output_path):
# Do some basic error handling

p = Path(filepath)
if not p.exists():
raise Exception("Given file path does not exists. Path: {}".format(filepath))

if not p.is_dir():
raise Exception("Given file path is not a folder. Path: {}".format(filepath))

# convert the database to a python list with nested dictionaries
#
extracted_values = shared.parse_sessionstorage(p)

# write the output to a json file
shared.write_results_to_json(extracted_values, output_path)


def run(args):
process_db(args.filepath, args.outputpath)


def parse_cmdline():
description = "Forensics.im Dump Session Storage"
parser = argparse.ArgumentParser(description=description)
required_group = parser.add_argument_group("required arguments")
required_group.add_argument(
"-f", "--filepath", required=True, help="File path to the IndexedDB."
)
required_group.add_argument(
"-o", "--outputpath", required=True, help="File path to the processed output."
)
args = parser.parse_args()
return args


def cli():
header = pyfiglet.figlet_format("Forensics.im Dump Tool")
print(header)
args = parse_cmdline()
run(args)
import click

from consts import DUMP_HEADER
from shared import parse_sessionstorage, write_results_to_json


def process_db(input_path: Path, output_path: Path):
extracted_values = parse_sessionstorage(input_path)
write_results_to_json(extracted_values, output_path)


@click.command()
@click.option(
"-f",
"--filepath",
type=click.Path(
exists=True, readable=True, writable=False, dir_okay=True, path_type=Path
),
required=True,
help="File path to the IndexedDB.",
)
@click.option(
"-o",
"--outputpath",
type=click.Path(writable=True, path_type=Path),
required=True,
help="File path to the processed output.",
)
def process_cmd(filepath, outputpath):
click.echo(DUMP_HEADER)
process_db(filepath, outputpath)


if __name__ == "__main__":
cli()
process_cmd()
Loading