示例#1
0
//        public void WriteAgentConfiguration(Cyberarms.IntrusionDetection.Api.Plugin.IAgentConfiguration agentConfiguration) {
//            // find the agent first
//            if (!Database.Instance.IsConfigured) configureDatabase();
//            Guid agentId = GetAgentId(agentConfiguration.AgentName);

//            string writeConfigCmd;
//            if (agentId != Guid.Empty) {
//                writeConfigCmd = @"update SecurityAgents set HardLockAttempts = @p2, HardLockTimeHours = @p3,
//LockForever = @p4, SoftLockAttempts = @p5, SoftLockTimeMinutes=@p6, OverwriteConfiguration=@p7 where AssemblyName = @p0";
//            } else {
//                // agent not configured in database
//                agentId = Guid.NewGuid();
//                writeConfigCmd = @"insert into SecurityAgents(AssemblyName, AgentId, HardLockAttempts, HardLockTimeHours,
//LockForever, SoftLockAttempts, SoftLockTimeMinutes, OverwriteConfiguration) values (@p0,@p1,@p2,@p3,@p4,@p5,@p6,@p7)";
//            }
//            Database.Instance.ExecuteNonQuery(writeConfigCmd, agentConfiguration.AssemblyName, agentId.ToString(),
//                agentConfiguration.HardLockAttempts, agentConfiguration.HardLockDurationHrs,
//                agentConfiguration.NeverUnlock, agentConfiguration.SoftLockAttempts, agentConfiguration.SoftLockDurationMins, agentConfiguration.OverwriteConfiguration);

//        }

        //public Guid GetAgentId(string displayName) {
        //    string cmd = "Select AgentId from  SecurityAgents where DisplayName like @p0";
        //    try {
        //        object result = Database.Instance.ExecuteScalar(cmd, displayName);
        //        Guid agentId;
        //        if (result != null && Guid.TryParse(result.ToString(), out agentId)) return agentId;
        //    } catch (Exception ex) {
        //        throw ex;
        //    }
        //    return Guid.Empty;
        //}

        public int GetSoftLockMinutes(SecurityAgent agent)
        {
            if (agent.OverrideConfig)
            {
                return(agent.SoftLockTimeMinutes);
            }
            return(SoftLockTimeMinutes);
        }
示例#2
0
 public void IncreaseStatistics(SecurityAgent agent, string statisticsColumn)
 {
     try {
         string sqlString = String.Format("Update AgentStatistics set {0}={0}+1 where AgentId=@p0", statisticsColumn);
         Database.Instance.ExecuteNonQuery(sqlString, agent.Id);
     } catch (Exception ex) {
         throw ex;
     }
 }
示例#3
0
 public void IncreaseFailedLoginStatistics(SecurityAgent agent)
 {
     if (!agentIds.Contains(agent.Id))
     {
         ConfigureStatistics(agent);
     }
     agent.FailedLogins++;
     IncreaseStatistics(agent, "FailedLogins");
 }
示例#4
0
        public void ConfigureStatistics(SecurityAgent agent)
        {
            string sqlString = "select count(*) from AgentStatistics where AgentId=@p0";
            object result    = Database.Instance.ExecuteScalar(sqlString, agent.Id);

            if (Db.DbValueConverter.ToInt(result) < 1)
            {
                sqlString = "insert into AgentStatistics(AgentId, FailedLogins, SoftLocks, HardLocks) values (@p0,0,0,0)";
                Database.Instance.ExecuteNonQuery(sqlString, agent.Id);
            }
            agentIds.Add(agent.Id);
        }
示例#5
0
        public int GetHardLockHours(SecurityAgent agent)
        {
            int hardLockHours;

            if (agent.OverrideConfig)
            {
                hardLockHours = agent.HardLockTimeHours;
                if (agent.LockForever)
                {
                    hardLockHours = (int)DateTime.MaxValue.Subtract(DateTime.Now).TotalHours;
                }
            }
            else
            {
                hardLockHours = HardLockTimeHours;
                if (LockForever)
                {
                    hardLockHours = (int)DateTime.MaxValue.Subtract(DateTime.Now).TotalHours;
                }
            }
            return(hardLockHours);
        }
示例#6
0
 public void IncreaseSoftLockStatistics(SecurityAgent agent)
 {
     agent.SoftLocks++;
     IncreaseStatistics(agent, "SoftLocks");
 }
示例#7
0
 public void IncreaseHardLockStatistics(SecurityAgent agent)
 {
     agent.HardLocks++;
     IncreaseStatistics(agent, "HardLocks");
 }
        public List <SecurityAgent> GetSecurityAgents(string fileName)
        {
            Assembly             assembly = Assembly.LoadFile(fileName);
            List <SecurityAgent> result   = new List <SecurityAgent>();

            foreach (Type type in assembly.GetTypes())
            {
                if (type.IsPublic && !type.IsAbstract)
                {
                    Type typeInterface = type.GetInterface(typeof(IAgentPlugin).ToString(), false);
                    //Make sure the interface we want to use actually exists
                    if (typeInterface != null)
                    {
                        try {
                            IAgentPlugin agentPlugin = (IAgentPlugin)Activator.CreateInstanceFrom(fileName, type.FullName.ToString()).Unwrap();
                            if (agentPlugin != null)
                            {
                                SecurityAgent securityAgent = new SecurityAgent();
                                securityAgent.AssemblyName = assembly.FullName;
                                if (agentPlugin is IExtendedInformation)
                                {
                                    IExtendedInformation exInfo = (IExtendedInformation)agentPlugin;
                                    securityAgent.DisplayName    = exInfo.DisplayName;
                                    securityAgent.UnselectedIcon = exInfo.UnselectedIcon;
                                    securityAgent.SelectedIcon   = exInfo.SelectedIcon;
                                    securityAgent.Icon           = exInfo.Icon;
                                    securityAgent.Id             = exInfo.Id;
                                }
                                else
                                {
                                    securityAgent.DisplayName    = type.FullName;
                                    securityAgent.UnselectedIcon = global::Cyberarms.IntrusionDetection.Shared.Resources.agent15px_default_dark;
                                    securityAgent.SelectedIcon   = global::Cyberarms.IntrusionDetection.Shared.Resources.agent15px_default_white;
                                    securityAgent.Icon           = global::Cyberarms.IntrusionDetection.Shared.Resources.agent15px_default_dark;
                                }
                                securityAgent.Name                = type.FullName;
                                securityAgent.Enabled             = false;
                                securityAgent.FailedLogins        = 0;
                                securityAgent.HardLockAttempts    = 10;
                                securityAgent.HardLocks           = 0;
                                securityAgent.HardLockTimeHours   = 24;
                                securityAgent.AssemblyFilename    = fileName;
                                securityAgent.SoftLockAttempts    = 3;
                                securityAgent.SoftLocks           = 0;
                                securityAgent.SoftLockTimeMinutes = 20;
                                securityAgent.OverrideConfig      = false;
                                if (agentPlugin.Configuration.AgentSettings != null)
                                {
                                    securityAgent.CustomConfiguration = GetCustomConfigurationObjects(agentPlugin.Configuration.AgentSettings);
                                }
                                result.Add(securityAgent);
                            }
                        } catch (Exception exception) {
                            System.Diagnostics.Debug.WriteLine(exception.Message);
                            throw exception;
                        }
                    }
                }
            }
            return(result);
        }