Agent: Refactor the hack to add http ports to the fingerprinters

This commit is contained in:
Mike Salvatore 2022-07-27 13:13:18 -04:00
parent 0a395caff9
commit 961d2df7d9
1 changed files with 23 additions and 9 deletions

View File

@ -1,7 +1,8 @@
import logging import logging
from dataclasses import replace
from queue import Queue from queue import Queue
from threading import Event from threading import Event
from typing import List from typing import List, Sequence
from common.agent_configuration import ( from common.agent_configuration import (
NetworkScanConfiguration, NetworkScanConfiguration,
@ -52,18 +53,14 @@ class Propagator:
network_scan_completed = Event() network_scan_completed = Event()
self._hosts_to_exploit = Queue() self._hosts_to_exploit = Queue()
# This is a hack to add http_ports to the options of fingerprinters network_scan = self._add_http_ports_to_fingerprinters(
# It will be reworked propagation_config.network_scan, propagation_config.exploitation.options.http_ports
for fingerprinter in propagation_config.network_scan.fingerprinters: )
if fingerprinter.name == "http":
fingerprinter.options[
"http_ports"
] = propagation_config.exploitation.options.http_ports
scan_thread = create_daemon_thread( scan_thread = create_daemon_thread(
target=self._scan_network, target=self._scan_network,
name="PropagatorScanThread", name="PropagatorScanThread",
args=(propagation_config.network_scan, stop), args=(network_scan, stop),
) )
exploit_thread = create_daemon_thread( exploit_thread = create_daemon_thread(
target=self._exploit_hosts, target=self._exploit_hosts,
@ -81,6 +78,23 @@ class Propagator:
logger.info("Finished attempting to propagate") logger.info("Finished attempting to propagate")
@staticmethod
def _add_http_ports_to_fingerprinters(
network_scan: NetworkScanConfiguration, http_ports: Sequence[int]
) -> NetworkScanConfiguration:
# This is a hack to add http_ports to the options of fingerprinters
# It will be reworked
modified_fingerprinters = [*network_scan.fingerprinters]
for i, fingerprinter in enumerate(modified_fingerprinters):
if fingerprinter.name != "http":
continue
modified_options = fingerprinter.options.copy()
modified_options["http_ports"] = list(http_ports)
modified_fingerprinters[i] = replace(fingerprinter, options=modified_options)
return replace(network_scan, fingerprinters=modified_fingerprinters)
def _scan_network(self, scan_config: NetworkScanConfiguration, stop: Event): def _scan_network(self, scan_config: NetworkScanConfiguration, stop: Event):
logger.info("Starting network scan") logger.info("Starting network scan")