日期:2014-05-16  浏览次数:20767 次

求助:asp超级链接转递参数的过滤问题
我用以下链接向文件zxrd.asp传递两个变量PName和ckb_date

http://sekee.com/zxrd.asp?action=modify&PName=%B2%CE%BF%BC%CF%FB%CF%A2&index=1 
http://sekee.com/zxrd.asp?action=modify&PName=风云天下
http://sekee.com/zxrd.asp?action=modify&PName=风云天下&ckb_date=2012-05-04
http://sekee.com/zxrd.asp?action=modify&PName=%B2%CE%BF%BC%CF%FB%CF%A2&ckb_date=2012%2D05%2D04&index=1

为防止SQL注入,加上了GuoLv.asp文件进行过滤,但却把我自己要用的链接也过滤掉了,求助有没有办法即起到过滤作用,又能让我要的以上链接通过?

下面是GuoLv.asp文件的代码:

<%
dim sql_injdata 
SQL_injdata = "'|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare" 
SQL_inj = split(SQL_Injdata,"|") 
If Request.QueryString<>"" Then 
 For Each SQL_Get In Request.QueryString 
  For SQL_Data=0 To Ubound(SQL_inj) 
   if instr(Request.QueryString(SQL_Get),Sql_Inj(Sql_DATA))>0 Then 
    Response.Write "<Script Language=****>alert('请不要在参数中包含非法字符尝试注入!');history.back(-1)</Script>" 
    Response.end 
   end if 
  next 
 Next 
End If  

If Request.Form<>"" Then 
 For Each Sql_Post In Request.Form 
  For SQL_Data=0 To Ubound(SQL_inj) 
   if instr(Request.Form(Sql_Post),Sql_Inj(Sql_DATA))>0 Then 
    Response.Write "<Script Language=****>alert('请不要在参数中包含非法字符尝试注入!');history.back(-1)</Script>" 
    Response.end 
   end if 
  next 
 next 
end if  
%> 

------解决方案--------------------
这种过滤方法根本不靠谱,影响正常的功能。你可以去掉
------解决方案--------------------
%
------解决方案--------------------


最好的方法是在查询数据的时候使用参数方法,而不是拼接sql语句
------解决方案--------------------
用ADO对象插入数据,不要拼接SQL,用不着过滤的。
------解决方案--------------------
替换掉'就好了吧,构造sql注意验证数据有效性

PName=replace(request.querystring("PName")&"","'","")
ckb_date=request.querystring("ckb_date")&""
if not isdate(ckb_date) then
  response.write "非法的日期"
  response.end
end if
'构造sql语句执行查询