Source code for expliot_finder.vulnerability_scanner.ui.scanner_progress_ui
"""UI used by all core 'vulnerability_scanner' modules."""
__all__ = ("display_scanning_progress",)
import asyncio
import dataclasses
from rich.console import Console
from rich.progress import Progress
from ..executor import VulnerabilityScannerExecutor
from ..captured_sensitive_target_info import CapturedSensitiveInfo
LAST_CAPTURED_INFO: dict[str, str] = {}
def display_captured_info(captured_sensitive_info: CapturedSensitiveInfo, console: Console) -> None:
"""Display captured information about the selected target in real time.
This function will not block the asynchronous 'vulnerability scanner' core
modules even if it will be called several times while them scanning chosen
target.
Args:
captured_sensitive_info:
Dataclass what stores discovered information about the target
what is currently scanning. The newly captured information will be
displayed by this function immediately.
console:
A high level console interface.
"""
global LAST_CAPTURED_INFO # pylint: disable=global-statement
if LAST_CAPTURED_INFO != captured_sensitive_info:
console.status("[bold green]Fetching vulnerability information's...")
for key, val in dict(captured_sensitive_info).items():
if key not in ("ports_services", "mac_vendor_name",
"mac_address") and val != "Unknown":
console.log(f"[green]Detected {key.upper()}: [yellow]{val}")
elif key == "mac_address" and val != "Unknown":
console.log(
f"[green]Detected {key.upper()}: [yellow]{val} "
f"({captured_sensitive_info.mac_vendor_name}"
)
LAST_CAPTURED_INFO = dataclasses.replace(captured_sensitive_info) # type: ignore
[docs]async def display_scanning_progress(executor: VulnerabilityScannerExecutor) -> None:
"""Display progress of scanning chosen target in real-time.
Show this below captured information about chosen the target to scan as text
in the console:
- IP
- OS name
- MAC address
- MAC vendor name
But for the progress of scanning ports in chosen target is shown as a status
bar. This the status bar will be updated on a regular basis while scanning
the next ports of the chosen target and will not block other scanners.
Args:
executor:
Instance of the class 'VulnerabilityScannerExecutor' what runs all
vulnerability scanner scanning modules.
"""
console = Console(log_path=False)
with Progress(console=console) as progress:
progress_status = progress.add_task(
f"[green]Scanning {executor.port_amount} ports...",
total=executor.port_amount
)
while executor.scanned_ports_count < executor.port_amount:
display_captured_info(executor.captured_sensitive_info, console)
progress.update(progress_status, advance=30)
await asyncio.sleep(1.2)