选择显示字体大小

在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应用程序里这类问题的发生。


 


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons