日期:2014-05-16  浏览次数:20414 次

SQL注入攻击规则库
      各位前辈好,我正在编写关于SQL注入的过滤器模块,附加于服务器中进行过滤。除了对一些关键字进行过滤,为了不限制更多的功能,我想对一些常用的攻击语句进行正则表达式的匹配过滤,可是现在不知道该过滤什么样的语句了,除了特别常用的恒真、恒假、or、and、;、--等,还想过滤可以查询到各种数据库类型、系统表等信息。我希望前辈们谁做过这个方向,能给我提些建议或者更好的思路,谢谢各位老师!
  Ps.是在.NET平台下的Web应用
------解决方案--------------------
 public static SqlConnection GreatConn()//创建数据库链接
        {
            string ss1 = "and,exec,insert,select,delete,update,count,chr,mid,master,truncate,char,declare";
            String[] sArray = ss1.Split(',');

            for (int i = 0; i < sArray.Length - 1; i++)
            {
                foreach (string tempLoopVar_SQL_Get in System.Web.HttpContext.Current.Request.QueryString)
                {
                    string SQL_Get = tempLoopVar_SQL_Get;
                    if (System.Web.HttpContext.Current.Request.QueryString[SQL_Get].Contains(sArray[i]) == true)
                    {
                        System.Web.HttpContext.Current.Response.Write("请不要尝试进行SQL注入!");
                        System.Web.HttpContext.Current.Response.End();
                    }
                }

                foreach (string tempLoopVar_Sql_Post in System.Web.HttpContext.Current.Request.Form)
                {
                    string Sql_Post = tempLoopVar_Sql_Post;
                    if (System.Web.HttpContext.Current.Request.Form[Sql_Post].Contains(sArray[i]) == true)
                    {
                        System.Web.HttpContext.Current.Response.Write("请不要尝试进行SQL注入!");
                        System.Web.HttpContext.Current.Response.End();
       &nb