【asp源码栏目提醒】:网学会员--在 asp源码编辑为广大网友搜集整理了:防范SQL注入攻击的ASP代码 - 开发文档绩等信息,祝愿广大网友取得需要的信息,参考学习。
防范SQL注入攻击的
ASP代码 SQL注入式攻击是利用是指利用设计上的漏洞在目标服务器上运行Sql命令以及进行其他方式的攻击动态生成Sql命令时没有对用户输入的数据进行验证是Sql注入攻击得逞的主要原因。
比如 如果你的查询语句是select from admin where usernameuser and passwordpwd 那么如果我的用户名是1 or 11 那么你的查询语句将会变成 select from admin where username1 or 11 and passwordpwd 这样你的查询语句就通过了从而就可以进入你的管理界面。
所以防范的时候需要对用户的输入进行检查。
特别式一些特殊字符比如单引号双引号分号逗号冒号连接号等进行转换或者过滤。
需要过滤的特殊字符及字符串有 net user xp_cmdshell /add exec master.dbo.xp_cmdshell net localgroup administrators select count Asc char mid : insert delete from drop table update truncate from 下面是我写的两种关于解决注入式攻击的防范代码供大家学习参考 js版的防范SQL注入式攻击代码 CODE START CODE END
asp版的防范SQL注入式攻击代码 CODE START On Error Resume Next Dim strTemp If LCaseRequest.ServerVariablesHTTPS off Then strTemp http:// Else strTemp https:// End If strTemp strTemp Request.ServerVariablesSERVER_NAME If Request.ServerVariablesSERVER_PORT 80 Then strTemp strTemp : Request.ServerVariablesSERVER_PORT strTemp strTemp Request.ServerVariablesURL If TrimRequest.QueryString Then strTemp strTemp TrimRequest.QueryString strTemp LCasestrTemp If InstrstrTempselect20 or InstrstrTempinsert20 or InstrstrTempdelete20from or InstrstrTempcount or InstrstrTempdrop20table or InstrstrTempupdate20 or InstrstrTemptruncate20 or InstrstrTempasc or InstrstrTempmid or InstrstrTempchar or InstrstrTempxp_cmdshell or InstrstrTempexec20master or InstrstrTempnet20localgroup20administrators or InstrstrTemp: or InstrstrTempnet20user or InstrstrTemp or InstrstrTemp20or20 then Response.Write script languagejavascript Response.Write alert非法地址 Response.Write location.hreferror.
asp Response.Write script End If CODE END C 检查字符串防SQL注入攻击 这个例子里暂定为号和号 bool CheckParamsparams object args string Lawlesses ifLawlessesnullLawlesses.Length0 return false else ifarg is ICollection //如果是一个集合则检查集合内元素是否字符串是字符串就进行检查 foreachobject obj in ICollectionarg ifobj is string ifRegex.Matchesobj.ToStringstr_Regex.Count0 return false return true
上一篇:
ASPNET009
下一篇:
“2018中国人保购车节暨第三届宁波汽车展销会”,老司机教您,现场如何快速抢购爱车!