安全对于所有应用程序来说都是十分重要的。一个简单应用程序里的某个失误都会造成对数据库或者其他企业资源未经授权的访问,因此安全尤其重要。一种常用的攻击方法是将命令嵌入到用户的回应里,而从用户输入里过滤掉这些非法的字符就能够防止这种攻击。 下面这段代码是设计用来处理从服务器返回的多个Recordset的。用户的输入会包含一个额外的、未预料的的执行命令。当NextRecordset方法被调用的时候,潜藏的恶意代码就会被执行。 这一攻击可以通过过滤掉用户输入信息中的非法字符(在注释段里)来避免。这样做了之后,用户的输入仍然被允许处理,但是清除掉了所有的非法字符。 Dim rst As Recordset strUserInput = “Smith;EXEC master..xp_cmdshell dir *.exe” Filter input for invalid characters Set rst = New Recordset Set rst2 = rst.NextRecordset() 在用户的输入中嵌入命令也是攻击ASP Web应用程序的一种常见手法,也叫做跨网站脚本攻击。过滤输入的内容并使用Server.HTMLEncode和Server.URLEncode这两个方法会有助于防止你ASP应用程序里这类问题的发生。
允许用户输入非法的字符会增加用户导致问题的机会。例如,很多应用程序都能够接受用户在SQL命令里增加的WHERE子句。恶意用户会通过向其输入的信息里增加额外命令的方法,来执行数据库服务器上的代码。例如,他们不是输入“Smith”,将其作为检索字符串,而是输入“Smith; EXEC master..xp_cmdshell dir *.exe”。
Dim rst2 As Recordset
Dim strUserInput As String
strUserInput = Replace(strUserInput, “<“, vbNullString)
strUserInput = Replace(strUserInput, “>”, vbNullString)
strUserInput = Replace(strUserInput, “”””, vbNullString)
strUserInput = Replace(strUserInput, “”, vbNullString)
strUserInput = Replace(strUserInput, “%”, vbNullString)
strUserInput = Replace(strUserInput, “;”, vbNullString)
strUserInput = Replace(strUserInput, “(“, vbNullString)
strUserInput = Replace(strUserInput, “)”, vbNullString)
strUserInput = Replace(strUserInput, “&”, vbNullString)
strUserInput = Replace(strUserInput, “+”, vbNullString)
strUserInput = Replace(strUserInput, “-“, vbNullString)
rst.ActiveConnection = “PROVIDER=SQLOLEDB;DATA SOURCE=SQLServer;” & _
“Initial Catalog=pubs;Integrated Security=SSPI”
rst.Open “Select * from authors where au_lname = ” & strUserInput & _
“”, , adOpenStatic
Do something with recordset 1
Do something with recordset 2
在asp中过滤用户输入 提高安全性_asp技巧
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 在asp中过滤用户输入 提高安全性_asp技巧
相关推荐
-      ASP基础教程:其它的ASP常用组件
-      ASP基础教程:学习ASP中子程序的应用
-      ASP基础教程之ASP程序对Cookie的处理
-      ASP基础教程之ASP AdRotator组件的使用
-      ADO初学者教程:ADO 通过GetString()加速脚本
-      ASP技巧实例:几行代码解决防止表单重复提交
-      ASP常见数学函数 Abs Atn Cos 等详细详解[ 来源:网页教学网 | 作者: | 时间:2007-09-12 10:57:29 | 收藏本文 ] 【大 中 小】【名称】
-      ASP基础教程之ASP AdRotator 组件的使用
