我正在尝试使用 python 自动运行和下载 nessus 扫描。我一直在使用 nessrest api for python,并且能够成功运行扫描,但没有成功下载 nessus 格式的报告。
任何想法我怎么能做到这一点?我一直在使用模块 scan_download,但它实际上是在我的扫描完成之前执行的。
我在这里先向您的帮助表示感谢!
我正在尝试使用 python 自动运行和下载 nessus 扫描。我一直在使用 nessrest api for python,并且能够成功运行扫描,但没有成功下载 nessus 格式的报告。
任何想法我怎么能做到这一点?我一直在使用模块 scan_download,但它实际上是在我的扫描完成之前执行的。
我在这里先向您的帮助表示感谢!
回顾一下这个问题,这里有一个使用 Nessrest API 从您的 nessus 主机下拉 CSV 报告导出的示例,
#!/usr/bin/python2.7
import sys
import os
import io
from nessrest import ness6rest
file_format = 'csv' # options: nessus, csv, db, html
dbpasswd = ''
scan = ness6rest.Scanner(url="https://nessus:8834", login="admin", password="P@ssword123", insecure=True)
scan.action(action='scans', method='get')
folders = scan.res['folders']
scans = scan.res['scans']
if scan:
scan.action(action='scans', method='get')
folders = scan.res['folders']
scans = scan.res['scans']
for f in folders:
if not os.path.exists(f['name']):
if not f['type'] == 'trash':
os.mkdir(f['name'])
for s in scans:
scan.scan_name = s['name']
scan.scan_id = s['id']
folder_name = next(f['name'] for f in folders if f['id'] == s['folder_id'])
folder_type = next(f['type'] for f in folders if f['id'] == s['folder_id'])
# skip trash items
if folder_type == 'trash':
continue
if s['status'] == 'completed':
file_name = '%s_%s.%s' % (scan.scan_name, scan.scan_id, file_format)
file_name = file_name.replace('\\','_')
file_name = file_name.replace('/','_')
file_name = file_name.strip()
relative_path_name = folder_name + '/' + file_name
# PDF not yet supported
# python API wrapper nessrest returns the PDF as a string object instead of a byte object, making writing and correctly encoding the file a chore...
# other formats can be written out in text mode
file_modes = 'wb'
# DB is binary mode
#if args.format == "db":
# file_modes = 'wb'
with io.open(relative_path_name, file_modes) as fp:
if file_format != "db":
fp.write(scan.download_scan(export_format=file_format))
else:
fp.write(scan.download_scan(export_format=file_format, dbpasswd=dbpasswd))
可以在这里查看更多示例,