public static void Main(string[] args) { // Don't validate certificates. ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications); /* * Uri baseUri = new Uri("https://localhost:8834"); * IConnection conn = new Connection(baseUri, "cns", "temp123"); * * List<Report> reports = conn.ListReports(); * foreach (Report report in reports) * { * Console.WriteLine(report.Name); * Console.WriteLine(report.Status); * Console.WriteLine(report.TimeStamp); * } * * using (FileStream toWrite = File.OpenWrite("/tmp/writeit.xml")) * { * if (reports.Count > 0) * { * conn.DownloadReport(reports[0].Name, toWrite); * } * } * * Policy policy = new Policy("ahallpolicy"); * policy.AddSmbCredentials("smbuser", "smbpass"); * policy.AddSshCredentials("sshuser", "sshpass"); * * conn.CreatePolicy(policy); * * Scan scan = new Scan("fishers"); * scan.Targets.Add("127.0.0.1"); * scan.Targets.Add("127.0.0.2"); * conn.CreateScan(scan, policy); * * // Wipes all policies. * //conn.ListPolicies().ForEach(x => conn.DeletePolicy(x)); */ // Playing with the nessus parser. string path = "/Users/ahall/Downloads/nessus.nessus"; var parser = new NessusParser(path); var report = parser.Run(); foreach (var host in report.Hosts) { Console.WriteLine("Host: " + host.Name); Console.WriteLine("High: " + host.NumVulnHigh); Console.WriteLine("Medium: " + host.NumVulnMedium); Console.WriteLine("Low: " + host.NumVulnLow); } int al = 14; }
public void ImportFromNessusFile(List <string> filenames) { DatabaseController db = new DatabaseController(); try { int lastHostID = db.GetFirstHostIDNumber(); List <Host> hostsList = new List <Host>(); List <Vulnerability> vulnList = new List <Vulnerability>(); foreach (string file in filenames) { NessusParser parser = new NessusParser(file); ParseReport report = parser.Run(); foreach (ParseReportHost host in report.Hosts) { string hostname = host.Properties.NetBiosName; string fullqualname = host.Properties.HostFqdn; if (string.IsNullOrEmpty(hostname)) { hostname = "unknown"; } if (string.IsNullOrEmpty(fullqualname)) { fullqualname = "unknown"; } hostsList.Add(new Host { ID = lastHostID, HostIP = host.Properties.HostIp, FQDN = fullqualname, NetBiosName = hostname, OperatingSystem = host.Properties.OperatingSystem }); List <ParseReportHostItem> vulnItems = host.Items; foreach (ParseReportHostItem vuln in vulnItems) { vulnList.Add(new Vulnerability { PluginID = vuln.PluginId, PluginName = vuln.PluginName, PluginType = vuln.PluginType, RiskFactor = vuln.RiskFactor, Severity = vuln.Severity, Description = vuln.Description, Solution = vuln.Solution, Port = vuln.Port.ToString(), Protocol = vuln.Protocol, Synopsis = vuln.Synopsis, PluginOutput = vuln.PluginOutput, HostID = lastHostID }); } ++lastHostID; } } db.PopulateDatabaseFromNessus(hostsList, vulnList); db.RemoveDuplicatesFromDatabase(); } catch (Exception) { Debug.WriteLine("Error: 96589"); } }