Function SafeRequest(ParaName,ParaType)
'--- 传入参数 ---
'ParaName:参数名称-字符型
'ParaType:参数类型-数字型(1表示以上参数是数字,0表示以上参数为字符)
Dim ParaValue
ParaValue=Request(ParaName)
If ParaType=1 then
If not isNumeric(ParaValue) then
Response.write "参数" & ParaName & "必须为数字型!"
Response.end
End if
Else
ParaValue=replace(ParaValue,"'","''")
End if
SafeRequest=ParaValue
End function
=========================================================
这个函数对于id为单个数字的用户来说已经安全了!它是从本质上防止了问题!而2楼那个看起来很专业!但防不住,人家可以用asc注入,这样排列组合一下,你的'|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare 这点是不够的
就可以这样获取参数:
dim temp
temp=SafeRequest("temp",0)
这样就可以截断单引号了,再进行其他处理(比如第一位是小数点,后面是数字),就可以放心操作数据库。
如果页面是这样:http://community.csdn.net/Expert/topic/4047/4047559.asp?temp=7490045
temp是数字,就用
dim temp
temp=SafeRequest("temp",1)
如果页面是这样:http://community.csdn.net/Expert/topic/4047/4047559.asp?temp=7490045&ty=abc&id=1
就用
dim temp,ty,id
temp=SafeRequest("temp",1)
ty=SafeRequest("ty",0)
id=SafeRequest("id",1)
Function SafeRequest(ParaName,ParaType)
'--- 传入参数 ---
'ParaName:参数名称-字符型
'ParaType:参数类型-数字型(1表示以上参数是数字,0表示以上参数为字符)
Dim ParaValue
ParaValue=Request(ParaName)
If ParaType=1 then
If not isNumeric(ParaValue) then
Response.write "参数" & ParaName & "必须为数字型!"
Response.end
End if
Else
ParaValue=replace(ParaValue,"'","''")
End if
SafeRequest=ParaValue
End function
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('SQL通用防注入系统提示↓nn请不要在参数中包含非法字符尝试注入!');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('SQL通用防注入系统提示↓nn请不要在参数中包含非法字符尝试注入!nnHTTP://www.521movie.com ');history.back(-1)</Script>"
Response.end
end if
next
next
end if