上一篇:小日历 - asp实例 >>
在ASP中过滤用户输入 提高安全性
允许用户输入非法的字符会增加用户导致问题的机会。例如,很多应用程序都能够接受用户在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应用程序里这类问题的发生。
下一篇:一段取得翻唱排行榜上歌曲名称,艺人,地址的脚本程序 >>
相关文章:
- · 在页面中控制媒体流的起播点和播放长度
- · .NET中实现无客户端联动菜单 (无刷新)
- · 模似windows XP 左侧的菜单效果
- · 表同步更新的问题的触发器
- · 浅谈自动采集程序及入库
- · 小处见大问题
- · ASP.NET 2.0: 在使用web.sitemap时,如何实现本地化
- · ASP模仿asp.net的DataGrid
- · 简单的表单验证类 ASP Validator
- · 遍历XML文档返回二维数组(ASP)(更新版)
- · ASP 函数语法速查表
- · 遍历XML文档的所有节点及属性(ASP)
- · Relaxlife.net最强计数器-利用操作INI文件来控制流量,也可用做系统设置
- · WEB文件管理器2.0版
- · RegularExpressionValidator正则表达式验证电子邮件
- · 关于教师评价系统的WEB程序(三)
- · 关于教师评价系统的WEB程序(二)
- · RSS应用现状以及我的一些想法
- · 二级下拉列表的实现
- · 《ASP入门-微软版》笔记
- · 《ASP网页制作教程》笔记
- · jscript错误代码及相应解释
- · ASP中数据库安全问题之我见!
- · 漫话验证码缘起,程序原理及其他
- · asp写的日志处理方法
- · 时间、空间性能极优的asp无组件上传类
- · html marquee 标记
- · C#对XML操作:一个处理XML文件的类(2)
- · 针对select写了一个通用的option输出函数
- · 使用存储过程从web页面传递参数
- · URL编码与SQL注射
- · 蛙蛙推荐:蛙蛙牌无组件上传类
- · WEB打印,个人认为最好的。
- · 文件、目录,文本文件等多种操作类
- · 有关页面登陆的一些设计
- · Access错误提示之Selected collating sequence not supported by the operating system.
- · javascript检测。在回送
- · ASP 编程中20个非常有用的例子
