asp 实现对SQL注入危险字符进行重编码处理的函数
%
'******************************
'函数:CheckStr(byVal ChkStr)
'参数:ChkStr,待验证的字符
'作者:阿里西西
'日期:2007/7/15
'描述:对SQL注入危险字符进行重编码处理
'示例:CheckStr("and 1=1 or select * from")
'******************************
Function CheckStr(byVal ChkStr)
Dim Str:Str=ChkStr
Str=Trim(Str)
If IsNull(Str) Then
CheckStr = ""
Exit Function
End If
Dim re
Set re=new RegExp
re.IgnoreCase =True
re.Global=True
re.Pattern="(\r\n){3,}"
Str=re.Replace(Str,"$1$1$1")
Set re=Nothing
Str = Replace(Str,"'","''")
Str = Replace(Str, "select", "sel#101;ct")
Str = Replace(Str, "join", "jo#105;n")
Str = Replace(Str, "union", "un#105;on")
Str = Replace(Str, "where", "wh#101;re")
Str = Replace(Str, "insert", "ins#101;rt")
Str = Replace(Str, "delete", "del#101;te")
Str = Replace(Str, "update", "up#100;ate")
Str = Replace(Str, "like", "lik#101;")
Str = Replace(Str, "drop", "dro#112;")
Str = Replace(Str, "create", "cr#101;ate")
Str = Replace(Str, "modify", "mod#105;fy")
Str = Replace(Str, "rename", "ren#097;me")
Str = Replace(Str, "alter", "alt#101;r")
Str = Replace(Str, "cast", "ca#115;t")
CheckStr=Str
End Function
'反编上面函数处理过的字符串
Function UnCheckStr(Str)
Str = Replace(Str, "sel#101;ct", "select")
Str = Replace(Str, "jo#105;n", "join")
Str = Replace(Str, "un#105;on", "union")
Str = Replace(Str, "wh#101;re", "where")
Str = Replace(Str, "ins#101;rt", "insert")
Str = Replace(Str, "del#101;te", "delete")
Str = Replace(Str, "up#100;ate", "update")
Str = Replace(Str, "lik#101;", "like")
Str = Replace(Str, "dro#112;", "drop")
Str = Replace(Str, "cr#101;ate", "create")
Str = Replace(Str, "mod#105;fy", "modify")
Str = Replace(Str, "ren#097;me", "rename")
Str = Replace(Str, "alt#101;r", "alter")
Str = Replace(Str, "ca#115;t", "cast")
UnCheckStr=Str
End Function
%>