C#判断Sql攻击

来源:互联网 发布:rf mems 知乎 编辑:程序博客网 时间:2024/06/03 19:08
//判断是否存在sql攻击//input 用户提交的数据//true-存在攻击规则 false-没有攻击规则public bool CheckSqlHacker(string inputStr){            string SqlStr = @"and|or|exec|execute|insert|select|delete|update|alter|create|drop|count|\*|chr|char|asc|mid|substring|master|truncate|declare|xp_cmdshell|restore|backup|net +user|net +localgroup +administrators";            try            {                if (inputStr != null && inputStr != string.Empty)                {                    string str_Regex = @"\b(" + SqlStr + @")\b";                    Regex regex = new Regex(str_Regex, RegexOptions.IgnoreCase);                    if (regex.IsMatch(inputStr))                    {                        return true;                                         }                }            }            catch            {                return true;            }            return false;}
0 0