From b28f330e8f47e97cd95b9956b3f8615cff0d800f Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 14 Dec 2021 07:10:38 -0500 Subject: [PATCH] Agent: Remove duplicate functionality that checked for open port --- monkey/infection_monkey/master/ip_scanner.py | 10 +++------- monkey/infection_monkey/master/propagator.py | 12 ++---------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/monkey/infection_monkey/master/ip_scanner.py b/monkey/infection_monkey/master/ip_scanner.py index cf77ea54d..450ff3006 100644 --- a/monkey/infection_monkey/master/ip_scanner.py +++ b/monkey/infection_monkey/master/ip_scanner.py @@ -60,7 +60,7 @@ class IPScanner: port_scan_data = self._scan_tcp_ports(ip, tcp_ports, tcp_timeout, stop) fingerprint_data = {} - if IPScanner._found_open_port(port_scan_data): + if IPScanner.port_scan_found_open_port(port_scan_data): fingerprinters = options["fingerprinters"] fingerprint_data = self._run_fingerprinters( ip, fingerprinters, ping_scan_data, port_scan_data, stop @@ -92,12 +92,8 @@ class IPScanner: return port_scan_data @staticmethod - def _found_open_port(port_scan_data: Dict[int, PortScanData]): - for psd in port_scan_data.values(): - if psd.status == PortStatus.OPEN: - return True - - return False + def port_scan_found_open_port(port_scan_data: Dict[int, PortScanData]): + return any(psd.status == PortStatus.OPEN for psd in port_scan_data.values()) def _run_fingerprinters( self, diff --git a/monkey/infection_monkey/master/propagator.py b/monkey/infection_monkey/master/propagator.py index 0c3acea1d..916297110 100644 --- a/monkey/infection_monkey/master/propagator.py +++ b/monkey/infection_monkey/master/propagator.py @@ -55,12 +55,10 @@ class Propagator: victim_host = VictimHost(ip) Propagator._process_ping_scan_results(victim_host, scan_results.ping_scan_data) - has_open_port = Propagator._process_tcp_scan_results( - victim_host, scan_results.port_scan_data - ) + Propagator._process_tcp_scan_results(victim_host, scan_results.port_scan_data) Propagator._process_fingerprinter_results(victim_host, scan_results.fingerprint_data) - if has_open_port: + if IPScanner.port_scan_found_open_port(scan_results.port_scan_data): self._hosts_to_exploit.put(victim_host) self._telemetry_messenger.send_telemetry(ScanTelem(victim_host)) @@ -73,20 +71,14 @@ class Propagator: @staticmethod def _process_tcp_scan_results(victim_host: VictimHost, port_scan_data: PortScanData) -> bool: - has_open_port = False - for psd in port_scan_data.values(): if psd.status == PortStatus.OPEN: - has_open_port = True - victim_host.services[psd.service] = {} victim_host.services[psd.service]["display_name"] = "unknown(TCP)" victim_host.services[psd.service]["port"] = psd.port if psd.banner is not None: victim_host.services[psd.service]["banner"] = psd.banner - return has_open_port - @staticmethod def _process_fingerprinter_results(victim_host: VictimHost, fingerprint_data: FingerprintData): for fd in fingerprint_data.values():