1: /// <summary>
2: ///SqlInject 的摘要说明
3: /// </summary>
4: public class SqlInject : System.Web.UI.Page
5: {6: //检测到注入后的处理方式: 0:仅警告;1:警告+记录;2:警告+自定义错误页面;3:警告+记录+自定义错误页面
7: private const int _type = 0;
8: private const string errRedirectPage = "/err.aspx";
9: 10: //如果记录注入信息,那么请设置:errMDBpath:数据库路径
11: private const string errMDBpath = "/SqlInject.mdb";
12: 13: 14: //过滤特征字符
15: //过滤特征字符
16: private static string StrKeyWord = ConfigurationManager.AppSettings["SqlKeyWord"]; //@"select|insert|delete|from|count(|drop table|update|truncate|asc(|mid(|char(|xp_cmdshell|exec|master|net local group administrators|net user|or|and";
17: private static string StrRegex = ConfigurationManager.AppSettings["SqlRegex"]; //@";|/|(|)|[|]|{|}|%|@|*|'|!"; // 原始过滤条件:【-|;|,|/|(|)|[|]|{|}|%|@|*|'|!】
18: 19: private HttpRequest request;
20: public SqlInject(System.Web.HttpRequest _request)
21: {22: this.request = _request;
23: }24: ///<summary>
25: ///检测SQL注入及记录、显示出错信息
26: ///</summary>
27: public void CheckSqlInject()
28: {29: bool isInject = false;
30: if (CheckRequestQuery() || CheckRequestForm())
31: {32: isInject = true;
33: }34: else
35: {36: return;
37: } 38: 39: switch (_type)
40: {41: case 0:
42: ShowErr();43: break;
44: case 1:
45: ShowErr(); 46: SaveToMdb();47: break;
48: case 2:
49: ShowErr();50: string temp;
51: System.Web.HttpContext.Current.Response.Write("<script>setTimeout(\"" + "location.href='" + errRedirectPage + "'" + "\",5000)</script>");
52: break;
53: case 3:
54: ShowErr(); 55: SaveToMdb();56: System.Web.HttpContext.Current.Response.Write("<script>setTimeout(\"" + "location.href='" + errRedirectPage + "'" + "\",5000)</script>");
57: break;
58: default:
59: break;
60: } 61: System.Web.HttpContext.Current.Response.End(); 62: 63: }64: private void SaveToMdb()
65: {66: OleDbConnection conn = new OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;Data Source=" + Server.MapPath(errMDBpath));
67: conn.Open(); 68: OleDbCommand cmd = conn.CreateCommand(); 69: 70: cmd.CommandText = "insert into [Record] (sIP,sDate,sPath) values ('" +
71: request.ServerVariables["REMOTE_ADDR"].ToString() + "','" +
72: DateTime.Now + "','" + request.ServerVariables["URL"].ToLower() + RelaceSingleQuotes(request.QueryString.ToString()) + "')";
73: int code = cmd.ExecuteNonQuery();
74: if (code == 1)
75: System.Web.HttpContext.Current.Response.Write("<br>****以上信息已记录至日志数据库****");
76: else
77: System.Web.HttpContext.Current.Response.Write("<br>日志数据库出错");
78: conn.Close(); 79: 80: }81: private string RelaceSingleQuotes(string _url)
82: {83: string URL = _url.Replace("'", "单引号");
84: return URL;
85: }86: private void ShowErr()
87: {88: //string msg = @"<font color=red>请不要尝试未授权之入侵检测!</font>" + @"<br><br>";
89: //msg += @"操作IP:" + request.ServerVariables["REMOTE_ADDR"] + @"<br>";
90: //msg += @"操作时间:" + DateTime.Now + @"<br>";
91: //msg += @"页面:" + request.ServerVariables["URL"].ToLower() + request.QueryString.ToString() + @"<br>";
92: //msg += @"<a href='#' onclick='javascript:window.close()'>关闭</a>";
93: //System.Web.HttpContext.Current.Response.Clear();
94: //System.Web.HttpContext.Current.Response.Write(msg);
95: System.Web.HttpContext.Current.Response.Write("<script>alert('请不要尝试未授权之入侵检测!');javascript:history.go(-1);</script>");
96: }97: ///<summary>
98: /// 特征字符
99: ///</summary>
100: public static string KeyWord
101: { 102: get 103: {104: return StrKeyWord;
105: } 106: }107: ///<summary>
108: /// 特征符号
109: ///</summary>
110: public static string RegexString
111: { 112: get 113: {114: return StrRegex;
115: } 116: }
- 全部评论(0)
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有