コード例 #1
0
ファイル: NessusParser.cs プロジェクト: ahall/NessusSharp
        public ParseReport Run()
        {
            var parseReport = new ParseReport();
            parseReport.Hosts = new List<ParseReportHost>();

            var element = XElement.Load(path);
            var report = element.Element("Report");
            foreach (var host in report.Elements("ReportHost"))
            {
                var parseHost = new ParseReportHost();
                parseHost.Items = new List<ParseReportHostItem>();

                parseHost.Name = (string)host.Attribute("name");
                if (string.IsNullOrEmpty(parseHost.Name))
                {
                    continue;
                }

                foreach (var item in host.Elements("ReportItem"))
                {
                    var parseReportHostItem = new ParseReportHostItem();
                    parseReportHostItem.Port = (int)item.Attribute("port");
                    parseReportHostItem.SvcName = (string)item.Attribute("svc_name");
                    parseReportHostItem.Protocol = (string)item.Attribute("protocol");
                    parseReportHostItem.PluginId = (int)item.Attribute("pluginID");
                    parseReportHostItem.PluginName = (string)item.Attribute("pluginName");

                    parseReportHostItem.Synopsis = (string)item.Element("synopsis");
                    parseReportHostItem.Description = (string)item.Element("description");

                    parseReportHostItem.RiskFactor = (string)item.Element("risk_factor");
                    switch (parseReportHostItem.RiskFactor)
                    {
                        case RiskFactor.Critical:
                            parseHost.NumVulnCritical++;
                            break;
                        case RiskFactor.High:
                            parseHost.NumVulnHigh++;
                            break;
                        case RiskFactor.Medium:
                            parseHost.NumVulnMedium++;
                            break;
                        case RiskFactor.Low:
                            parseHost.NumVulnLow++;
                            break;
                        default:
                            parseHost.NumVulnNone++;
                            break;
                    }

                    parseReportHostItem.Solution = (string)item.Element("solution");
                    parseReportHostItem.PluginType = (string)item.Element("plugin_type");
                    parseReportHostItem.PluginOutput = (string)item.Element("plugin_output");
                    parseHost.Items.Add(parseReportHostItem);
                }

                var parseHostProps = new ParseHostProperties();
                foreach (var hostProp in host.Elements("HostProperties"))
                {
                    foreach (var prop in hostProp.Elements())
                    {
                        string propName = (string)prop.Attribute("name");
                        if (propName == "HOST_START")
                        {
                            parseHostProps.HostStart = prop.Value;
                        }
                        else if (propName == "HOST_END")
                        {
                            parseHostProps.HostEnd = prop.Value;
                        }
                        else if (propName == "operating-system")
                        {
                            parseHostProps.OperatingSystem = prop.Value;
                        }
                        else if (propName == "host-ip")
                        {
                            parseHostProps.HostIp = prop.Value;
                        }
                        else if (propName == "host-fqdn")
                        {
                            parseHostProps.HostFqdn = prop.Value;
                        }
                        else if (propName == "netbios-name")
                        {
                            parseHostProps.NetBiosName = prop.Value;
                        }
                        else if (propName == "mac-address")
                        {
                            parseHostProps.MacAddress = prop.Value;
                        }
                    }

                    parseHost.Properties = parseHostProps;
                }

                // TODO: Need to check a special plugin to get this, leaving as 0 for now.
                parseHost.NumOpenPorts = 0;

                parseReport.Hosts.Add(parseHost);
            }

            return parseReport;
        }
コード例 #2
0
        public ParseReport Run()
        {
            var parseReport = new ParseReport();

            parseReport.Hosts = new List <ParseReportHost>();

            var element = XElement.Load(path);
            var report  = element.Element("Report");

            foreach (var host in report.Elements("ReportHost"))
            {
                var parseHost = new ParseReportHost();
                parseHost.Items = new List <ParseReportHostItem>();

                parseHost.Name = (string)host.Attribute("name");
                if (string.IsNullOrEmpty(parseHost.Name))
                {
                    continue;
                }

                foreach (var item in host.Elements("ReportItem"))
                {
                    var parseReportHostItem = new ParseReportHostItem();
                    parseReportHostItem.Port       = (int)item.Attribute("port");
                    parseReportHostItem.SvcName    = (string)item.Attribute("svc_name");
                    parseReportHostItem.Protocol   = (string)item.Attribute("protocol");
                    parseReportHostItem.PluginId   = (int)item.Attribute("pluginID");
                    parseReportHostItem.PluginName = (string)item.Attribute("pluginName");

                    parseReportHostItem.Synopsis    = (string)item.Element("synopsis");
                    parseReportHostItem.Description = (string)item.Element("description");

                    parseReportHostItem.RiskFactor = (string)item.Element("risk_factor");
                    switch (parseReportHostItem.RiskFactor)
                    {
                    case RiskFactor.Critical:
                        parseHost.NumVulnCritical++;
                        break;

                    case RiskFactor.High:
                        parseHost.NumVulnHigh++;
                        break;

                    case RiskFactor.Medium:
                        parseHost.NumVulnMedium++;
                        break;

                    case RiskFactor.Low:
                        parseHost.NumVulnLow++;
                        break;

                    default:
                        parseHost.NumVulnNone++;
                        break;
                    }

                    parseReportHostItem.Solution     = (string)item.Element("solution");
                    parseReportHostItem.PluginType   = (string)item.Element("plugin_type");
                    parseReportHostItem.PluginOutput = (string)item.Element("plugin_output");
                    parseHost.Items.Add(parseReportHostItem);
                }

                var parseHostProps = new ParseHostProperties();
                foreach (var hostProp in host.Elements("HostProperties"))
                {
                    foreach (var prop in hostProp.Elements())
                    {
                        string propName = (string)prop.Attribute("name");
                        if (propName == "HOST_START")
                        {
                            parseHostProps.HostStart = prop.Value;
                        }
                        else if (propName == "HOST_END")
                        {
                            parseHostProps.HostEnd = prop.Value;
                        }
                        else if (propName == "operating-system")
                        {
                            parseHostProps.OperatingSystem = prop.Value;
                        }
                        else if (propName == "host-ip")
                        {
                            parseHostProps.HostIp = prop.Value;
                        }
                        else if (propName == "host-fqdn")
                        {
                            parseHostProps.HostFqdn = prop.Value;
                        }
                        else if (propName == "netbios-name")
                        {
                            parseHostProps.NetBiosName = prop.Value;
                        }
                        else if (propName == "mac-address")
                        {
                            parseHostProps.MacAddress = prop.Value;
                        }
                    }

                    parseHost.Properties = parseHostProps;
                }

                // TODO: Need to check a special plugin to get this, leaving as 0 for now.
                parseHost.NumOpenPorts = 0;

                parseReport.Hosts.Add(parseHost);
            }

            return(parseReport);
        }