防SQL注入
最近中招<script src=http://s.see9.us/s.js></script>,比较郁闷,真是猖獗啊,
再回过头来看看代码中的拼接,发现几处Request.QueryString并不是用参数传值,没有做限制,估计就是漏洞点,只有在补充过滤类,来限制了
其实用重写来做,比较方便和安全,我看网上也有类似方法,但把过滤用StartProcessRequest()来实现,没有必要,并不是每个网页都有SQL操作.
如果中招,数据库中已经被插入字符代码,先删除数据,方法如下:[针对远程数据库,本机数据库,或者自己的主机,直接还原好]
在查询分析器中列出需要删除数据的表,如果某些表不删,在where后加 and a.name <> '不删数据表'
再把以前备份的数据建导进去,不要告诉我你重来没有备份过数据吧
再回过头来看看代码中的拼接,发现几处Request.QueryString并不是用参数传值,没有做限制,估计就是漏洞点,只有在补充过滤类,来限制了
1
/// <summary>
2
/// 过滤SQL注入关键字[post,get]
3
/// </summary>
4
/// <param name="pStr"></param>
5
/// <returns></returns>
6
public static string GetQueryStringSafe(string pStr)
7
{
8
bool IsValue = true;
9
if (pStr != null && pStr.Length > 0)
10
{
11
pStr = pStr.ToLower();
12
string strSQLin = "'|and|--|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare|;|&|%20|==|>|<";
13
string[] strSQLinGroup = strSQLin.Split(new char[] { '|' }, 23);//23个关键字,有待补充
14
for (int i = 0; i < strSQLinGroup.Length; i++)
15
{
16
if (pStr.IndexOf(strSQLinGroup[i]) >= 0)//表示存在
17
{
18
IsValue = false;
19
break;
20
}
21
}
22
}
23
else
24
{
25
IsValue = false;
26
}
27
if (IsValue)
28
{
29
return pStr;
30
}
31
else
32
return "";
33
}
只需要在你用到拼接时,检查一下![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
27
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
29
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
30
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
31
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
32
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
33
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
其实用重写来做,比较方便和安全,我看网上也有类似方法,但把过滤用StartProcessRequest()来实现,没有必要,并不是每个网页都有SQL操作.
如果中招,数据库中已经被插入字符代码,先删除数据,方法如下:[针对远程数据库,本机数据库,或者自己的主机,直接还原好]
在查询分析器中列出需要删除数据的表,如果某些表不删,在where后加 and a.name <> '不删数据表'
1
select 'truncate table ' +a.name+char(13)
2
from sysobjects a
3
where a.type= 'u'
4
order by a.name
然后复制查询出的内容,复制到查询分析器中执行![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
再把以前备份的数据建导进去,不要告诉我你重来没有备份过数据吧