add nessus API key support

This commit is contained in:
pemontto
2019-04-29 17:20:52 +01:00
parent eb9695605b
commit e752655990
3 changed files with 8 additions and 4 deletions

View File

@ -2,6 +2,8 @@
enabled=true enabled=true
hostname=localhost hostname=localhost
port=8834 port=8834
access_key=
secret_key=
username=nessus_username username=nessus_username
password=nessus_password password=nessus_password
write_path=/opt/VulnWhisperer/data/nessus/ write_path=/opt/VulnWhisperer/data/nessus/

View File

@ -2,6 +2,8 @@
enabled=true enabled=true
hostname=nessus hostname=nessus
port=443 port=443
access_key=
secret_key=
username=nessus_username username=nessus_username
password=nessus_password password=nessus_password
write_path=/opt/VulnWhisperer/data/nessus/ write_path=/opt/VulnWhisperer/data/nessus/

View File

@ -74,8 +74,8 @@ class NessusAPI(object):
'X-Cookie': None 'X-Cookie': None
} }
if self.profile == 'tenable' and all((self.access_key, self.secret_key)): if all((self.access_key, self.secret_key)):
self.logger.debug('Using Tenable API keys') self.logger.debug('Using {} API keys'.format(self.profile))
self.api_keys = True self.api_keys = True
self.session.headers['X-ApiKeys'] = 'accessKey={}; secretKey={}'.format(self.access_key, self.secret_key) self.session.headers['X-ApiKeys'] = 'accessKey={}; secretKey={}'.format(self.access_key, self.secret_key)
else: else:
@ -155,7 +155,7 @@ class NessusAPI(object):
req = self.request(query, data=json.dumps(data), method='POST', json_output=True) req = self.request(query, data=json.dumps(data), method='POST', json_output=True)
try: try:
file_id = req['file'] file_id = req['file']
if not self.api_keys: if self.profile == 'nessus':
token_id = req['token'] if 'token' in req else req['temp_token'] token_id = req['token'] if 'token' in req else req['temp_token']
except Exception as e: except Exception as e:
self.logger.error('{}'.format(str(e))) self.logger.error('{}'.format(str(e)))
@ -167,7 +167,7 @@ class NessusAPI(object):
running = report_status['status'] != 'ready' running = report_status['status'] != 'ready'
sys.stdout.write('.') sys.stdout.write('.')
sys.stdout.flush() sys.stdout.flush()
if self.profile == 'tenable': if self.profile == 'tenable' or self.api_keys:
content = self.request(self.EXPORT_FILE_DOWNLOAD.format(scan_id=scan_id, file_id=file_id), method='GET', download=True) content = self.request(self.EXPORT_FILE_DOWNLOAD.format(scan_id=scan_id, file_id=file_id), method='GET', download=True)
else: else:
content = self.request(self.EXPORT_TOKEN_DOWNLOAD.format(token_id=token_id), method='GET', download=True) content = self.request(self.EXPORT_TOKEN_DOWNLOAD.format(token_id=token_id), method='GET', download=True)