我的数据库所有表被注入JS代码了。
有什么办法过滤吗?我的整个网都是存储过程

解决方案 »

  1.   

    我的数据库所有表被注入JS代码了
    1:可能是人家直接在数据库UPdate的,看下日志,执行的SQL。。
    2:在C#里面拼接字符串和在存储过程里面拼接字符串是一个道理,不要以为用了存储过程就可以过滤非法字符关键还是看要怎么用法
      

  2.   

    /// <summary>
        /// 清除危险脚本
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static string GetSafeHtml(string html)
        {
            //过滤<script></script>标记
            html = Regex.Replace(html, @"<script[\s\S]+</script *>", "", RegexOptions.IgnoreCase);
            //过滤href=javascript: (<A>) 属性
            html = Regex.Replace(html, @" href *= *[\s\S]*script *:", "", RegexOptions.IgnoreCase);
            //过滤其它控件的on...事件
            html = Regex.Replace(html, @" on[\s\S]*=", " _disibledevent=", RegexOptions.IgnoreCase);
            //过滤iframe
            html = Regex.Replace(html, @"<iframe[\s\S]+</iframe *>", "", RegexOptions.IgnoreCase);
            //过滤frameset
            html = Regex.Replace(html, @"<frameset[\s\S]+</frameset *>", "", RegexOptions.IgnoreCase);        return html;
        }
      

  3.   

    sql 注入 要防范了
     
      

  4.   

    只能 过滤 sql 关键字
      

  5.   

    在global里过滤数据
    void Application_BeginRequest(Object sender, EventArgs e)
        {
            StartProcessRequest();    }
        private void StartProcessRequest()
        {
            try
            {
                string getkeys = "";
                string sqlErrorPage = "index.aspx";
                if (System.Web.HttpContext.Current.Request.QueryString != null)
                {                for (int i = 0; i < System.Web.HttpContext.Current.Request.QueryString.Count; i++)
                    {
                        getkeys = System.Web.HttpContext.Current.Request.QueryString.Keys[i];
                        if (!ProcessSqlStr(System.Web.HttpContext.Current.Request.QueryString[getkeys]))
                        {
                            System.Web.HttpContext.Current.Response.Redirect(sqlErrorPage);
                            System.Web.HttpContext.Current.Response.End();
                        }
                    }
                }
                if (System.Web.HttpContext.Current.Request.Form != null)
                {
                    for (int i = 0; i < System.Web.HttpContext.Current.Request.Form.Count; i++)
                    {
                        getkeys = System.Web.HttpContext.Current.Request.Form.Keys[i];
                        if (getkeys == "__VIEWSTATE") continue;
                        if (!ProcessSqlStr(System.Web.HttpContext.Current.Request.Form[getkeys]))
                        {
                            System.Web.HttpContext.Current.Response.Redirect(sqlErrorPage);
                            System.Web.HttpContext.Current.Response.End();
                        }
                    }
                }
            }
            catch
            {   
            }
        }
        private bool ProcessSqlStr(string Str)
        {
            bool ReturnValue = true;
            try
            {
                if (Str.Trim() != "")
                {
                    string SqlStr = "exec¦insert¦select¦delete¦master¦update¦truncate¦declare";
                    string[] anySqlStr = SqlStr.Split('¦');
                    foreach (string ss in anySqlStr)
                    {
                       if(!Str.ToLower().Contains("updatepanel"))
                       {
                        if (Str.ToLower().IndexOf(ss) >= 0)
                        {
                            ReturnValue = false;
                            break;
                        }
                       }
                    }
                }
            }
            catch
            {
                ReturnValue = false;
            }
            return ReturnValue;
        }
    通过存储过程,删除数据库中JS脚本