不错呦!smile@林凯西,确保“准备文件”中的几个文件都有安装,S...您好,看了您这篇帖子觉得很有帮助。但是有个问题想请...我的修改过了怎么还被恶意注册呢 @jjjjiiii 用PJ快9年了,主要是A...PJ3啊,貌似很少有人用PJ了,现在不是WP就是z...@332347365,我当时接入时错误码没有-10...楼主,ChkValue值应为-103是什么意思呢?...大哥 你最近能看到我发的信息,请跟我联系,我有个制...
防SQL注入不能滥杀无辜
编辑:dnawo 日期:2008-03-22
我们先来看看新云网站管理系统 v3.1.0.1231的防SQL注入函数:
使用这段函数只要参数中包含"insert|select|delete|update"等字符就被认为是在注入,那么偏偏有时候我要搜索的就是"update"呢?对不起,不行!显然这已造成了使用上的不便。
再来看看FoosunCMS V4.0 Sp5 For ASP的防SQL注入函数:
和新云一样也是存在过滤过严的问题!
下边我们再看看PowerEasy® SiteWeaver™ CMS 6.5 Build 0128的防SQL注入函数:
看来动易程序员已经考虑到了滥杀的可能性,所以只有当"select|update|insert|delete"等字符前含有空格可才会被认为是在注入!不过个人认为注入时空格恐怕都应该在这些字符之后更多些吧?regEx.Pattern的值改为:
是不是更恰当些呢?^_^
SQL注入漏洞是Web应用程序致命的几大漏洞之一,是应当做好防范,但也不可"宁可错杀一千 而不放走一个"而滥杀无辜,最终造成使用上的不便!
复制内容到剪贴板
程序代码

Public Function CheckInfuse(ByVal str, ByVal strLen)
Dim strUnsafe, arrUnsafe
Dim i
If Trim(str) = "" Then
CheckInfuse = ""
Exit Function
End If
str = Left(str, strLen)
On Error Resume Next
strUnsafe = "'|^|;|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare"
If Trim(str) <> "" Then
If Len(str) > strLen Then
Response.Write "<Script Language=JavaScript>alert('安全系统提示↓\n\n您提交的字符数超过了限制!');history.back(-1)</Script>"
CheckInfuse = ""
Response.End
End If
arrUnsafe = Split(strUnsafe, "|")
For i = 0 To UBound(arrUnsafe)
If InStr(1, str, arrUnsafe(i), 1) > 0 Then
Response.Write "<Script Language=JavaScript>alert('安全系统提示↓\n\n请不要在参数中包含非法字符!');history.back(-1)</Script>"
CheckInfuse = ""
Response.End
End If
Next
End If
CheckInfuse = Trim(str)
Exit Function
If Err.Number <> 0 Then
Err.Clear
Response.Write "<Script Language=JavaScript>alert('安全系统提示↓\n\n请不要在参数中包含非法字符!');history.back(-1)</Script>"
CheckInfuse = ""
Response.End
End If
End Function
Dim strUnsafe, arrUnsafe
Dim i
If Trim(str) = "" Then
CheckInfuse = ""
Exit Function
End If
str = Left(str, strLen)
On Error Resume Next
strUnsafe = "'|^|;|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare"
If Trim(str) <> "" Then
If Len(str) > strLen Then
Response.Write "<Script Language=JavaScript>alert('安全系统提示↓\n\n您提交的字符数超过了限制!');history.back(-1)</Script>"
CheckInfuse = ""
Response.End
End If
arrUnsafe = Split(strUnsafe, "|")
For i = 0 To UBound(arrUnsafe)
If InStr(1, str, arrUnsafe(i), 1) > 0 Then
Response.Write "<Script Language=JavaScript>alert('安全系统提示↓\n\n请不要在参数中包含非法字符!');history.back(-1)</Script>"
CheckInfuse = ""
Response.End
End If
Next
End If
CheckInfuse = Trim(str)
Exit Function
If Err.Number <> 0 Then
Err.Clear
Response.Write "<Script Language=JavaScript>alert('安全系统提示↓\n\n请不要在参数中包含非法字符!');history.back(-1)</Script>"
CheckInfuse = ""
Response.End
End If
End Function
使用这段函数只要参数中包含"insert|select|delete|update"等字符就被认为是在注入,那么偏偏有时候我要搜索的就是"update"呢?对不起,不行!显然这已造成了使用上的不便。
再来看看FoosunCMS V4.0 Sp5 For ASP的防SQL注入函数:
复制内容到剪贴板
程序代码

Function NoSqlHack(FS_inputStr)
Dim f_NoSqlHack_AllStr,f_NoSqlHack_Str,f_NoSqlHack_i,Str_InputStr
Str_InputStr=FS_inputStr
'目前用最严的过滤方式
f_NoSqlHack_AllStr="dbcc|alter|drop|* |and|exec|or|insert|select|delete|update|count|master|truncate|declare|char|mid(|chr|set |where|xp_cmdshell"
f_NoSqlHack_Str = Split(f_NoSqlHack_AllStr,"|")
For f_NoSqlHack_i=LBound(f_NoSqlHack_Str) To Ubound(f_NoSqlHack_Str)
If Instr(LCase(Str_InputStr),f_NoSqlHack_Str(f_NoSqlHack_i))<>0 Then
If f_NoSqlHack_Str(f_NoSqlHack_i)="'" Then f_NoSqlHack_Str(f_NoSqlHack_i)=" \' "
Response.Write "<html><title>警告</title><body bgcolor=""EEEEEE"" leftmargin=""60"" topmargin=""30""><font style=""font-size:16px;font-weight:bolder;color:blue;""><li>您提交的数据有恶意字符</li></font><font style=""font-size:14px;font-weight:bolder;color:red;""><br><li>您的数据已经被记录!</li><br><li>您的IP:"&Request.ServerVariables("Remote_Addr")&"</li><br><li>操作日期:"&Now&"</li></font></body></html><!--Powered by Foosun Inc.,AddTime:"&now&"-->"
Response.End
End if
Next
NoSqlHack = Replace(Replace(Str_InputStr,"'","''"),"%27","''")
End Function
Dim f_NoSqlHack_AllStr,f_NoSqlHack_Str,f_NoSqlHack_i,Str_InputStr
Str_InputStr=FS_inputStr
'目前用最严的过滤方式
f_NoSqlHack_AllStr="dbcc|alter|drop|* |and|exec|or|insert|select|delete|update|count|master|truncate|declare|char|mid(|chr|set |where|xp_cmdshell"
f_NoSqlHack_Str = Split(f_NoSqlHack_AllStr,"|")
For f_NoSqlHack_i=LBound(f_NoSqlHack_Str) To Ubound(f_NoSqlHack_Str)
If Instr(LCase(Str_InputStr),f_NoSqlHack_Str(f_NoSqlHack_i))<>0 Then
If f_NoSqlHack_Str(f_NoSqlHack_i)="'" Then f_NoSqlHack_Str(f_NoSqlHack_i)=" \' "
Response.Write "<html><title>警告</title><body bgcolor=""EEEEEE"" leftmargin=""60"" topmargin=""30""><font style=""font-size:16px;font-weight:bolder;color:blue;""><li>您提交的数据有恶意字符</li></font><font style=""font-size:14px;font-weight:bolder;color:red;""><br><li>您的数据已经被记录!</li><br><li>您的IP:"&Request.ServerVariables("Remote_Addr")&"</li><br><li>操作日期:"&Now&"</li></font></body></html><!--Powered by Foosun Inc.,AddTime:"&now&"-->"
Response.End
End if
Next
NoSqlHack = Replace(Replace(Str_InputStr,"'","''"),"%27","''")
End Function
和新云一样也是存在过滤过严的问题!
下边我们再看看PowerEasy® SiteWeaver™ CMS 6.5 Build 0128的防SQL注入函数:
复制内容到剪贴板
程序代码

Sub StopInjection(Values)
Dim FoundInjection
regEx.Pattern = "'|;|#|([\s\b+()]+(select|update|insert|delete|declare|@|exec|dbcc|alter|drop|create|backup|if|else|end|and|or|add|set|open|close|use|begin|retun|as|go|exists)[\s\b+]*)"
Dim sItem, sValue
For Each sItem In Values
sValue = Values(sItem)
If regEx.Test(sValue) Then
FoundInjection = True
Response.Write "很抱歉,由于您提交的内容中含有危险的SQL注入代码,致使本次操作无效! "
Response.Write "<br>字段名:" & sItem
Response.Write "<br>字段值:" & sValue
Response.Write "<br>关键字:"
Set Matches = regEx.Execute(sValue)
For Each Match In Matches
Response.Write Match.value & " "
Next
Response.Write "<br><br>如果您是正常提交仍出现上面的提示,请联系站长修改Config.asp文件的第7行,暂时禁用掉防SQL注入功能,操作完成后再打开。"
End If
Next
If FoundInjection = True Then
Response.End
End If
End Sub
Dim FoundInjection
regEx.Pattern = "'|;|#|([\s\b+()]+(select|update|insert|delete|declare|@|exec|dbcc|alter|drop|create|backup|if|else|end|and|or|add|set|open|close|use|begin|retun|as|go|exists)[\s\b+]*)"
Dim sItem, sValue
For Each sItem In Values
sValue = Values(sItem)
If regEx.Test(sValue) Then
FoundInjection = True
Response.Write "很抱歉,由于您提交的内容中含有危险的SQL注入代码,致使本次操作无效! "
Response.Write "<br>字段名:" & sItem
Response.Write "<br>字段值:" & sValue
Response.Write "<br>关键字:"
Set Matches = regEx.Execute(sValue)
For Each Match In Matches
Response.Write Match.value & " "
Next
Response.Write "<br><br>如果您是正常提交仍出现上面的提示,请联系站长修改Config.asp文件的第7行,暂时禁用掉防SQL注入功能,操作完成后再打开。"
End If
Next
If FoundInjection = True Then
Response.End
End If
End Sub
看来动易程序员已经考虑到了滥杀的可能性,所以只有当"select|update|insert|delete"等字符前含有空格可才会被认为是在注入!不过个人认为注入时空格恐怕都应该在这些字符之后更多些吧?regEx.Pattern的值改为:
复制内容到剪贴板
程序代码

regEx.Pattern = "'|;|#|([\s\b+()]*select|update|insert|delete|declare|@|exec|dbcc|alter|drop|create|backup|if|else|end|and|or|add|set|open|close|use|begin|retun|as|go|exists)[\s\b+]+)"
是不是更恰当些呢?^_^
SQL注入漏洞是Web应用程序致命的几大漏洞之一,是应当做好防范,但也不可"宁可错杀一千 而不放走一个"而滥杀无辜,最终造成使用上的不便!
评论: 0 | 引用: 0 | 查看次数: 4857
发表评论
请登录后再发表评论!