0

我有一个来自我想要解析的 .nessus 文件的 XML,我已经找到了一些代码并正在根据我的需要对其进行调整,但是在测试下面的函数之后,它会重复行,有时 6 到 7 次其他 8 次。

def handleReport(report):
    findings = []
    reportHost = dict.fromkeys(csvHeaders, '')
    for item in report:
        if item.tag == 'HostProperties':
            for tag in (tag for tag in item if tag.attrib['name'] in nessusFields):
                reportHost[getKey(tag.attrib['name'])] = getValue(tag.text)
        if item.tag == 'ReportItem':
                reportRow = dict(reportHost)
                reportRow['Port'] = item.attrib['port']
                for tag in (tag for tag in item if tag.tag in nessusFields):
                    reportRow[getKey(tag.tag)] = getValue(tag.text)
                    findings.append(reportRow)
    return findings

这是我要修改的功能。为了进行一些比赛, csvHeaders 包含我想要的 CSV 导出的列,report 是一个 .nessus 文件,它具有与 xml 不同的结构。在 xml 中,有一个 HostProperties 对象,我只想要 2 个值 "192.168.1.20" 和 "targetofscan.domain.me" 。host-ip 和 host-fqdn 都是 nessusFields 的一部分,其中包含另一组字段,这些字段也存在于第二个对象上。
xml的结构如下:

nessusclientdata_v2
     policy
     report
        reportshot
           hostproperties
           reportitem
           reportitem
           ......

如上所述,我的目标是获取报告对象内部的内容,hostproperties 的 2 个属性,其余的来自有多个 off 的 reportitem。

根据我上面显示的功能,我缺少什么或者我需要编辑什么以确保它不会多次重复行?同样,这是我发现的代码中的一个函数,可以满足我的需求。

4

0 回答 0