Skip to content

Commit

Permalink
update based on review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
sfowl committed Nov 5, 2024
1 parent 1d34941 commit 652f299
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions scanners/nessus/nessus_none.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def __init__(self, config: RapidastConfigModel, ident: str = "nessus"):
# self.auth_config = config.subtree_to_dict("general.authentication") # creds for target hosts
# XXX self.config is already a dict with raw config values
self.cfg = dacite.from_dict(data_class=NessusConfig, data=nessus_config_section)
self.sleep_interval: int = 20
self._sleep_interval: int = 10
self._timeout: int = 300
self._connect()

def _connect(self):
Expand Down Expand Up @@ -97,6 +98,9 @@ def setup(self):
create_folder=True,
)

if self._scan_id < 0:
raise RuntimeError(f"Unexpected scan_id {self.scan_id}")

# only user-created scan policies seem to be identified and must be
# created with the name used in the config as a prerequisite
if self.cfg.scan.policy:
Expand All @@ -116,17 +120,23 @@ def run(self):
self.nessus_client.post_scan(scan_id=self.scan_id)

# Wait for the scan to complete
start = time.time()
while self.nessus_client.get_scan_status(self.scan_id)["status"] not in END_STATUSES:
time.sleep(self.sleep_interval)
logging.debug("Waiting {self.sleep_interval}s for scan to finish")
if time.time() - start > self._timeout:
logging.error(f"Timeout {self._timeout}s reached waiting for scan to complete")
self.state = State.ERROR
break

time.sleep(self._sleep_interval)
logging.debug(f"Waiting {self._sleep_interval}s for scan to finish")
logging.info(self.nessus_client.get_scan_status(self.scan_id))

def postprocess(self):
# After scan is complete, download report in csv, nessus, and html format
# Path and any folders must already exist in this implementation
logging.debug("Retrieving scan reports")
scan_reports = self.nessus_client.get_scan_reports(self.scan_id, self.results_dir)
print(scan_reports)
logging.debug(scan_reports)
if not self.state == State.ERROR:
self.state = State.PROCESSED

Expand Down

0 comments on commit 652f299

Please sign in to comment.