17年专业上海网页设计公司—上海彭塔网络技术有限公司

手机端 网站地图
当前位置:首页 > 建站常识 > 列表

ASP动态参数传递怎么进行安全过滤?

点击:时间:2017/3/20关键词:asp参数 上海网页设计公司
ASP网站的动态参数传递一直是个不小的安全问题,如不进行安全过滤经常会被黑客利用,一般的注入便是由于网站设计时没有注意好传递过来的参数进行过滤,比如http://www.52banmian.com/news.asp?id=5直接用request("id")来

ASP动态参数传递怎么进行安全过滤?

ASP网站的动态参数传递一直是个不小的安全问题,如不进行安全过滤经常会被黑客利用,一般的注入便是由于网站设计时没有注意好传递过来的参数进行过滤,比如http://www.52banmian.com/news.asp?id=5直接用request("id")来获取ID=5,黑客则可轻易利用此入侵。

方法一:

<%'过滤安全字符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", "sel&#101;ct") ParaValue = Replace(ParaValue, "join", "jo&#105;n") ParaValue = Replace(ParaValue, "union", "un&#105;on") ParaValue = Replace(ParaValue, "where", "wh&#101;re") ParaValue = Replace(ParaValue, "insert", "ins&#101;rt") ParaValue = Replace(ParaValue, "delete", "del&#101;te") ParaValue = Replace(ParaValue, "update", "up&#100;ate") ParaValue = Replace(ParaValue, "like", "lik&#101;") ParaValue = Replace(ParaValue, "drop", "dro&#112;") ParaValue = Replace(ParaValue, "create", "cr&#101;ate") ParaValue = Replace(ParaValue, "modify", "mod&#105;fy") ParaValue = Replace(ParaValue, "rename", "ren&#097;me") ParaValue = Replace(ParaValue, "alter", "alt&#101;r") ParaValue = Replace(ParaValue, "cast", "ca&#115;t") ParaValue = Replace(ParaValue, "and", "an&#100;") ParaValue = Replace(ParaValue, "or", "o&#114;")End if SafeRequest=ParaValue End function%>

用法:当传递过来的参数ID为数字时,用safeRequest("id",1)接收;当传递的ID为字符时,用safeRequest("id",0)接收,这样便可防御一般黑客的参数注入。

方法二:

简单过滤黑客需要用到的常用注入符号:<%id=replace(request("id"), " ' ", " ' ' ")%>
预约建站
免费提供网站优化
领取关键词