加入收藏 | 设为首页 | 会员中心 | 我要投稿 汽车网 (https://www.0577qiche.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

只需两个小函数让你的ASP程序对SQL注入免疫

发布时间:2023-05-26 17:20:19 所属栏目:Asp教程 来源:
导读:两个小函数让你的ASP程序对SQL注入免疫!

Rem ## 长整数转换
Function toNum(s, default)
If IsNumeric(s) and s <> "" then
toNum = CLng(s)
Else
toNum = default
End If
End Function

Rem #
两个小函数让你的ASP程序对SQL注入免疫!

Rem ## 长整数转换 
Function toNum(s, default) 
If IsNumeric(s) and s <> "" then 
toNum = CLng(s) 
Else 
toNum = default 
End If 
End Function 

Rem ## SQL 语句转换 
Function toSql(str) 
If IsNull(str) Then str = "" 
toSql = replace(str, "''", "''''") 
End Function 

示例: 
Dim sql 
Dim strWhere, 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函数改为如下: 
Function toSql(str) 
If IsNull(str) Then str = "" 
str = replace(str, chr(0), "") 
toSql = replace(str, "''", "''''") 
End Function 

另注: 

检测外部提交的函数 
Function CheckUrlRefer() 
Dim strLocalUrl, intUrlLen, strUrlRefer 
strLocalUrl = "http://127.0.0.1" 
intUrlLen = Len(strLocalUrl) 
strUrlRefer = LCase(request.ServerVariables("HTTP_REFERER") & "") 
''检测前一个页面是否来自 strLocalUrl 
If Left(strUrlRefer, intUrlLen) = strLocalUrl Then 
CheckUrlRefer = True 
Else 
CheckUrlRefer = False 
End If 
End Function 

该函数可以帮助你抵挡外部的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 

dim qs,errc,iii 
qs=request.servervariables("query_string") 
dim nothis(18) 
nothis(0)="net user" 

(编辑:汽车网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章