======================================================
060915
======================================================
放在公共页面的内容
#region SQL注入式攻击代码分析
/// <summary>
/// 处理用户提交的请求
/// </summary>
public void StartProcessRequest()
{
try
{
string getkeys = "";
//string sqlErrorPage = System.Configuration.ConfigurationSettings.AppSettings["CustomErrorPage"].ToString();
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]))
{
err(2);
//System.Web.HttpContext.Current.Response.Redirect(sqlErrorPage + "?err=非常抱歉,引发未知错误!");
//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 (!ProcessSqlStr(System.Web.HttpContext.Current.Request.Form[getkeys]))
{
err(2);
//System.Web.HttpContext.Current.Response.Redirect(sqlErrorPage + "?err=非常抱歉,引发未知错误!");
//System.Web.HttpContext.Current.Response.End();
}
}
}
}
catch
{
// 错误处理: 处理用户提交信息!
}
}
/// <summary>
/// 分析用户请求是否正常
/// </summary>
/// <param name="Str">传入用户提交数据</param>
/// <returns>返回是否含有SQL注入式攻击代码</returns>
private bool ProcessSqlStr(string Str)
{
Str = Str.ToLower();
bool ReturnValue = true;
try
{
if (Str != "")
{
string SqlStr = "or |and |exec |insert |select |delete |update |count | * |chr |mid |master |truncate |char |declare |drop |create |'";
string[] anySqlStr = SqlStr.Split('|');
foreach (string ss in anySqlStr)
{
if (Str.IndexOf(ss) >= 0)
{
ReturnValue = false;
}
}
}
}
catch
{
ReturnValue = false;
}
return ReturnValue;
}
#endregion
/// <summary>
/// 处理用户提交的请求
/// </summary>
public void StartProcessRequest()
{
try
{
string getkeys = "";
//string sqlErrorPage = System.Configuration.ConfigurationSettings.AppSettings["CustomErrorPage"].ToString();
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]))
{
err(2);
//System.Web.HttpContext.Current.Response.Redirect(sqlErrorPage + "?err=非常抱歉,引发未知错误!");
//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 (!ProcessSqlStr(System.Web.HttpContext.Current.Request.Form[getkeys]))
{
err(2);
//System.Web.HttpContext.Current.Response.Redirect(sqlErrorPage + "?err=非常抱歉,引发未知错误!");
//System.Web.HttpContext.Current.Response.End();
}
}
}
}
catch
{
// 错误处理: 处理用户提交信息!
}
}
/// <summary>
/// 分析用户请求是否正常
/// </summary>
/// <param name="Str">传入用户提交数据</param>
/// <returns>返回是否含有SQL注入式攻击代码</returns>
private bool ProcessSqlStr(string Str)
{
Str = Str.ToLower();
bool ReturnValue = true;
try
{
if (Str != "")
{
string SqlStr = "or |and |exec |insert |select |delete |update |count | * |chr |mid |master |truncate |char |declare |drop |create |'";
string[] anySqlStr = SqlStr.Split('|');
foreach (string ss in anySqlStr)
{
if (Str.IndexOf(ss) >= 0)
{
ReturnValue = false;
}
}
}
}
catch
{
ReturnValue = false;
}
return ReturnValue;
}
#endregion
#region 出错提示
/// <summary>
/// 出错提示
/// </summary>
/// <param name="Num">提示代码
/// 1=非常抱歉,您所选择的内容不存在!
/// 2=您没有进行此操作的权限,请与管理员联系
/// 3=操作成功!
/// </param>
///
public void err(int Num)
{
string str = "";
switch (Num)
{
case 1:
str = "非常抱歉,您所选择的内容不存在!";
break;
case 2:
str = "您没有进行此操作的权限,请与管理员联系!";
break;
case 3:
str = "操作成功!";
break;
default:
str = "非常抱歉,引发未知错误!";
break;
}
HttpContext.Current.Response.Redirect(ConfigurationManager.AppSettings["CustomErrorPage"].ToString() + "?err=" + str, true);
}
#endregion
/// <summary>
/// 出错提示
/// </summary>
/// <param name="Num">提示代码
/// 1=非常抱歉,您所选择的内容不存在!
/// 2=您没有进行此操作的权限,请与管理员联系
/// 3=操作成功!
/// </param>
///
public void err(int Num)
{
string str = "";
switch (Num)
{
case 1:
str = "非常抱歉,您所选择的内容不存在!";
break;
case 2:
str = "您没有进行此操作的权限,请与管理员联系!";
break;
case 3:
str = "操作成功!";
break;
default:
str = "非常抱歉,引发未知错误!";
break;
}
HttpContext.Current.Response.Redirect(ConfigurationManager.AppSettings["CustomErrorPage"].ToString() + "?err=" + str, true);
}
#endregion
放在配置文件里面的内容


