-
-
Save JamesConlan96/93eff681c649d230d3e0866c106cef89 to your computer and use it in GitHub Desktop.
Merging Nessus Files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# file: merger.py | |
# based off: http://cmikavac.net/2011/07/09/merging-multiple-nessus-scans-python-script/ | |
# by: mastahyeti | |
# modified by: JamesConlan96 | |
import argparse | |
import xml.etree.ElementTree as etree | |
import shutil | |
import sys | |
import os | |
def parseArgs(): | |
"""Parses CLI arguments""" | |
parser = argparse.ArgumentParser(description="Merge multiple nessus files") | |
parser.add_argument('-o', '--outfile', default="merged_report", | |
action="store", help="name for output nessus file " + | |
"(default: merged_report)") | |
parser.add_argument('-n', '--name', action="store", default="merged_report", | |
help="Name for output Nessus report" + | |
"(default: merged_report)") | |
parser.add_argument("input_file", nargs='+', action="store", | |
help="Nessus file to merge") | |
return parser.parse_args() | |
def yesNo(prompt): | |
"""Prompts the user for a yes/no response""" | |
yn = input("{0} (y/n): ".format(prompt)) | |
if yn.lower() == 'y': | |
return True | |
elif yn.lower() == 'n': | |
return False | |
else: | |
return self.yesNo(prompt) | |
if __name__ == "__main__": | |
args = parseArgs() | |
if os.path.exists("{0}.nessus".format(args.outfile)): | |
if not yesNo("Output file '{0}.nessus' already exists, overwrite it?".format(args.outfile)): | |
sys.exit() | |
first = 1 | |
for fileName in args.input_file: | |
if ".nessus" in fileName: | |
print(":: Parsing", fileName) | |
if first: | |
mainTree = etree.parse(fileName) | |
report = mainTree.find('Report') | |
report.attrib['name'] = args.name | |
first = 0 | |
else: | |
tree = etree.parse(fileName) | |
for host in tree.findall('.//ReportHost'): | |
existing_host = report.find(".//ReportHost[@name='"+host.attrib['name']+"']") | |
if not existing_host: | |
print("adding host: " + host.attrib['name']) | |
report.append(host) | |
else: | |
for item in host.findall('ReportItem'): | |
if not existing_host.find("ReportItem[@port='"+ item.attrib['port'] +"'][@pluginID='"+ item.attrib['pluginID'] +"']"): | |
print("adding finding: " + item.attrib['port'] + ":" + item.attrib['pluginID']) | |
existing_host.append(item) | |
print(":: => done.") | |
if "nss_report" in os.listdir("."): | |
shutil.rmtree("nss_report") | |
mainTree.write("{0}.nessus".format(args.outfile), encoding="utf-8", xml_declaration=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment