36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
|
|
from detections import *
|
||
|
|
from console import console
|
||
|
|
|
||
|
|
from rich.table import Table
|
||
|
|
from time import time
|
||
|
|
|
||
|
|
|
||
|
|
class Scanner:
|
||
|
|
def __init__(self):
|
||
|
|
self.detections = {
|
||
|
|
"Hash Detection": Hash(),
|
||
|
|
"Yara Pattern Matching": Yara(),
|
||
|
|
"Heuristics": Heuristics()
|
||
|
|
}
|
||
|
|
|
||
|
|
def scan_file(self, file_path: str):
|
||
|
|
with console.status(f"Scanning {file_path}...") as status:
|
||
|
|
f = open(file_path, "rb")
|
||
|
|
contents = f.read()
|
||
|
|
|
||
|
|
|
||
|
|
table = Table("Scan", "Match")
|
||
|
|
|
||
|
|
for name, detection in self.detections.items():
|
||
|
|
start_time = time()
|
||
|
|
console.print(f"[d]Running {name}..", end='\r')
|
||
|
|
|
||
|
|
match = detection.run(contents, f)
|
||
|
|
table.add_row(name, "[bold orange1]⚠️ Match" if match else "[bold green]✅ Clean")
|
||
|
|
|
||
|
|
console.print(f"Running {name}.. [d]({round(time()-start_time, 3)}s)", highlight=False)
|
||
|
|
|
||
|
|
f.close()
|
||
|
|
|
||
|
|
print()
|
||
|
|
console.print(table)
|