Example #1
0
        private WorkingSystem ObtainSystemInformation(XmlReader xmlReader)
        {
            try
            {
                WorkingSystem workingsystem = new WorkingSystem();

                while (xmlReader.Read())
                {
                    if (xmlReader.IsStartElement())
                    {
                        switch (xmlReader.Name)
                        {
                        case "HOST_NAME":
                        {
                            workingsystem.HostName = ObtainCurrentNodeValue(xmlReader);
                            break;
                        }

                        case "HOST_IP":
                        {
                            workingsystem.IpAddress = ObtainCurrentNodeValue(xmlReader);
                            break;
                        }

                        default:
                        { break; }
                        }
                    }
                    else if (xmlReader.NodeType == XmlNodeType.EndElement && xmlReader.Name.Equals("ASSET"))
                    {
                        break;
                    }
                }

                return(workingsystem);
            }
            catch (Exception exception)
            {
                log.Error("Unable to obtain host system information.");
                throw exception;
            }
        }
Example #2
0
        /// <summary>
        /// Reads *.ckl files exported from the DISA STIG Viewer and writes the results to the appropriate DataTables.
        /// </summary>
        /// <param name="fileName">Name of *.ckl file to be parsed.</param>
        /// <param name="mitigationsList">List of mitigation items for vulnerabilities to be read against.</param>
        /// <param name="systemName">Name of the system that the mitigations check will be run against.</param>
        /// <returns>string Value</returns>
        public string ReadCklFile(string fileName, ObservableCollection <MitigationItem> mitigationsList, string systemName)
        {
            try
            {
                if (fileName.IsFileInUse())
                {
                    log.Error(fileName + " is in use; please close any open instances and try again.");
                    return("Failed; File In Use");
                }
                fileNameWithoutPath = Path.GetFileName(fileName);
                groupName           = systemName;
                using (SQLiteTransaction sqliteTransaction = FindingsDatabaseActions.sqliteConnection.BeginTransaction())
                {
                    using (SQLiteCommand sqliteCommand = FindingsDatabaseActions.sqliteConnection.CreateCommand())
                    {
                        sqliteCommand.Parameters.Add(new SQLiteParameter("FindingType", "CKL"));
                        CreateAddGroupNameCommand(systemName, sqliteCommand);
                        CreateAddFileNameCommand(fileNameWithoutPath, sqliteCommand);
                        XmlReaderSettings xmlReaderSettings = GenerateXmlReaderSettings();
                        using (XmlReader xmlReader = XmlReader.Create(fileName, xmlReaderSettings))
                        {
                            while (xmlReader.Read())
                            {
                                if (xmlReader.IsStartElement())
                                {
                                    switch (xmlReader.Name)
                                    {
                                    case "ASSET":
                                    {
                                        workingSystem = ObtainSystemInformation(xmlReader);
                                        CreateAddAssetCommand(sqliteCommand);
                                        break;
                                    }

                                    case "STIG_INFO":
                                    {
                                        ObtainStigInfo(xmlReader);
                                        break;
                                    }

                                    case "VULN":
                                    {
                                        ParseVulnNode(xmlReader, sqliteCommand);
                                        break;
                                    }

                                    default:
                                    { break; }
                                    }
                                }
                            }
                        }
                    }
                    sqliteTransaction.Commit();
                }
                return("Processed");
            }
            catch (Exception exception)
            {
                log.Error("Unable to process CKL file.");
                log.Debug("Exception details:", exception);
                return("Failed; See Log");
            }
        }