Skip to content

Commit

Permalink
feat: Updated scanners/openvas_scanner.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] authored Oct 30, 2023
1 parent 250c51b commit 1f754f5
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions scanners/openvas_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def __init__(self):
transform = EtreeTransform()
self.gmp = Gmp(connection, transform=transform)
self.storage_service = StorageService()
self.scan_status = None
self.scan_results = None

# Login
try:
Expand All @@ -49,9 +51,11 @@ def __init__(self):

def start(self, scan_name, target):
print(f'[{self.name}] Starting Scan for Target: {target}')
self.scan_status = 'INPROGRESS'

try:
return self.scan(scan_name, target)
self.scan_results = self.scan(scan_name, target)
return self.scan_results
except:
print(f'[{self.name}] Not able to connect to the {self.name}: ', sys.exc_info())
return False
Expand All @@ -65,6 +69,7 @@ def scan(self, scan_name, target):
# Creating Target
target_response = self.gmp.create_target(name=scan_name, hosts=[address])
# print('target_response')
self.scan_status = 'INPROGRESS'
pretty_print(target_response)
target_id = target_response.get('id')

Expand Down Expand Up @@ -132,6 +137,7 @@ def _create_report(self, scan_name):
print(f'[{self.name}] Created Report: {report_id} with Task: {task_id}')

self.storage_service.update_by_name(scan_name, scan_data)
self.scan_status = 'COMPLETE'

return scan_data

Expand All @@ -141,8 +147,7 @@ def get_scan_status(self, scan_name, scan_status_list=[]):
if not self.is_valid_scan(scan_name):
return False

scan_data = self.storage_service.get_by_name(scan_name)
scan_status = scan_data.get('OPENVAS', {}).get('scan_status', {})
return self.scan_status
openvas_id = scan_data.get('OPENVAS', {})['openvas_id']
target = scan_data['target']

Expand Down Expand Up @@ -179,7 +184,7 @@ def get_scan_results(self, scan_name, scan_results={}):
if not self.is_valid_scan(scan_name):
return False

scan_data = self.storage_service.get_by_name(scan_name)
return self.scan_results

# if scan_data.get('OPENVAS', {}).get('scan_status').get('status', None) != 'COMPLETE':
# print(f'[{self.name}] Scan is in progress')
Expand Down Expand Up @@ -233,8 +238,7 @@ def _process_results(self, report_response, scan_results={}):

def is_valid_scan(self, scan_name):

scan_data = self.storage_service.get_by_name(scan_name)
if not scan_data:
if self.scan_status is None:
print(f'[{self.name}] Invalid Scan Name: {scan_name}')
return False

Expand Down

0 comments on commit 1f754f5

Please sign in to comment.