ASP網站的(de)動态參數傳遞一直是個(gè)不小的(de)安全問題,如不進行安全過濾經常會被黑(hēi)客利用(yòng),一般的(de)注入便是由于網站設計時(shí)沒有注意好傳遞過來(lái)的(de)參數進行過濾,比如http://www.52banmian.com/news.asp?id=5直接用(yòng)request("id")來(lái)獲取ID=5,黑(hēi)客則可(kě)輕易利用(yòng)此入侵。
方法一:
<%'過濾安全字符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 & "必須爲數字型!<br /><br />" Response.end End if Else ParaValue=replace(ParaValue,"'","''") ParaValue = Replace(ParaValue, "select", "select") ParaValue = Replace(ParaValue, "join", "join") ParaValue = Replace(ParaValue, "union", "union") ParaValue = Replace(ParaValue, "where", "where") ParaValue = Replace(ParaValue, "insert", "insert") ParaValue = Replace(ParaValue, "delete", "delete") ParaValue = Replace(ParaValue, "update", "update") ParaValue = Replace(ParaValue, "like", "like") ParaValue = Replace(ParaValue, "drop", "drop") ParaValue = Replace(ParaValue, "create", "create") ParaValue = Replace(ParaValue, "modify", "modify") ParaValue = Replace(ParaValue, "rename", "rename") ParaValue = Replace(ParaValue, "alter", "alter") ParaValue = Replace(ParaValue, "cast", "cast") ParaValue = Replace(ParaValue, "and", "and") ParaValue = Replace(ParaValue, "or", "or")End if SafeRequest=ParaValue End function%>
用(yòng)法:當傳遞過來(lái)的(de)參數ID爲數字時(shí),用(yòng)safeRequest("id",1)接收;當傳遞的(de)ID爲字符時(shí),用(yòng)safeRequest("id",0)接收,這(zhè)樣便可(kě)防禦一般黑(hēi)客的(de)參數注入。
方法二:
簡單過濾黑(hēi)客需要用(yòng)到的(de)常用(yòng)注入符号:<%id=replace(request("id"), " ' ", " ' ' ")%>