Rem##長整數轉換
FunctiontoNum(s,default)
IfIsNumeric(s)ands<>""then
toNum=CLng(s)
Else
toNum=default
EndIf
EndFunction
Rem##SQL語句轉換
FunctiontoSql(str)
IfIsNull(str)Thenstr=""
toSql=replace(str,"''","''''")
EndFunction
示例:
Dimsql
DimstrWhere,strName,intAge
strName=toSql(request("user"))
intAge=toNum(request("age"),20)
sql="SELECT*FROM[USER]"&_
"WHERE[AGE]>"&strName&_
"AND[USERNAME]=''"&intAge&"''"
一般情況下,通過上面兩個函數的過慮,可以杜絕網上的SQL注入攻擊!如果你覺得有需要,可以加上對chr(0)的替換,將toSql函數改為如下:
FunctiontoSql(str)
IfIsNull(str)Thenstr=""
str=replace(str,chr(0),"")
toSql=replace(str,"''","''''")
EndFunction
另註:
***********************************************************************
檢測外部提交的函數
FunctionCheckUrlRefer()
DimstrLocalUrl,intUrlLen,strUrlRefer
strLocalUrl="http://127.0.0.1"
intUrlLen=Len(strLocalUrl)
strUrlRefer=LCase(request.ServerVariables("HTTP_REFERER")&"")
''檢測前一個頁面是否來自strLocalUrl
IfLeft(strUrlRefer,intUrlLen)=strLocalUrlThen
CheckUrlRefer=True
Else
CheckUrlRefer=False
EndIf
EndFunction
***********************************************************************
該函數可以幫助你抵擋外部的SQL注入測試,只需要在頁面的頭部調用即可.
通過簡單的兩個小函數,讓你的ASP程序更安全!
歡迎高手指正(請將繞過這兩個函數的方法寫出來)!
相關討論頁面:
http://community.csdn.net/Expert/TopicView.asp?id=3585010
http://community.csdn.net/Expert/TopicView.asp?id=3582230
http://community.csdn.net/Expert/topic/3589/3589480.xml?temp=.4866449
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
dimqs,errc,iii
qs=request.servervariables("query_string")
dimnothis(18)
nothis(0)="netuser"