>第二种情况也存在第一种情况中的问题;已知的错误输入随着攻击技术的发展变化。 第三种情况可能是三种中最好的,但是很难实现。 从安全角度看合并第二种方法和第三种方法可能是最好的方法——只允许正确的输入,然后搜索输入中已知的错误数据。 带有连接符号的姓名的问题对于体现合并两种方法的必要性是一个好的例子: Quentin Bassington-Bassington 我们必须在正确输入中允许连接符号,但是我们也意识到字符序列’—’对SQL SERVER很重要。 当合并修改数据和字符序列确认时,会出现另一个问题。例如,如果我们应用一个错误过滤在除去单引号之后去探测’—’,’select’和’union’,攻击者可以输入: uni’on sel’ect @@version-’- 既然单引号被除去,攻击者可以简单地散布单引号在自己的错误的字符串中躲避被发现。 这有一些确认代码的例子: 方法一——过滤单引号 function escape(input) input=replace(input,"’","’’") escape=input end function
方法二——拒绝已知的错误输入 function validate_string(input) known_bad=array("select","insert","update","delete","drop","—","’") validate_string=true for i=lbound(known_bad) to ubound(known_bad) if(instr(1,input,known_bad(i),vbtextcompare)<>0) then validate_string=false exit function end if next end function
方法三——只允许正确的输入 function validatepassword(input) good_password_chars=” abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789” validatepassword=true for i=1 to len(input) c=mid(input,I,1) if(InStr(good_password_chars,c)=0) then validatepassword=false exit function end if next end function
[参考文献] [1] Web Application Disassembly with ODBC Error Messages, David Litchfield http://www.nextgenss.com/papers/webappdis.doc [2] SQL Server Security Checklist http://www.sqlsecurity.com/checklist.asp [3] SQL Server 2000 Extended Stored Procedure Vulnerability http://www.atstake.com/research/adv...0/a120100-2.txt [4] Microsoft SQL Server Extended Stored Procedure Vulnerability http://www.atstake.com/research/adv...0/a120100-1.txt [5] Multiple Buffer Format String Vulnerabilities In SQL Server http://www.microsoft.com/technet/se...in/MS01-060.asphttp://www.atstake.com/research/adv...1/a122001-1.txt