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

Warn user if they're trying to hurt themselves #75

Merged
merged 2 commits into from
May 24, 2022
Merged
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
17 changes: 16 additions & 1 deletion malduck/extractor/extract_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,18 @@ def __init__(self, modules_path: Optional[str] = None) -> None:
# Load Yara rules
self.rules: Yara = Yara.from_dir(modules_path)
# Preload modules
load_modules(modules_path, onerror=self.on_error)
loaded_modules = load_modules(modules_path, onerror=self.on_error)
self.extractors: List[Type[Extractor]] = Extractor.__subclasses__()

loaded_extractors = [x.__module__ for x in self.extractors]

for module in loaded_modules.values():
module_name = module.__name__
if not any(x.startswith(module_name) for x in loaded_extractors):
warnings.warn(
f"The extractor engine couldn't import any Extractors from module {module_name}. Make sure the Extractor class is imported into __init__.py",
)

def on_error(self, exc: Exception, module_name: str) -> None:
"""
Handler for all exceptions raised during module load
Expand Down Expand Up @@ -313,6 +322,12 @@ def push_procmem(
# For each extractor...
for ext_class in self.parent.extractors:
extractor = ext_class(self)

if type(extractor.yara_rules) is str:
raise TypeError(
f'"{extractor.__class__.__name__}.yara_rules" cannot be a string, convert it into a list of strings'
)

# For each rule identifier in extractor.yara_rules...
for rule in extractor.yara_rules:
if rule in matches:
Expand Down