public void MergeSelectedVulnerabilities(List <int> pluginIDList, string newIssueTitle, string pluginNames, string severityRating, string riskFactor)
        {
            using (ToolViewContext db = new ToolViewContext()) {
                try {
                    List <Vulnerability> vulnsToMerge = new List <Vulnerability>();
                    db.Configuration.AutoDetectChangesEnabled = false;
                    db.Configuration.ValidateOnSaveEnabled    = false;

                    int newPluginID = GetFreePluginID();

                    foreach (int pluginID in pluginIDList)
                    {
                        db.Vulnerabilities.Where(v => v.PluginID == pluginID).Update(x => new Vulnerability()
                        {
                            PluginID    = newPluginID,
                            PluginName  = newIssueTitle,
                            Description = pluginNames,
                            Solution    = "",
                            Severity    = severityRating,
                            RiskFactor  = riskFactor
                        });
                    }

                    db.SaveChanges();
                }
                catch (Exception e) {
                    Debug.WriteLine("Error: 923843" + ": " + e);
                }
                finally {
                    db.Dispose();
                }
            }
        }
        public int GetFirstHostIDNumber()
        {
            using (ToolViewContext db = new ToolViewContext()) {
                db.Configuration.AutoDetectChangesEnabled = false;
                int result = 0;

                try {
                    if (db.Hosts.Any())
                    {
                        result = db.Hosts.Max(x => x.ID);
                    }
                    else
                    {
                        result = 1;
                    }
                }
                catch (Exception) {
                    Debug.WriteLine("Error: 95458");
                }
                finally {
                    db.Dispose();
                }

                return(result);
            }
        }
        public void RemoveDuplicatesFromDatabase()
        {
            using (ToolViewContext db = new ToolViewContext()) {
                try {
                    db.Configuration.AutoDetectChangesEnabled = false;

                    var hostDuplicates = from h in db.Hosts
                                         group h by new { h.HostIP, h.NetBiosName, h.FQDN, h.OperatingSystem }
                    into g
                    where g.Count() > 1
                    select g;

                    foreach (var g in hostDuplicates)
                    {
                        List <Host> duplicates = g.Skip(1).ToList();

                        foreach (Host record in duplicates)
                        {
                            db.Configuration.AutoDetectChangesEnabled = false;
                            db.Hosts.Remove(record);
                        }
                    }
                    db.SaveChanges();
                }
                catch (Exception) {
                    Debug.WriteLine("Error: 965777");
                }
                finally {
                    db.Dispose();
                }
            }
        }
Beispiel #4
0
        public List <AffectedHosts> GetAffectedHosts(int pluginID)
        {
            using (ToolViewContext db = new ToolViewContext()) {
                List <AffectedHosts> affectedHosts = new List <AffectedHosts>();

                try {
                    var query = (from h in db.Hosts
                                 join v in db.Vulnerabilities.Where(vuln => vuln.PluginID == pluginID)
                                 on h.ID equals v.HostID
                                 into result
                                 select new {
                        h.HostIP,
                        h.NetBiosName,
                        h.FQDN,
                        Vulns = result,
                    }).OrderBy(o => o.HostIP);

                    foreach (var host in query)
                    {
                        if (host.Vulns.Any())
                        {
                            List <string> portList = new List <string>();

                            foreach (Vulnerability vuln in host.Vulns)
                            {
                                portList.Add(vuln.Port + "/" + vuln.Protocol);
                            }

                            AffectedHosts hst = new AffectedHosts {
                                HostIP = host.HostIP,
                                FQDN   = host.NetBiosName,
                                Ports  = string.Join(", ", portList.Distinct())
                            };
                            affectedHosts.Add(hst);
                        }
                    }
                }
                catch (Exception e) {
                    Debug.WriteLine("Error: 92121" + ": " + e);
                }

                var DistinctItems            = affectedHosts.GroupBy(x => x.HostIP).Select(y => y.First());
                List <AffectedHosts> newList = new List <AffectedHosts>();

                foreach (var item in DistinctItems)
                {
                    newList.Add(item);
                }

                return(newList);
            }
        }
Beispiel #5
0
 public List <Vulnerability> GetVulnList()
 {
     using (ToolViewContext db = new ToolViewContext()) {
         List <Vulnerability> vulnList = null;
         try {
             vulnList = db.Vulnerabilities.ToList();
         }
         catch (Exception) {
             Debug.WriteLine("Error: 921234");
         }
         return(vulnList);
     }
 }
 public void DeleteDatabase()
 {
     using (ToolViewContext db = new ToolViewContext()) {
         try {
             db.Configuration.AutoDetectChangesEnabled = false;
             db.Database.Delete();
         }
         catch (Exception) {
             Debug.WriteLine("Error: 95447");
         }
         finally {
             db.Dispose();
         }
     }
 }
 public void ClearDatabase()
 {
     using (ToolViewContext db = new ToolViewContext()) {
         try {
             db.Database.ExecuteSqlCommand("DELETE FROM Host");
             db.Database.ExecuteSqlCommand("DBCC CHECKIDENT(Host, RESEED, 1)");
         }
         catch (Exception e) {
             Debug.WriteLine("Error: 965333 : " + e);
         }
         finally {
             db.Dispose();
         }
     }
 }
Beispiel #8
0
        public AppendixData GetAppendixPluginID()
        {
            using (ToolViewContext db = new ToolViewContext()) {
                AppendixData appData = new AppendixData();

                try {
                    appData = db.Appendix.FirstOrDefault();
                }
                catch (Exception e) {
                    Debug.WriteLine("Error: 921234" + e);
                }

                return(appData);
            }
        }
Beispiel #9
0
        public Vulnerability GetSelectedVuln(int pluginID)
        {
            using (ToolViewContext db = new ToolViewContext()) {
                Vulnerability vuln = new Vulnerability();

                try {
                    vuln = db.Vulnerabilities.Where(v => v.PluginID == pluginID).FirstOrDefault();
                }
                catch (Exception e) {
                    Debug.WriteLine("Error: 92360" + ": " + e);
                }

                return(vuln);
            }
        }
Beispiel #10
0
        public List <Vulnerability> GetAppendixData(string hostIP, int pluginID)
        {
            using (ToolViewContext db = new ToolViewContext()) {
                Host host = new Host();
                List <Vulnerability> vuln = new List <Vulnerability>();

                try {
                    host = db.Hosts.Where(h => h.HostIP == hostIP).FirstOrDefault();
                    vuln = db.Vulnerabilities.Where(v => v.HostID == host.ID && v.PluginID == pluginID).ToList();
                }
                catch (Exception e) {
                    Debug.WriteLine("Error: 9213214" + e);
                }

                return(vuln);
            }
        }
Beispiel #11
0
        public List <AffectedHostsMulti> GetAffectedHostsMulti(List <int> pluginIDList)
        {
            using (ToolViewContext db = new ToolViewContext()) {
                List <AffectedHostsMulti> affectedHosts = new List <AffectedHostsMulti>();

                try {
                    var query = (from h in db.Hosts
                                 join v in db.Vulnerabilities.Where(vuln => pluginIDList.Contains(vuln.PluginID))
                                 on h.ID equals v.HostID
                                 into result
                                 select new {
                        h.HostIP,
                        NetBiosName = h.NetBiosName,
                        FQDN = h.FQDN,
                        Vulns = result
                    }).OrderBy(o => o.HostIP);

                    foreach (var host in query)
                    {
                        if (host.Vulns.Any())
                        {
                            List <string> portList = new List <string>();

                            foreach (Vulnerability vuln in host.Vulns)
                            {
                                portList.Add(vuln.Port + "/" + vuln.Protocol);
                            }

                            AffectedHostsMulti hst = new AffectedHostsMulti {
                                HostIP = host.HostIP,
                                FQDN   = host.FQDN,
                                Ports  = string.Join(", ", portList.Distinct()),
                                Vulns  = string.Join(System.Environment.NewLine, host.Vulns.Select(x => x.PluginName))
                            };
                            affectedHosts.Add(hst);
                        }
                    }
                }
                catch (Exception e) {
                    Debug.WriteLine("Error: 92121" + ": " + e);
                }

                return(affectedHosts);
            }
        }
 public void PopulateDatabaseFromNessus(List <Host> hostList, List <Vulnerability> vulnList)
 {
     using (ToolViewContext db = new ToolViewContext()) {
         try {
             db.Configuration.AutoDetectChangesEnabled = false;
             db.Configuration.ValidateOnSaveEnabled    = false;
             db.Database.CommandTimeout = 0;
             db.BulkInsert(hostList);
             db.BulkInsert(vulnList);
         }
         catch (Exception e) {
             Debug.WriteLine(e.Message);
             Debug.WriteLine("Error: 965784");
         }
         finally {
             db.Dispose();
         }
     }
 }
        public bool IsTablesPopulated()
        {
            bool result = false;

            using (ToolViewContext db = new ToolViewContext()) {
                try {
                    if (db.Hosts.Any() && db.Vulnerabilities.Any())
                    {
                        result = true;
                    }
                }
                catch (Exception e) {
                    Debug.WriteLine("Error: 330913 : " + e);
                }
                finally {
                    db.Dispose();
                }
            }
            return(result);
        }
        private int GetFreePluginID()
        {
            using (ToolViewContext db = new ToolViewContext()) {
                int newPluginID = new Random().Next(100000, 999999);

                try {
                    while (db.Vulnerabilities.Any(v => v.PluginID == newPluginID))
                    {
                        newPluginID = new Random().Next(100000, 999999);
                    }
                }
                catch (Exception e) {
                    Debug.WriteLine("Error: 922324" + ": " + e);
                }
                finally {
                    db.Dispose();
                }

                return(newPluginID);
            }
        }
        public void RemoveSelectedVulnerability(List <int> pluginIDList)
        {
            using (ToolViewContext db = new ToolViewContext()) {
                try {
                    db.Configuration.AutoDetectChangesEnabled = false;
                    db.Configuration.ValidateOnSaveEnabled    = false;

                    foreach (int pluginID in pluginIDList)
                    {
                        db.Vulnerabilities.Where(v => v.PluginID == pluginID).Delete();
                    }

                    db.SaveChanges();
                }
                catch (Exception e) {
                    Debug.WriteLine("Error: 923657" + ": " + e);
                }
                finally {
                    db.Dispose();
                }
            }
        }
Beispiel #16
0
        public void SetAppendixPluginID(int pluginID)
        {
            using (ToolViewContext db = new ToolViewContext()) {
                AppendixData appData = new AppendixData();

                try {
                    if (db.Appendix.Any())
                    {
                        AppendixData recordDelete = db.Appendix.FirstOrDefault();
                        db.Appendix.Remove(recordDelete);
                        db.SaveChanges();
                    }

                    appData.pluginID = pluginID;
                    db.Appendix.Add(appData);
                    db.SaveChanges();
                }
                catch (Exception e) {
                    Debug.WriteLine("Error: 921234" + e);
                }
            }
        }
Beispiel #17
0
        public List <VulnXMLHosts> GetVulnXMLData()
        {
            using (ToolViewContext db = new ToolViewContext()) {
                List <VulnXMLHosts> result = new List <VulnXMLHosts>();

                try {
                    var query = (from h in db.Hosts
                                 join v in db.Vulnerabilities
                                 on h.ID equals v.HostID
                                 into output
                                 select new {
                        h.HostIP,
                        h.NetBiosName,
                        h.FQDN,
                        Vulns = output
                    }).OrderBy(o => o.HostIP);

                    foreach (var item in query)
                    {
                        if (item.Vulns.Any())
                        {
                            VulnXMLHosts host = new VulnXMLHosts {
                                HostIP      = item.HostIP,
                                NetBiosName = item.NetBiosName,
                                FQDN        = item.FQDN,
                                Vulns       = item.Vulns.ToList()
                            };

                            result.Add(host);
                        }
                    }
                }
                catch (Exception e) {
                    Debug.WriteLine("Error: 9445860" + ": " + e);
                }

                return(result);
            }
        }
Beispiel #18
0
        public List <AffectedPatchHosts> GetAffectedPatchHosts(int pluginID)
        {
            using (ToolViewContext db = new ToolViewContext()) {
                List <AffectedPatchHosts> hosts = new List <AffectedPatchHosts>();

                try {
                    var query = (from h in db.Hosts
                                 join v in db.Vulnerabilities.Where(vuln => vuln.PluginID == pluginID)
                                 on h.ID equals v.HostID
                                 into result
                                 select new {
                        h.HostIP,
                        NetBiosName = h.NetBiosName,
                        FQDN = h.FQDN,
                        Vulns = result
                    }).OrderBy(o => o.HostIP);

                    foreach (var host in query)
                    {
                        if (host.Vulns.Any())
                        {
                            AffectedPatchHosts hst = new AffectedPatchHosts {
                                HostIP      = host.HostIP,
                                NetBiosName = host.NetBiosName,
                                FQDN        = host.FQDN,
                                Vulns       = host.Vulns.ToList()
                            };
                            hosts.Add(hst);
                        }
                    }
                }
                catch (Exception e) {
                    Debug.WriteLine("Error: 945660" + ": " + e);
                }

                return(hosts);
            }
        }