Dependency Checking (#75)

* Adds req testing methodology, needs fixes

* Improves dependency exception handling

* Better meets_requirements implementation

Still need to adjust tests to fake installation

* Changes to exception boolean to enable tool check

tests and class variables modified for new tool check

* Adjust test_get_scans to use appropriate variable

* Adds Go requirement where relevant

* Adds missing scan dependencies

* Add clarification to error message
This commit is contained in:
Ryan Good
2020-08-07 08:48:49 -05:00
committed by GitHub
parent d97315a2da
commit d7dbd1e7b3
21 changed files with 181 additions and 165 deletions

View File

@@ -6,11 +6,29 @@ import pkgutil
import importlib
import ipaddress
from pathlib import Path
from cmd2.ansi import style
from collections import defaultdict
from ..recon.config import defaults
def meets_requirements(requirements, exception):
""" Determine if tools required to perform task are installed. """
tools = get_tool_state()
for tool in requirements:
if not tools.get(tool).get("installed"):
if exception:
raise RuntimeError(
style(f"[!!] {tool} is not installed, and is required to run this scan", fg="bright_red")
)
else:
return False
return True
def get_tool_state() -> typing.Union[dict, None]:
""" Load current tool state from disk. """
tools = Path(defaults.get("tools-dir")) / ".tool-dict.pkl"
@@ -60,7 +78,9 @@ def get_scans():
# final check, this ensures that the tools necessary to AT LEAST run this scan are present
# does not consider upstream dependencies
try:
if not sub_obj.meets_requirements():
requirements = sub_obj.requirements
exception = False # let meets_req know we want boolean result
if not meets_requirements(requirements, exception):
continue
except AttributeError:
# some scan's haven't implemented meets_requirements yet, silently allow them through