Esempio n. 1
0
        public SoftwareCheckResult CheckExploitCompatibility(long exploit, Node node)
        {
            SoftwareCheckResult result = SoftwareCheckResult.Invalid;

            Software libExploit;

            if (!Exloits.TryGetValue(exploit, out libExploit))
            {
                //just check numbers
                if (CheckAttackRule(exploit, node.Software))
                {
                    return(SoftwareCheckResult.Unknown);
                }
                else
                {
                    return(SoftwareCheckResult.Invalid);
                }
            }
            else
            {
                //check node types fit
                if (libExploit.NodeTypesString.Contains(node.NodeType))
                {
                    //just check numbers
                    if (CheckAttackRule(exploit, node.Software))
                    {
                        return(SoftwareCheckResult.Valid);
                    }
                    else
                    {
                        return(SoftwareCheckResult.Unknown);
                    }
                }
                else
                {
                    return(SoftwareCheckResult.Invalid);
                }
            }
        }
Esempio n. 2
0
        public void AddNewSoft(Software software, string networkName)
        {
            if (string.IsNullOrEmpty(software.SoftwareType))
            {
                software.SoftwareType = "";
            }


            if (string.IsNullOrEmpty(software.CodeStr))
            {
                software.CodeStr = "";
            }


            if (software.Code == 0)
            {
                software.Code = long.Parse(software.CodeStr);
            }

            if (software.Code != 0)
            {
                software.CodeStr = software.Code.ToString();
            }

            if (string.IsNullOrEmpty(software.Effect))
            {
                software.Effect = "";
            }


            if (string.IsNullOrEmpty(software.InevitableEffect))
            {
                software.InevitableEffect = "";
            }

            if (string.IsNullOrEmpty(software.NodeTypesString))
            {
                software.NodeTypesString = "";
            }

            if (string.IsNullOrEmpty(software.seenInNet))
            {
                software.seenInNet = "";
            }

            if (!string.IsNullOrEmpty(networkName))
            {
                if (!software.seenInNet.Contains(networkName))
                {
                    software.seenInNet += $",{networkName}";
                }
            }

            if (software.SoftwareType.Equals("exploit"))
            {
                if (Exloits.ContainsKey(software.Code))
                {
                    throw new ArgumentException($"Expolit #{software.Code} is duplicated in library.");
                }

                Software.Add(software);
                Exloits.Add(software.Code, software);
            }
            else if (software.SoftwareType.Equals("defence"))
            {
                if (Defences.ContainsKey(software.Code))
                {
                    throw new ArgumentException($"Defence #{software.Code} is duplicated in library.");
                }

                Defences.Add(software.Code, software);
                Software.Add(software);
            }
            else
            {
                if (Unknown.ContainsKey(software.Code))
                {
                    throw new ArgumentException($"Unknown soft #{software.Code} is duplicated in library.");
                }

                Unknown.Add(software.Code, software);
                Software.Add(software);
            }

            if (All.ContainsKey(software.Code))
            {
                throw new ArgumentException($"Software  #{software.Code} is duplicated in library.");
            }

            All.Add(software.Code, software);
        }