VS下SQL防注入

  1. //在global.asax里添加如下代码段
  2. protected void Application_BeginRequest(Object sender, EventArgs e) 
  3.         { 
  4.             //SQL防注入 
  5.             string Sql_1 = "exec |insert+ |select+ |delete |update |count |chr |mid |master+ |truncate |char |declare |drop+ |drop+table |creat+ |creat+table"
  6.             string Sql_2 = "exec+ |insert+ |delete+ |update+ |count( |count+ |chr+ |+mid( |+mid+ |+master+ |truncate+ |char+ |+char( |declare+ |drop+ |creat+ |drop+table |creat+table"
  7.             string[] sql_c = Sql_1.Split(' |'); 
  8.             string[] sql_c1 = Sql_2.Split(' |'); 
  9.    
  10.             if(Request.QueryString != null
  11.             { 
  12.                 foreach (string sl in sql_c) 
  13.                 { 
  14.                     if(Request.QueryString.ToString().ToLower().IndexOf(sl.Trim()) >=0) 
  15.                     { 
  16.                         Response.Write("警告!你的IP已经被记录!");//吓唬人的 
  17.                         Response.Write(sl); 
  18.                         Response.Write(Request.QueryString.ToString()); 
  19.                         //System.Windows.Forms.MessageBox.Show("禁止提交外部数据","1",System.Windows.F 
  20.                         //orms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Error,System.Windows.Forms.MessageBoxDefaultButton.Button1,System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly); 
  21.                         //Response.Redirect("http://www.163.com"); 
  22.                         Response.End(); 
  23.                         break
  24.                     } 
  25.                 } 
  26.             } 
  27.     
  28.             if(Request.Form.Count > 0) 
  29.             { 
  30.      
  31.                 string s1 = Request.ServerVariables["SERVER_NAME"].Trim();//服务器名称 
  32.                 if(Request.ServerVariables["HTTP_REFERER"] != null
  33.                 { 
  34.                     string s2 = Request.ServerVariables["HTTP_REFERER"].Trim();//http接收的名称 
  35.                     string s3 = ""
  36.                     if(s1.Length > (s2.Length -7)) 
  37.                     { 
  38.                         s3 = s2.Substring(7); 
  39.                     } 
  40.                     else 
  41.                     { 
  42.                         s3 = s2.Substring(7,s1.Length); 
  43.                     } 
  44.                     if(s3 != s1) 
  45.                     { 
  46.                         Response.Write("你的IP已被记录!警告!");//吓人的 
  47.                         //System.Windows.Forms.MessageBox.Show("禁止提交外部数据","1",System.Windows.Forms.MessageBoxButtons.OK,Sy 
  48.                         //stem.Windows.Forms.MessageBoxIcon.Error,System.Windows.Forms.MessageBoxDefaultButton.Button1,System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly); 
  49.                         //Response.Redirect("http://www.163.com"); 
  50.                         Response.End(); 
  51.                     } 
  52.                 }  
  53.             } 
  54.         } 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值