#region SQL注入式攻击代码分析
/// <summary>
/// 处理用户提交的请求
/// </summary>
private void StartProcessRequest()
{
try
{
string getkeys = ""; 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.Write("<h3>不能包含执行语句</h3>");
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]))
{
jcFAQApp.FAQ_Util.Log.WriteMessage("<font color:red>注入攻击</red>", System.Web.HttpContext.Current.Request.UserHostAddress.ToString());
System.Web.HttpContext.Current.Response.Write("<h3>不能包含执行语句</h3>");
System.Web.HttpContext.Current.Response.End();
}
}
}
}
catch
{ }
}
/// <summary>
/// 分析用户请求是否正常
/// </summary>
/// <param name="Str">传入用户提交数据 </param>
/// <returns>返回是否含有SQL注入式攻击代码 </returns>
private bool ProcessSqlStr(string Str)
{
bool ReturnValue = true;
try
{
if (Str.Trim() != "")
{
//string SqlStr = "and ¦exec ¦insert ¦select ¦delete ¦update ¦count ¦* ¦chr ¦mid ¦master ¦truncate ¦char ¦declare";
string SqlStr = "exec ¦insert ¦select ¦delete ¦update ¦mid ¦master ¦truncate ¦declare";
string[] anySqlStr = SqlStr.Split('¦');
foreach (string ss in anySqlStr)
{
if (Str.ToLower().IndexOf(ss) >= 0)
{
ReturnValue = false;
break;
}
}
}
}
catch
{
ReturnValue = false;
}
return ReturnValue;
}
#endregion
jcFAQApp这个是什么意思,老报错。怎么解决。。望高手给菜鸟小弟我解决
/// <summary>
/// 处理用户提交的请求
/// </summary>
private void StartProcessRequest()
{
try
{
string getkeys = ""; 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.Write("<h3>不能包含执行语句</h3>");
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]))
{
jcFAQApp.FAQ_Util.Log.WriteMessage("<font color:red>注入攻击</red>", System.Web.HttpContext.Current.Request.UserHostAddress.ToString());
System.Web.HttpContext.Current.Response.Write("<h3>不能包含执行语句</h3>");
System.Web.HttpContext.Current.Response.End();
}
}
}
}
catch
{ }
}
/// <summary>
/// 分析用户请求是否正常
/// </summary>
/// <param name="Str">传入用户提交数据 </param>
/// <returns>返回是否含有SQL注入式攻击代码 </returns>
private bool ProcessSqlStr(string Str)
{
bool ReturnValue = true;
try
{
if (Str.Trim() != "")
{
//string SqlStr = "and ¦exec ¦insert ¦select ¦delete ¦update ¦count ¦* ¦chr ¦mid ¦master ¦truncate ¦char ¦declare";
string SqlStr = "exec ¦insert ¦select ¦delete ¦update ¦mid ¦master ¦truncate ¦declare";
string[] anySqlStr = SqlStr.Split('¦');
foreach (string ss in anySqlStr)
{
if (Str.ToLower().IndexOf(ss) >= 0)
{
ReturnValue = false;
break;
}
}
}
}
catch
{
ReturnValue = false;
}
return ReturnValue;
}
#endregion
jcFAQApp这个是什么意思,老报错。怎么解决。。望高手给菜鸟小弟我解决
解决方案 »
- 定义N个有规律的属性名,调用问题[在线]
- session 修改程序后失效了???
- 关于C#自定义命名空间之间的引用问题
- 求助:登入出现这种情况是什么原因??
- WEB页面继承的问题
- 谁帮忙下啊。我现在遇上很大的麻烦了。求正态分布函数的asp.net(vb.net)的编程
- 如何提供速度
- 提问啊 特急 。。代码有冲突
- 在js中我怎么这样写取不到页面上的值啊???
- 怎样找到Datagrid的页眉中的TextBox控件阿?我用DataGrid.Controls(0).Controls(0).findControl("TextBoxName"),但是不行阿
- 类似QQ农场的快速登录 思路
- 怎样实现同一个账号密码,能够在两个绝对对立的系统里面登录并操作
你没有添加对其引用所以会摄氏
你如果把小弟改成小M ,CSDN的高手会蜂拥而至
including me
添加引用
using 命名空间;
1.先在bin右键添加jcFAQApp.dll的引用
2.右键选中jcFAQApp --Reslove--选择 using.....
直接用参数化操作.省心省力
参数化,网上介绍的资料汗牛充栋
代码的写法有N多种,不过核心思想都是一样的.譬如传统的某个查询,你可能会写成
String strsql="select * from mynews where id ='"+bh+"'";
如果用参数化(注意第一句的不同)
string strsql = "select * from mynews where id = @bh";
SqlCommand cmd = new SqlCommand(strsql, con);//创建Command对象
cmd.Parameters.Add("@bh", SqlDbType.Int);//增加参数@bh
cmd.Parameters[0].Value = 4;//通过索引为参数赋值
SqlDataReader dr = cmd.ExecuteReader();//
区别就是你不用那么多Replace了~
用参数化方法,对于where id = @bh这样的条件
无论你在@bh中输入什么恶意的字符,对于执行效果而言,
你可以理解为:它们都被打包成一个字段值,而无非暴露在外面,来改变SQL语句的语义.