private void AddVulnerabilityAndUniqueFinding(FprVulnerability fprVulnerability) { try { using (SQLiteCommand sqliteCommand = FindingsDatabaseActions.sqliteConnection.CreateCommand()) { FprDescription fprDescription = fprDescriptionList.FirstOrDefault(x => x.ClassId == fprVulnerability.ClassId); sqliteCommand.Parameters.Add(new SQLiteParameter("VulnId", fprVulnerability.ClassId)); sqliteCommand.Parameters.Add(new SQLiteParameter("Description", InjectDefinitionValues(fprDescription.Description, fprVulnerability))); sqliteCommand.Parameters.Add(new SQLiteParameter("RiskStatement", InjectDefinitionValues(fprDescription.RiskStatement, fprVulnerability))); sqliteCommand.Parameters.Add(new SQLiteParameter("VulnTitle", InjectDefinitionValues(fprDescription.VulnTitle, fprVulnerability))); sqliteCommand.Parameters.Add(new SQLiteParameter("CrossReferences", fprVulnerability.InstanceId)); sqliteCommand.Parameters.Add(new SQLiteParameter("CheckContent", fprVulnerability.Category)); sqliteCommand.Parameters.Add(new SQLiteParameter("FileName", file)); sqliteCommand.Parameters.Add(new SQLiteParameter("LastObserved", lastObserved)); sqliteCommand.Parameters.Add(new SQLiteParameter("AssetIdToReport", softwareName)); sqliteCommand.Parameters.Add(new SQLiteParameter("Version", version)); sqliteCommand.Parameters.Add(new SQLiteParameter("FindingDetails", "Instance ID:" + Environment.NewLine + fprVulnerability.InstanceId)); List <KeyValuePair <string, string> > nistControls = fprDescription.References.Where( x => x.Key.Contains("800-53")).OrderByDescending(x => x.Key).ToList(); if (nistControls != null && nistControls.Count > 0) { sqliteCommand.Parameters.Add(new SQLiteParameter("NistControl", nistControls[0].Value.Split(' ')[0])); } sqliteCommand.Parameters.Add(new SQLiteParameter("FixText", fprDescription.FixText)); List <KeyValuePair <string, string> > asdStigs = fprDescription.References.Where( x => x.Key.Contains("AS&D")).ToList(); string[] delimiter = new string[] { "CAT" }; if (asdStigs != null && asdStigs.Count > 0) { asdStigs = asdStigs.OrderByDescending(x => Convert.ToDecimal(x.Key.Substring(5, 1))). ThenByDescending(x => x.Key.Split(',')[0].Substring(7).Length). ThenByDescending(x => x.Key.Substring(7)).ToList(); if (asdStigs[0].Value.Contains(", ")) { string[] asdStigValues = asdStigs[0].Value.Split(',').ToArray(); foreach (string stigValue in asdStigValues) { sqliteCommand.Parameters.Add(new SQLiteParameter("StigId", stigValue.Trim().Split(' ')[0])); sqliteCommand.Parameters.Add(new SQLiteParameter("RawRisk", stigValue.Split(delimiter, StringSplitOptions.None)[1].Trim())); sqliteCommand.Parameters.Add(new SQLiteParameter("Impact", RawRiskToImpactConverter(stigValue.Split(delimiter, StringSplitOptions.None)[1].Trim()))); CreateAddVulnerabilityCommand(sqliteCommand); CreateAddUniqueFindingCommand(sqliteCommand); } } else { sqliteCommand.Parameters.Add(new SQLiteParameter("StigId", asdStigs[0].Value.Replace(", ", Environment.NewLine).Trim().Split(' ')[0])); sqliteCommand.Parameters.Add(new SQLiteParameter("RawRisk", asdStigs[0].Value.Split(delimiter, StringSplitOptions.None)[1].Trim())); sqliteCommand.Parameters.Add(new SQLiteParameter("Impact", RawRiskToImpactConverter(asdStigs[0].Value.Split(delimiter, StringSplitOptions.None)[1].Trim()))); CreateAddVulnerabilityCommand(sqliteCommand); CreateAddUniqueFindingCommand(sqliteCommand); } } else { CreateAddVulnerabilityCommand(sqliteCommand); CreateAddUniqueFindingCommand(sqliteCommand); } } } catch (Exception exception) { log.Error("Unable to generate SQLiteParameter List."); throw exception; } }
private void ParseFvdlDescriptionNode(XmlReader xmlReader) { try { FprDescription fprDescription = new FprDescription(); fprDescription.ClassId = xmlReader.GetAttribute("classID"); while (xmlReader.Read()) { if (xmlReader.IsStartElement()) { switch (xmlReader.Name) { case "Abstract": { xmlReader.Read(); fprDescription.VulnTitle = SanitizeVulnTitle(xmlReader.Value); fprDescription.RiskStatement = SanitizeRiskStatement(xmlReader.Value); break; } case "Explanation": { xmlReader.Read(); fprDescription.Description = SanitizeDescription(xmlReader.Value); break; } case "Recommendations": { xmlReader.Read(); fprDescription.FixText = SanitizeRecommendations(xmlReader.Value); break; } case "Reference": { string value = ObtainReferencesValue(xmlReader); string key = ObtainReferencesKey(xmlReader); string keyCheck; if (!fprDescription.References.TryGetValue(key, out keyCheck)) { fprDescription.References.Add(key, value); } break; } default: { break; } } } else if (xmlReader.NodeType == XmlNodeType.EndElement && xmlReader.Name == "Description") { fprDescriptionList.Add(fprDescription); return; } } } catch (Exception exception) { log.Error("Unable to parse FVDL Description node."); throw exception; } }