【问题标题】:How can I use nessrest api (python) to export nessus scan reports in xml?如何使用 nessrest api (python) 以 xml 格式导出 nessus 扫描报告?
【发布时间】:2016-09-24 00:41:50
【问题描述】:

我正在尝试使用 python 自动运行和下载 nessus 扫描。我一直在使用 nessrest api for python,并且能够成功运行扫描,但没有成功下载 nessus 格式的报告。

有什么想法可以做到这一点吗?我一直在使用模块 scan_download,但它实际上是在我的扫描完成之前执行的。

提前感谢您的帮助!

【问题讨论】:

  • 您必须在下载前“导出”报告。您可以使用 /status API 方法检查正在进行的扫描的状态。工作流程应如下所示:getToken()、startScan()、checkIfFinished()、export()、download()

标签: python-2.7 nessus


【解决方案1】:

回过头来看这个问题,这里有一个使用 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))

可以在这里查看更多示例,

https://github.com/tenable/nessrest/tree/master/scripts

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-17
    • 2020-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多