NetExec/nxc/parsers/nessus.py

45 lines
1.5 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import xmltodict
# Ideally i'd like to be able to pull this info out dynamically from each protocol object but i'm a lazy bastard
protocol_dict = {
2023-05-02 15:17:59 +00:00
"smb": {"ports": [445, 139], "services": ["smb", "cifs"]},
"mssql": {"ports": [1433], "services": ["mssql"]},
"ssh": {"ports": [22], "services": ["ssh"]},
"winrm": {"ports": [5986, 5985], "services": ["www", "https?"]},
"http": {"ports": [80, 443, 8443, 8008, 8080, 8081], "services": ["www", "https?"]},
}
def parse_nessus_file(nessus_file, protocol):
targets = []
def handle_nessus_file(path, item):
# Must return True otherwise xmltodict will throw a ParsingIterrupted() exception
# https://github.com/martinblech/xmltodict/blob/master/xmltodict.py#L219
2023-05-02 15:17:59 +00:00
if any("ReportHost" and "ReportItem" in values for values in path):
item = dict(path)
2023-05-02 15:17:59 +00:00
ip = item["ReportHost"]["name"]
if ip in targets:
return True
2023-05-02 15:17:59 +00:00
port = item["ReportItem"]["port"]
svc_name = item["ReportItem"]["svc_name"]
2023-05-02 15:17:59 +00:00
if port in protocol_dict[protocol]["ports"]:
targets.append(ip)
2023-05-02 15:17:59 +00:00
if svc_name in protocol_dict[protocol]["services"]:
targets.append(ip)
return True
else:
return True
2023-05-02 15:17:59 +00:00
with open(nessus_file, "r") as file_handle:
xmltodict.parse(file_handle, item_depth=4, item_callback=handle_nessus_file)
return targets