我的一亩三分地 我就喜欢!
13fen  设为主页
 收藏本站
 
当前位置: > 一亩三分地:首页 > 网络学院 > 网络编程 > ASP专区 > Asp基础/应用 > 在ASP中过滤用户输入 提高安全性
热门文章排行
热门文章排行 手推车”功能的实现(10-07)
八大法则防范ASP网站漏洞(10-23)
ASP教程十一、调试ASP脚本(10-23)
在JSP中访问数据库大全(10-23)
虚机服务中常见Asp.Net低级错误一览(03-21)
精采文章排行
精采文章排行 ASP.NET实现抓取网页中的链接(11-15)
ASP连接数据库的11种方法(11-10)
如何动态创建网页的RSS内容摘要(11-10)
ASP网站漏洞及入侵防范方法(11-10)
ASP自定义函数:对字符串正则替换(11-10)
技术专题推荐
网管论坛交流
 

在ASP中过滤用户输入 提高安全性 

作者:佚名   来源:本站教程   点击:   日期:2007-03-22

安全对于所有应用程序来说都是十分重要的。一个简单应用程序里的某个失误都会造成对数据库或者其他企业资源未经授权的访问,因此安全尤其重要。一种常用的攻击方法是将命令嵌入到用户的回应里,而从用户输入里过滤掉这些非法的字符就能够防止这种攻击。


允许用户输入非法的字符会增加用户导致问题的机会。例如,很多应用程序都能够接受用户在SQL命令里增加的WHERE子句。恶意用户会通过向其输入的信息里增加额外命令的方法,来执行数据库服务器上的代码。例如,他们不是输入“Smith”,将其作为检索字符串,而是输入“Smith'; EXEC master..xp_cmdshell 'dir *.exe”。

下面这段代码是设计用来处理从服务器返回的多个Recordset的。用户的输入会包含一个额外的、未预料的的执行命令。当NextRecordset方法被调用的时候,潜藏的恶意代码就会被执行。

这一攻击可以通过过滤掉用户输入信息中的非法字符(在注释段里)来避免。这样做了之后,用户的输入仍然被允许处理,但是清除掉了所有的非法字符。

Dim rst As Recordset
Dim rst2 As Recordset
Dim strUserInput As String

strUserInput = "Smith';EXEC master..xp_cmdshell 'dir *.exe"

'Filter input for invalid characters
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)

Set rst = New Recordset
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

Set rst2 = rst.NextRecordset()
'Do something with recordset 2

在用户的输入中嵌入命令也是攻击ASP Web应用程序的一种常见手法,也叫做跨网站脚本攻击。过滤输入的内容并使用Server.HTMLEncode和Server.URLEncode这两个方法会有助于防止你ASP应用程序里这类问题的发生。

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【论坛讨论

   相关文章:
·ASP中巧用Response属性 ·第六课:ASP脚本循环语句
·在 Web 页上使用条件数值格式 ·连接数据库查询手册(不仅仅适用于asp)
·警惕"给你的FileSystemObject对象加把锁" ·用ASP做全文检索

   文章评论:(条)
  
 请留名: 匿名评论   点击查看所有评论 网管论坛
 

  责任编辑:一分  声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。