Пример #1
0
 /// <summary>
 /// Converts The Given String into none HALFFULLWIDTH String
 /// </summary>
 /// <param name="valueToClear">The Value To Be Cleared From The Input String</param>
 /// <param name="isItActive">Tells If The Module Should Be Activated</param>
 /// <returns>The Cleared String</returns>
 public static string ClearHalfFullWidth(string valueToClear, bool isItActive)
 {
     if (isItActive)
     {
         logger.Debug("Begin With CleanUp");
         if (GeneralUtilities.CheckString(valueToClear))
         {
             char[]        Characters = valueToClear.ToCharArray();
             StringBuilder results    = new StringBuilder(Characters.Length);
             for (int i = 0; i < Characters.Length; i++)
             {
                 int integerPresentation =
                     (int)Characters[i];
                 if (integerPresentation >= HALFFULLWIDTHBEGIN && integerPresentation <= HALFFULLWIDTHEND)
                 {
                     Characters[i] = (char)(integerPresentation - HALFFULLWIDTHCLEAR);
                 }
                 results.Append(Characters[i]);
             }
             valueToClear = results.ToString();
         }
     }
     return(valueToClear);
 }
Пример #2
0
        public object OldCreate(object parent, object configContext, XmlNode section)
        {
            log.Info("Beginning with the parsing of the web.config");
            //Read The Debug and Activity Attributes Before Creating The
            //Configuration Storage Object
            XmlElement activation = section["Activation"];

            log.Info("Reading The Main Attributes");
            string debug = activation.Attributes["Debug"].Value;

            if (XmlConvert.ToBoolean(debug))
            {
                BasicConfigurator.Configure(new TraceAppender(pat));
            }
            string active       = activation.Attributes["Active"].Value;
            string keywordcheck = activation.Attributes["KeywordCheck"].Value;
            string regexcheck   = activation.Attributes["RegExCheck"].Value;
            string cookies      = section["Handlers"].ChildNodes[0].Attributes["Action"].Value;
            string formfields   = section["Handlers"].ChildNodes[1].Attributes["Action"].Value;
            string querystring  = section["Handlers"].ChildNodes[2].Attributes["Action"].Value;

            log.Info("Finished successfully Mapping The Main Attributes");
            //DefenceMainSettings settings = new DefenceMainSettings();
            ViewStateStatus     viewStateHiding = new ViewStateStatus(true, ViewStateStatus.Method.GUID);
            DefenceMainSettings settings        = new DefenceMainSettings(viewStateHiding);
            ArrayList           ary             = settings.DenyList;

            if (keywordcheck == "true")
            {
                if (section["KeywordList"] != null && section["KeywordList"].ChildNodes != null)
                {
                    for (int i = 0; i < section["KeywordList"].ChildNodes.Count; i++)
                    {
                        string patterns = section["KeywordList"].ChildNodes[i].InnerText;
                        if (GeneralUtilities.CheckString(patterns))
                        {
                            try
                            {
                                string names = section["KeywordList"].ChildNodes[i].Attributes["name"].Value;
                                ary.Add(new Textrule(names, patterns, Rule.ActionTypes.Deny));
                            }
                            catch (Exception ex)
                            {
                                log.Error("Error in keywordlist configuration parsing", ex);
                            }
                        }
                    }
                }
            }
            if (regexcheck == "true")
            {
                for (int x = 0; x < section["RegExDeny"].ChildNodes.Count; x++)
                {
                    string patterns = section["RegExDeny"].ChildNodes[x].InnerText;
                    if (GeneralUtilities.CheckString(patterns))
                    {
                        try
                        {
                            ary.Add(new Regexrule(section["RegExDeny"].ChildNodes[x].Attributes["name"].Value, patterns, Rule.ActionTypes.Deny));
                        }
                        catch (Exception ex)
                        {
                            log.Error("Error in regex configuration parsing", ex);
                        }
                    }
                }
            }
            settings.HandleCookies = int.Parse(cookies);
            settings.HandleForms   = int.Parse(formfields);
            settings.HandleQueries = int.Parse(querystring);
            //Disabled Prior To Release v0.3
            //settings.IsSqlInjectionBlock = (sqlinjection == "true"?true:false);
            settings.IsDebug  = XmlConvert.ToBoolean(debug);
            settings.IsActive = XmlConvert.ToBoolean(active);
            log.Info("Finished Parsing of The Web.Config");
            return(settings);
        }
Пример #3
0
        /// <summary>
        /// Converts The Given XmlNode into a Rule
        /// </summary>
        /// <param name="node">The XmlNode To Be Converted To Rule</param>
        /// <param name="ary">The Arraylist to be used to add the created rule</param>
        /// <returns></returns>
        public static Rule XmlToRule(XmlNode node, ArrayList ary)
        {
            IEnumerator enumator = node.Attributes.GetEnumerator();

            if (!GeneralUtilities.CheckString(node.InnerText))
            {
                return(null);
            }
            int    count = 0;
            string values = "", tip = "", rulename = "", action = "";

            while (enumator.MoveNext())
            {
                XmlAttribute atrb  = (XmlAttribute)enumator.Current;
                string       atrbb = atrb.Name.ToLower();

                StringBuilder attributebuild = new StringBuilder();
                attributebuild.Append("attribute name:");
                attributebuild.Append(atrbb);
                attributebuild.Append(" value:");
                attributebuild.Append(atrb.Value);

                log.Info(attributebuild.ToString());

                if (atrbb == "name" || atrbb == "action" || atrbb == "type")
                {
                    if (!GeneralUtilities.CheckString(atrb.Value))
                    {
                        break;
                    }
                }
                else
                {
                    continue;
                }

                if (atrbb == "name")
                {
                    rulename = atrb.Value;
                    count++;
                }
                else if (atrbb == "action")
                {
                    action = atrb.Value;
                    count++;
                }
                else if (atrbb == "type")
                {
                    tip = atrb.Value;
                    count++;
                }

                if (count == 3)
                {
                    values = node.InnerText;
                    count  = 0;
                    try
                    {
                        if ((Enum.Parse(typeof(RuleTypes), tip, true) != null) && (Enum.Parse(typeof(ActionTypes), action, true) != null))
                        {
                            object[] args = new object[3];

                            args[0] = rulename;
                            args[1] = values;
                            args[2] = Enum.Parse(typeof(ActionTypes), action, true);

                            Type tips = System.Type.GetType(typeof(Rule).Namespace + "." + tip);

                            object obj = Activator.CreateInstance(tips, args);

                            ary.Add(obj);

                            return((Rule)obj);
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex.Message);
                    }
                }
            }
            return(null);
        }