联系我们

为客户提供超预期的高品质网站设计!

拦截sql盲注,post提交和get提交,检测cookie等内容

2017-4-29 0:00:00

-----------------使用方法------------------------------------------------------------------
1.将App_Code目录拷贝到web根目录
假如已经存在App_Code目录,那直接把App_Code目录里的360safe.cs文件拷贝到当前的App_Code目录即可。

2.将Global.asax文件拷贝到web根目录
假如已经存在Global.asax文件,那直接把下面这段代码
     void Application_BeginRequest(object sender, EventArgs e)
    {

            if (Request.Cookies != null)
            {
                if (safe_360.CookieData())
                {
                    Response.Write("您提交的Cookie数据有恶意字符!");
                    Response.End();
                
                }

           
            }

            if (Request.UrlReferrer != null)
            {
                if (safe_360.referer())
                {
                    Response.Write("您提交的Referrer数据有恶意字符!");
                    Response.End();
                }
            }

            if (Request.RequestType.ToUpper() == "POST")
            {
                if (safe_360.PostData())
                {

                    Response.Write("您提交的Post数据有恶意字符!");
                    Response.End();
                }
            }
            if (Request.RequestType.ToUpper() == "GET")
            {
                if (safe_360.GetData())
                {
                    Response.Write("您提交的Get数据有恶意字符!");
                    Response.End();
                }
            }

         
    }
拷贝到当前的Global.asax文件里保存。



=========Global.asax=========

using System;
using System.Web;
using System.Text;
using System.Text.RegularExpressions;

public class safe_360
{

    private const string StrRegex = @"\b(alert|confirm|prompt)\b|^\+/v(8|9)|\b(and|or)\b.{1,6}?(=|>|<|\bin\b|\blike\b)|/\*.+?\*/|<\s*script\b|<\s*img\b|\bEXEC\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\s+(TABLE|DATABASE)";

    public static bool PostData()
    {
        bool result = false;

        for (int i = 0; i < HttpContext.Current.Request.Form.Count; i++)
        {
            result = CheckData(HttpContext.Current.Request.Form[i].ToString());
            if (result)
            {
                break;
            }
        }
        return result;
    }

 
    public static bool GetData()
    {
        bool result = false;

        for (int i = 0; i < HttpContext.Current.Request.QueryString.Count; i++)
        {
            result = CheckData(HttpContext.Current.Request.QueryString[i].ToString());
            if (result)
            {
                break;
            }
        }
        return result;
    }


    public static bool CookieData()
    {
        bool result = false;
        for (int i = 0; i < HttpContext.Current.Request.Cookies.Count; i++)
        {
            result = CheckData(HttpContext.Current.Request.Cookies[i].Value.ToLower());
            if (result)
            {
                break;
            }
        }
        return result;
   
    }
    public static bool referer()
    {
        bool result = false;
        return result = CheckData(HttpContext.Current.Request.UrlReferrer.ToString());
    }

    public static bool CheckData(string inputData)
    {
        if (Regex.IsMatch(inputData, StrRegex))
        {
            return true;
        }
        else
        {
            return false;
        }
    }

 
}



上一条新闻:jquery 隐藏没有内容的元素(循环做法)
下一条新闻:如何实现CSS限制字数,超出部份显示点点点...

 

400-6137-308 54057491 info@maolian.net