asp.net 注入 我的数据库所有表被注入JS代码了。有什么办法过滤吗?我的整个网都是存储过程 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我的数据库所有表被注入JS代码了1:可能是人家直接在数据库UPdate的,看下日志,执行的SQL。。2:在C#里面拼接字符串和在存储过程里面拼接字符串是一个道理,不要以为用了存储过程就可以过滤非法字符关键还是看要怎么用法 /// <summary> /// 清除危险脚本 /// </summary> /// <param name="source"></param> /// <returns></returns> public static string GetSafeHtml(string html) { //过滤<script></script>标记 html = Regex.Replace(html, @"<script[\s\S]+</script *>", "", RegexOptions.IgnoreCase); //过滤href=javascript: (<A>) 属性 html = Regex.Replace(html, @" href *= *[\s\S]*script *:", "", RegexOptions.IgnoreCase); //过滤其它控件的on...事件 html = Regex.Replace(html, @" on[\s\S]*=", " _disibledevent=", RegexOptions.IgnoreCase); //过滤iframe html = Regex.Replace(html, @"<iframe[\s\S]+</iframe *>", "", RegexOptions.IgnoreCase); //过滤frameset html = Regex.Replace(html, @"<frameset[\s\S]+</frameset *>", "", RegexOptions.IgnoreCase); return html; } sql 注入 要防范了 只能 过滤 sql 关键字 在global里过滤数据void Application_BeginRequest(Object sender, EventArgs e) { StartProcessRequest(); } private void StartProcessRequest() { try { string getkeys = ""; string sqlErrorPage = "index.aspx"; 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.Redirect(sqlErrorPage); 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])) { System.Web.HttpContext.Current.Response.Redirect(sqlErrorPage); System.Web.HttpContext.Current.Response.End(); } } } } catch { } } private bool ProcessSqlStr(string Str) { bool ReturnValue = true; try { if (Str.Trim() != "") { string SqlStr = "exec¦insert¦select¦delete¦master¦update¦truncate¦declare"; string[] anySqlStr = SqlStr.Split('¦'); foreach (string ss in anySqlStr) { if(!Str.ToLower().Contains("updatepanel")) { if (Str.ToLower().IndexOf(ss) >= 0) { ReturnValue = false; break; } } } } } catch { ReturnValue = false; } return ReturnValue; }通过存储过程,删除数据库中JS脚本 mysql中如何实现sql的charindex功能 asp.net 中的wsdl编译问题 一个简单的问题!!! 小问题,请大家帮忙,谢谢 gridview分页后就不强制换行了.二者怎么不兼容么? 请问一下 我的日历出现乱码 怎么解决 关闭子窗体问题(急!) ^^^^^^^^^^asp.net中如何截取字符串的前几个字符??? WEB程序中,可以多个用户同时打开数据吗? asp.net中如何建立框架,网页如何调用,如何建立菜单? 触发_RowCommand II5和IIS6
1:可能是人家直接在数据库UPdate的,看下日志,执行的SQL。。
2:在C#里面拼接字符串和在存储过程里面拼接字符串是一个道理,不要以为用了存储过程就可以过滤非法字符关键还是看要怎么用法
/// 清除危险脚本
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static string GetSafeHtml(string html)
{
//过滤<script></script>标记
html = Regex.Replace(html, @"<script[\s\S]+</script *>", "", RegexOptions.IgnoreCase);
//过滤href=javascript: (<A>) 属性
html = Regex.Replace(html, @" href *= *[\s\S]*script *:", "", RegexOptions.IgnoreCase);
//过滤其它控件的on...事件
html = Regex.Replace(html, @" on[\s\S]*=", " _disibledevent=", RegexOptions.IgnoreCase);
//过滤iframe
html = Regex.Replace(html, @"<iframe[\s\S]+</iframe *>", "", RegexOptions.IgnoreCase);
//过滤frameset
html = Regex.Replace(html, @"<frameset[\s\S]+</frameset *>", "", RegexOptions.IgnoreCase); return html;
}
void Application_BeginRequest(Object sender, EventArgs e)
{
StartProcessRequest(); }
private void StartProcessRequest()
{
try
{
string getkeys = "";
string sqlErrorPage = "index.aspx";
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.Redirect(sqlErrorPage);
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]))
{
System.Web.HttpContext.Current.Response.Redirect(sqlErrorPage);
System.Web.HttpContext.Current.Response.End();
}
}
}
}
catch
{
}
}
private bool ProcessSqlStr(string Str)
{
bool ReturnValue = true;
try
{
if (Str.Trim() != "")
{
string SqlStr = "exec¦insert¦select¦delete¦master¦update¦truncate¦declare";
string[] anySqlStr = SqlStr.Split('¦');
foreach (string ss in anySqlStr)
{
if(!Str.ToLower().Contains("updatepanel"))
{
if (Str.ToLower().IndexOf(ss) >= 0)
{
ReturnValue = false;
break;
}
}
}
}
}
catch
{
ReturnValue = false;
}
return ReturnValue;
}
通过存储过程,删除数据库中JS脚本