-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpie.py
58 lines (42 loc) · 1.72 KB
/
pie.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""Extract Indicators of Compromise (IOCs) from PDF documents."""
import argparse
from pathlib import Path
from rich.console import Console
from utils.helpers import Helpers
from utils.worker import PDFWorker
helper = Helpers()
console = Console(highlight=False)
# Base directory
root = Path(__file__).resolve().parent
class FileMissingError(Exception):
"""Custom exception for missing file."""
def __init__(self, pdf_doc: argparse.Namespace) -> None:
"""Initializes the FileMissingError class."""
super().__init__(f"[ERROR] No such file: {pdf_doc}")
def main() -> None:
"""Main function that takes in command line arguments for a PDF document and extracts IOCs.
Raises:
FileMissingError: If the file does not exist.
"""
parser = argparse.ArgumentParser(description="PDF IOC Extractor")
parser.add_argument(dest="pdf_doc", help="Path to single PDF document")
parser.add_argument("-o", "--out", dest="output", action="store_true", help="Write output to file")
args = parser.parse_args()
# Check if pdf file exists
if not Path(args.pdf_doc).exists():
raise FileMissingError(args.pdf_doc)
title = Path(args.pdf_doc).name # get filename for report title
worker = PDFWorker() # instantiate PDFWorker class
worker.tlds_file() # check for the tlds file and download if needed.
worker.processor(pdfdoc=args.pdf_doc, output=args.output, title=title) # process PDF document
if __name__ == "__main__":
BANNER = r"""
____ ____ ______
/ __ \ / _/ / ____/
/ /_/ / / / / __/
/ ____/ _/ / / /___
/_/ /___/ /_____/
PDF IOC Extractor
"""
console.print(f"{BANNER}", style="cyan bold")
main()