forked from levyjm/NessusConverter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nessus_to_csv.py
60 lines (49 loc) · 2.82 KB
/
nessus_to_csv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
import xml.etree.ElementTree as etree
import csv
import os
import argparse
def parse_arguments():
parser = argparse.ArgumentParser(description="Converts Nessus files into a CSV file with semicolon delimiters.")
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("-i", "--input_dir", type=str, help="Directory containing the Nessus files")
group.add_argument("-f", "--input_file", type=str, help="Path to a single Nessus file")
parser.add_argument("-o", "--output_file", type=str, required=True, help="The path to the output CSV file")
return parser.parse_args()
def process_nessus_file(file_path, csvwriter):
tree = etree.parse(file_path)
root = tree.getroot()
# Extracting the "Report name" as "Scan Group"
scan_group = root.find(".//Report").attrib.get('name') if root.find(".//Report") is not None else 'N/A'
for reportHost in root.iter('ReportHost'):
ip = reportHost.get('name')
for reportItem in reportHost.iter('ReportItem'):
risk_factor = reportItem.find('risk_factor')
if risk_factor is not None and risk_factor.text != "None": # Check for risk_factor being not "None"
severity = risk_factor.text
cvss_score = reportItem.find('cvss3_base_score').text if reportItem.find('cvss3_base_score') is not None else 'N/A'
vpr_score = reportItem.find('vpr_score').text if reportItem.find('vpr_score') is not None else 'N/A'
plugin_id = reportItem.get('pluginID')
plugin_name = reportItem.get('pluginName')
port = reportItem.get('port')
cves = reportItem.findall('cve')
cve_list = ', '.join(cve.text for cve in cves) if cves else 'N/A'
# Adjusting the order and including all required fields
data_row = [scan_group, ip, port, cve_list, severity, cvss_score, vpr_score, plugin_id, plugin_name]
csvwriter.writerow(data_row)
def main(input_dir, input_file, output_file):
with open(output_file, 'w', newline='') as nessus_file:
csvwriter = csv.writer(nessus_file, delimiter=';')
# Updated headers to match the new requirement
headers = ['Scan Group', 'IP Address', 'Port', 'CVEs', 'Severity', 'CVSS Score', 'VPR Score', 'Plugin ID', 'Name']
csvwriter.writerow(headers)
if input_dir:
for fileName in os.listdir(input_dir):
if fileName.endswith(".nessus"):
fullPath = os.path.join(input_dir, fileName)
process_nessus_file(fullPath, csvwriter)
elif input_file:
process_nessus_file(input_file, csvwriter)
if __name__ == "__main__":
args = parse_arguments()
main(args.input_dir, args.input_file, args.output_file)