private ItemType CreateTextFileContentItemType(string filepath, string pattern, int instance, string text)
        {
            var status = StatusEnumeration.exists;
            EntityItemAnySimpleType textEntity = null;

            if (string.IsNullOrEmpty(text))
            {
                status = StatusEnumeration.doesnotexist;
            }
            else
            {
                textEntity = OvalHelper.CreateEntityItemAnyTypeWithValue(text);
            }

            return(new textfilecontent_item()
            {
                status = status,
                pattern = OvalHelper.CreateItemEntityWithStringValue(pattern),
                instance = OvalHelper.CreateItemEntityWithIntegerValue(instance.ToString()),
                filename = OvalHelper.CreateItemEntityWithStringValue(Path.GetFileName(filepath)),
                path = OvalHelper.CreateItemEntityWithStringValue(Path.GetDirectoryName(filepath)),
                filepath = OvalHelper.CreateItemEntityWithStringValue(filepath),
                text = textEntity
            });
        }
示例#2
0
 private OVAL.SystemCharacteristics.Unix.process_item CreateProcessItem(UnixProcessInfo targetProcess)
 {
     return(new OVAL.SystemCharacteristics.Unix.process_item()
     {
         command = OvalHelper.CreateItemEntityWithStringValue(targetProcess.Command),
         pid = OvalHelper.CreateItemEntityWithIntegerValue(targetProcess.Pid.ToString()),
         ppid = OvalHelper.CreateItemEntityWithIntegerValue(targetProcess.PPid.ToString()),
         priority = OvalHelper.CreateItemEntityWithIntegerValue(targetProcess.Prio.ToString()),
         tty = OvalHelper.CreateItemEntityWithStringValue(targetProcess.Tty),
         user_id = OvalHelper.CreateItemEntityWithIntegerValue(targetProcess.User),
         start_time = new OVAL.SystemCharacteristics.EntityItemStringType()
         {
             status = OVAL.SystemCharacteristics.StatusEnumeration.notcollected
         },
         exec_time = new OVAL.SystemCharacteristics.EntityItemStringType()
         {
             status = OVAL.SystemCharacteristics.StatusEnumeration.notcollected
         },
         ruid = new OVAL.SystemCharacteristics.EntityItemIntType()
         {
             status = OVAL.SystemCharacteristics.StatusEnumeration.notcollected
         },
         scheduling_class = new OVAL.SystemCharacteristics.EntityItemStringType()
         {
             status = OVAL.SystemCharacteristics.StatusEnumeration.notcollected
         }
     });
 }
示例#3
0
        protected override IEnumerable <Common.BasicClasses.CollectedItem> collectDataForSystemItem(OVAL.SystemCharacteristics.ItemType systemItem)
        {
            CiscoIOSVersion myVersion = CiscoIOSHelper.CiscoGetVersion(TelnetConnection);

            version_item vItem = (version_item)systemItem;

            vItem.mainline_rebuild = OvalHelper.CreateItemEntityWithStringValue(myVersion.MainlineRebuild);
            vItem.major_release    = OvalHelper.CreateItemEntityWithStringValue(myVersion.MajorRelease);
            vItem.major_version    = OvalHelper.CreateItemEntityWithIntegerValue(myVersion.MajorVersion.ToString());
            vItem.minor_version    = OvalHelper.CreateItemEntityWithIntegerValue(myVersion.MinorVersion.ToString());
            if (myVersion.Rebuild >= 0)
            {
                vItem.rebuild = OvalHelper.CreateItemEntityWithIntegerValue(myVersion.Rebuild.ToString());
            }
            if (myVersion.Release >= 0)
            {
                vItem.release = OvalHelper.CreateItemEntityWithIntegerValue(myVersion.Release.ToString());
            }
            vItem.subrebuild       = OvalHelper.CreateItemEntityWithStringValue(myVersion.SubRebuild);
            vItem.train_identifier = OvalHelper.CreateItemEntityWithStringValue(myVersion.TrainIdentifier);
            vItem.train_number     = OvalHelper.CreateItemEntityWithStringValue(myVersion.TrainNumber);
            vItem.version_string   = new EntityItemIOSVersionType {
                Value = myVersion.VersionString
            };

            return(new ItemTypeHelper().CreateCollectedItemsWithOneItem(systemItem, BuildExecutionLog()));
        }
        protected override IEnumerable <CollectedItem> collectDataForSystemItem(ItemType systemItem)
        {
            CreatePasswordItemsCollectorInstance();
            var passwordItem = (password_item)systemItem;

            try
            {
                var passwordInfo = this.TryToCollectPasswordItem(passwordItem.username.Value);
                passwordItem.gcos       = OvalHelper.CreateItemEntityWithStringValue(passwordInfo.Gecos);
                passwordItem.group_id   = OvalHelper.CreateItemEntityWithIntegerValue(passwordInfo.Gid);
                passwordItem.home_dir   = OvalHelper.CreateItemEntityWithStringValue(passwordInfo.HomeDir);
                passwordItem.last_login = new EntityItemIntType()
                {
                    status = StatusEnumeration.notcollected
                };
                passwordItem.login_shell = OvalHelper.CreateItemEntityWithStringValue(passwordInfo.Shell);
                passwordItem.password    = OvalHelper.CreateItemEntityWithStringValue(passwordInfo.Password);
                passwordItem.user_id     = OvalHelper.CreateItemEntityWithIntegerValue(passwordInfo.Uid);
            }
            catch (PasswordItemNotExistsException)
            {
                passwordItem.status = StatusEnumeration.doesnotexist;
            }


            return(new ItemTypeHelper().CreateCollectedItemsWithOneItem(systemItem, BuildExecutionLog()));
        }
示例#5
0
 private ItemType CreateFileItem()
 {
     return(new unix.file_item()
     {
         a_time = OvalHelper.CreateItemEntityWithIntegerValue("201009221850"),
         c_time = OvalHelper.CreateItemEntityWithIntegerValue("201009011850"),
         type = OvalHelper.CreateItemEntityWithStringValue("text"),
     });
 }
示例#6
0
        private void MapLockoutPoliciesToLockoutItemType(lockoutpolicy_item lockoutItemType, PasswordPolicyHelper.USER_MODALS_INFO_3 policies)
        {
            var duration           = policies.usrmod3_lockout_duration.ToString();
            var observationWindows = policies.usrmod3_lockout_observation_window.ToString();
            var threshold          = policies.usrmod3_lockout_threshold.ToString();

            lockoutItemType.lockout_duration           = OvalHelper.CreateItemEntityWithIntegerValue(duration);
            lockoutItemType.lockout_observation_window = OvalHelper.CreateItemEntityWithIntegerValue(observationWindows);
            lockoutItemType.lockout_threshold          = OvalHelper.CreateItemEntityWithIntegerValue(threshold);
        }
示例#7
0
 private textfilecontent_item CreateFakeTextFileContentItem(
     string filepath, string path, string filename, string pattern, string instance)
 {
     return(new textfilecontent_item()
     {
         filepath = OvalHelper.CreateItemEntityWithStringValue(filepath),
         path = (path == null) ? null : OvalHelper.CreateItemEntityWithStringValue(path),
         filename = (filename == null) ? null : OvalHelper.CreateItemEntityWithStringValue(filename),
         pattern = (pattern == null) ? null : OvalHelper.CreateItemEntityWithStringValue(pattern),
         instance = (instance == null) ? null : OvalHelper.CreateItemEntityWithIntegerValue(instance)
     });
 }
        private void MapPasswrodPolicyToPasswordPolicyItemType(passwordpolicy_item passwordItemType, PasswordPolicyHelper.USER_MODALS_INFO_0 passwordPolicies)
        {
            var maxPasswordAge        = passwordPolicies.usrmod0_max_passwd_age.ToString();
            var minPasswordAge        = passwordPolicies.usrmod0_min_passwd_age.ToString();
            var minPasswordLength     = passwordPolicies.usrmod0_min_passwd_len.ToString();
            var passwordHistoryLength = passwordPolicies.usrmod0_password_hist_len.ToString();

            passwordItemType.max_passwd_age    = OvalHelper.CreateItemEntityWithIntegerValue(maxPasswordAge);
            passwordItemType.min_passwd_age    = OvalHelper.CreateItemEntityWithIntegerValue(minPasswordAge);
            passwordItemType.min_passwd_len    = OvalHelper.CreateItemEntityWithIntegerValue(minPasswordLength);
            passwordItemType.password_hist_len = OvalHelper.CreateItemEntityWithIntegerValue(passwordHistoryLength);
        }
示例#9
0
 private ItemType CreateTextFileContentItem(
     string filepath, string path, string filename, string pattern, string instance, string text)
 {
     return(new textfilecontent_item()
     {
         filepath = OvalHelper.CreateItemEntityWithStringValue(filepath),
         path = OvalHelper.CreateItemEntityWithStringValue(path),
         filename = OvalHelper.CreateItemEntityWithStringValue(filename),
         pattern = OvalHelper.CreateItemEntityWithStringValue(pattern),
         instance = OvalHelper.CreateItemEntityWithIntegerValue(instance),
         text = OvalHelper.CreateEntityItemAnyTypeWithValue(text)
     });
 }
示例#10
0
        public void Should_be_possible_to_collect_a_process_item()
        {
            var objectCollector = new ProcessObjectCollector();

            var collectedItems =
                objectCollector
                .CollectDataForSystemItem(
                    new OVAL.SystemCharacteristics.Unix.process_item()
            {
                command = OvalHelper.CreateItemEntityWithStringValue("ssh"),
                pid     = OvalHelper.CreateItemEntityWithIntegerValue("30"),
                ppid    = OvalHelper.CreateItemEntityWithIntegerValue("0")
            });

            ItemTypeChecker.DoBasicAssertForCollectedItems(collectedItems, 1, typeof(OVAL.SystemCharacteristics.Unix.process_item), true);
            var collectedProcessItem = (OVAL.SystemCharacteristics.Unix.process_item)collectedItems.First().ItemType;

            ItemTypeEntityChecker.AssertItemTypeEntity(collectedProcessItem.command, "ssh");
            ItemTypeEntityChecker.AssertItemTypeEntity(collectedProcessItem.pid, "30");
            ItemTypeEntityChecker.AssertItemTypeEntity(collectedProcessItem.ppid, "0");
        }
示例#11
0
        public IEnumerable <ItemType> GetItemsToCollect(Definitions.ObjectType objectType, VariablesEvaluated variables)
        {
            var sapcodeObjectType = (sapcode_object)objectType;
            var variableEvaluator = new VariableEntityEvaluator(variables);
            var issues            = variableEvaluator.EvaluateVariableForEntity(((EntitySimpleBaseType)sapcodeObjectType.Items[sapcodeObjectType.ItemsElementName.ToList().IndexOf(SapCodeObjectItemsChoices.issue)]));
            var systemNames       = variableEvaluator.EvaluateVariableForEntity(((EntitySimpleBaseType)sapcodeObjectType.Items[sapcodeObjectType.ItemsElementName.ToList().IndexOf(SapCodeObjectItemsChoices.system_name)]));
            var itemList          = new List <ItemType>();

            foreach (var systemName in systemNames)
            {
                foreach (var issueNumber in issues)
                {
                    itemList.Add(new sapcode_item()
                    {
                        issue       = OvalHelper.CreateItemEntityWithIntegerValue(issueNumber),
                        system_name = OvalHelper.CreateItemEntityWithIntegerValue(systemName)
                    });
                }
            }

            return(itemList.ToArray());
        }
示例#12
0
        protected override IEnumerable <CollectedItem> collectDataForSystemItem(Modulo.Collect.OVAL.SystemCharacteristics.ItemType systemItem)
        {
            var fileItem = (file_item)systemItem;

            try
            {
                var completeFilepath       = GetCompleteFilepath(fileItem);
                var collectedVariableValue = this.TryToCollectFile(completeFilepath);

                var shortFileTime = this.ToShortFileTime(collectedVariableValue.LastModified);
                fileItem.m_time   = OvalHelper.CreateItemEntityWithIntegerValue(shortFileTime);
                fileItem.filepath = OvalHelper.CreateItemEntityWithStringValue(completeFilepath);
                fileItem.size     = OvalHelper.CreateItemEntityWithIntegerValue(collectedVariableValue.FileSize.ToString());
                fileItem.type     = OvalHelper.CreateItemEntityWithStringValue(collectedVariableValue.FileType);

                fileItem.suid   = OvalHelper.CreateBooleanEntityItemFromBoolValue((collectedVariableValue.Mode & 0x0800) != 0);
                fileItem.sgid   = OvalHelper.CreateBooleanEntityItemFromBoolValue((collectedVariableValue.Mode & 0x0400) != 0);
                fileItem.sticky = OvalHelper.CreateBooleanEntityItemFromBoolValue((collectedVariableValue.Mode & 0x0200) != 0);
                fileItem.uread  = OvalHelper.CreateBooleanEntityItemFromBoolValue((collectedVariableValue.Mode & 0x0100) != 0);
                fileItem.uwrite = OvalHelper.CreateBooleanEntityItemFromBoolValue((collectedVariableValue.Mode & 0x0080) != 0);
                fileItem.uexec  = OvalHelper.CreateBooleanEntityItemFromBoolValue((collectedVariableValue.Mode & 0x0040) != 0);
                fileItem.gread  = OvalHelper.CreateBooleanEntityItemFromBoolValue((collectedVariableValue.Mode & 0x0020) != 0);
                fileItem.gwrite = OvalHelper.CreateBooleanEntityItemFromBoolValue((collectedVariableValue.Mode & 0x0010) != 0);
                fileItem.gexec  = OvalHelper.CreateBooleanEntityItemFromBoolValue((collectedVariableValue.Mode & 0x0008) != 0);
                fileItem.oread  = OvalHelper.CreateBooleanEntityItemFromBoolValue((collectedVariableValue.Mode & 0x0004) != 0);
                fileItem.owrite = OvalHelper.CreateBooleanEntityItemFromBoolValue((collectedVariableValue.Mode & 0x0002) != 0);
                fileItem.oexec  = OvalHelper.CreateBooleanEntityItemFromBoolValue((collectedVariableValue.Mode & 0x0001) != 0);

                fileItem.group_id = OvalHelper.CreateItemEntityWithIntegerValue(collectedVariableValue.Group);
                fileItem.user_id  = OvalHelper.CreateItemEntityWithIntegerValue(collectedVariableValue.Owner);
            }
            catch (FileNotExistsException)
            {
                base.SetDoesNotExistStatusForItemType(systemItem, String.Format("{0}/{1}", fileItem.path.Value, fileItem.filename.Value));
            }

            return(new ItemTypeHelper().CreateCollectedItemsWithOneItem(systemItem, BuildExecutionLog()));
        }
示例#13
0
        public void FillItemTypeWithData(file_item newFileItem, object collectedData)
        {
            FileItemSystemData fileSystemData = (FileItemSystemData)collectedData;

            newFileItem.owner       = OvalHelper.CreateItemEntityWithStringValue(fileSystemData.Owner);
            newFileItem.size        = OvalHelper.CreateItemEntityWithIntegerValue(fileSystemData.Size.ToString());
            newFileItem.a_time      = OvalHelper.CreateItemEntityWithIntegerValue(fileSystemData.ATime.ToString());
            newFileItem.c_time      = OvalHelper.CreateItemEntityWithIntegerValue(fileSystemData.CTime.ToString());
            newFileItem.m_time      = OvalHelper.CreateItemEntityWithIntegerValue(fileSystemData.MTime.ToString());
            newFileItem.ms_checksum = OvalHelper.CreateItemEntityWithStringValue(fileSystemData.MS_Checksum);
            newFileItem.version     = OvalHelper.CreateVersionItemTypeWithValue(fileSystemData.Version);
            newFileItem.type        = new EntityItemFileTypeType()
            {
                Value = fileSystemData.Type
            };
            newFileItem.development_class = OvalHelper.CreateItemEntityWithStringValue(fileSystemData.DevelopmentClass);
            newFileItem.company           = OvalHelper.CreateItemEntityWithStringValue(fileSystemData.Company);
            newFileItem.internal_name     = OvalHelper.CreateItemEntityWithStringValue(fileSystemData.InternalName);
            newFileItem.language          = OvalHelper.CreateItemEntityWithStringValue(fileSystemData.Language);
            newFileItem.original_filename = OvalHelper.CreateItemEntityWithStringValue(fileSystemData.OriginalFilename);
            newFileItem.product_name      = OvalHelper.CreateItemEntityWithStringValue(fileSystemData.ProductName);
            newFileItem.product_version   = OvalHelper.CreateVersionItemTypeWithValue(fileSystemData.ProductVersion);
        }
示例#14
0
        protected override IEnumerable <CollectedItem> collectDataForSystemItem(ItemType systemItem)
        {
            base.ExecutionLogBuilder.CollectingDataFrom("SapCode Object");

            var sapCodeItem = ((sapcode_item)systemItem);

            //var systemId = Convert.ToInt32(sapCodeItem.system_name.Value);
            //var authResult = connectionProvider.authenticate("modulo", "modulo01");
            //if (!isSapInitialized)
            //{
            //    base.ExecutionLogBuilder.CollectingDataFrom(string.Format("Sap Connection for system {0} initialized.", systemId));

            //    isSapInitialized = true;
            //}
            //var issueResult = connectionProvider.scanIssueListBySystem(authResult.token, systemId, new[] { (long)Convert.ToInt32(sapCodeItem.issue.Value) });
            if (issueResult == null)
            {
                sapCodeItem.status = StatusEnumeration.notcollected;
            }
            else if (issueResult.status != "COMPLETE")
            {
                sapCodeItem.status = StatusEnumeration.error;
                if (!string.IsNullOrEmpty(issueResult.status))
                {
                    base.ExecutionLogBuilder.AddInfo("Issue Status: " + issueResult.status);
                }
                if (!string.IsNullOrEmpty(issueResult.internalErrorMessage))
                {
                    base.ExecutionLogBuilder.AddInfo("CC Internal Error message: " + issueResult.internalErrorMessage);
                }
            }
            else
            {
                var evidencesForThisIssue =
                    issueResult.evidenceList.Where(x => x.issueId == Convert.ToInt32(sapCodeItem.issue.Value)).ToList();
                var nIssuesForThisId = evidencesForThisIssue.Count;

                sapCodeItem.total_issues_found =
                    OvalHelper.CreateItemEntityWithIntegerValue(nIssuesForThisId.ToString());
                sapCodeItem.total_programs_scanned =
                    OvalHelper.CreateItemEntityWithIntegerValue(issueResult.totalProgramsScanned.ToString());
                var formattedEvidences = new List <EntityItemStringType>();
                foreach (var programEvidences in evidencesForThisIssue.GroupBy(x => x.programName))
                {
                    formattedEvidences.Add(
                        OvalHelper.CreateItemEntityWithStringValue(string.Format("Program name: '{0}'",
                                                                                 programEvidences.Key)));
                    foreach (var programEvidence in programEvidences)
                    {
                        formattedEvidences.Add(
                            OvalHelper.CreateItemEntityWithStringValue(string.Format("Line number: {0}",
                                                                                     programEvidence.lineNumber)));
                        formattedEvidences.Add(
                            OvalHelper.CreateItemEntityWithStringValue(string.Format("Details: {0}",
                                                                                     programEvidence.details)));
                    }
                }
                sapCodeItem.evidences = formattedEvidences.ToArray();
            }
            return(new ItemTypeHelper().CreateCollectedItemsWithOneItem(systemItem, BuildExecutionLog()));
        }