http://www.vjsdn.com/bbs/bbsTopicDetails.aspx?pid=352
http://www.vjsdn.com/bbs/bbsTopicDetails.aspx?pid=448
这里有些解决方案,但还是被hackers找到入口,迫使我关掉其它页面,请高手们献良言,不胜感谢!!!另外Text字段被大量注入如 <script>www.xxx.com/0.js</script> 如何批量替换,请提供C#源代码.我另加分,谢谢!
http://www.vjsdn.com/bbs/bbsTopicDetails.aspx?pid=448
这里有些解决方案,但还是被hackers找到入口,迫使我关掉其它页面,请高手们献良言,不胜感谢!!!另外Text字段被大量注入如 <script>www.xxx.com/0.js</script> 如何批量替换,请提供C#源代码.我另加分,谢谢!
解决方案 »
- table 表格里面 怎么嵌入checkbox ?
- TextRenderer.DrawText有问题
- 中止正在运行的线程
- 如何禁止用户点击DataGrid改变目前选定的行(winform)
- 关于菜单自画问题,急!!!一经解答,立即散分!
- 如何实现在窗口的textbox中按回车后,光标自动跳到下一个textbox中
- 求助:在C#中,怎样查找调用API函数的写法
- c#的问题,客户机和服务器通信问题?
- 頁面更新的問題急。。。。。。。。。。。。。
- 为什么asp和aspx的server.urlencode会得到不同的结果。?
- 使用 visual stdio 2010 鼠标选中代码进行复制或粘贴时,窗口就会不停抖动
- 怎么通过取得的类型名进行强制类型转换
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;
}
操作数据库用存储过程参考
参考
string Temp = StrText;
if (StrText == "" || StrText == null)
{
Temp = "";
}
else
{
Temp = Temp.ToLower();
Temp = Temp.Replace("(", "(");
Temp = Temp.Replace(")", ")");
Temp = Temp.Replace("--", "");
Temp = Temp.Replace("/*", "");
Temp = Temp.Replace("*/", "");
Temp = Temp.Replace("delete", "");
Temp = Temp.Replace("drop", "");
Temp = Temp.Replace("create", "");
Temp = Temp.Replace("cast", "");
Temp = Temp.Replace("exec", "");
Temp = Temp.Replace("insert", "");
Temp = Temp.Replace("select", "");
Temp = Temp.Replace("update", "");
Temp = Temp.Replace("grant", "");
Temp = Temp.Replace("alter", "");
Temp = Temp.Replace("len", "");
Temp = Temp.Replace("and", "");
Temp = Temp.Replace("%", "%");
Temp = Temp.Replace("'", " ’"); } return Temp;
}
Sql 里面,如果有规律的注入字符,你就写个replace替换,要是没有规律的,呵呵,用数据库备份吧---例如:
update TableName set a=a.Replace('<script>www.xxx.com/0.js </script>','')
祝你好运!
{
string Temp = StrText;
//......
}
DECLARE @fieldtype sysname
SET @fieldtype='varchar'
--删除处理
DECLARE hCForEach CURSOR GLOBAL
FOR
SELECT N'update '+QUOTENAME(o.name)
+N' set '+ QUOTENAME(c.name) + N' = replace(' + QUOTENAME(c.name) + ',''<script_src=http://ucmal.com/0.js> </script>'','''')'
FROM sysobjects o,syscolumns c,systypes t
WHERE o.id=c.id
AND OBJECTPROPERTY(o.id,N'IsUserTable')=1
AND c.xusertype=t.xusertype
AND t.name=@fieldtype
EXEC sp_MSforeach_Worker @command1=N'?'先执行SET @fieldtype='varchar'
再SET @fieldtype='nvarchar'再SET @fieldtype='ntext'
----------------------------------
当SET @fieldtype='ntext' 时运行出错.ntext字段能用replace方法?????????????
???????????????????????Server: Msg 8116, Level 16, State 1, Line 1
函数 replace 的参数 1 的数据类型 ntext 无效。
希望对你有用! O(∩_∩)O~
这个方法适合于过滤要保存到数据库的参数的方法。
如果SQL存在漏洞,黑客们会利用操作数据库的语句,例如添加语句在字段的值里面附带 cast 或 create ,当数据库在执行的期间会创建相应的过程或方法,以便他们后续的操控。
多以过滤掉这个对sql敏感的关键字。对好使用 SqlParameter 操作数据库。 呵呵