因为在改进公司的一套ASP代码,所以考虑了一下防注入的问题。

参考了网上的几处代码,进行了修改和整合,都转换成小写再处理。

还考虑了script注入。

代码如下:

'Asp防注入代码
SQL_injdata =lcase(":|;|>|<|--|sp_|xp_|\|dir|cmd|^|(|)|+|$|'")
SQL_injdata =SQL_injdata&lcase("|copy|format|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare|script")
SQL_inj = split(SQL_Injdata,"|") if Request.QueryString<>"" then
For Each SQL_Get In Request.QueryString
For SQL_Data= To Ubound(SQL_inj)
if not IsNumeric(Request.QueryString(SQL_Get)) then
if instr(lcase(Request.QueryString(SQL_Get)),Sql_Inj(Sql_DATA))> Then
Response.Write "对不起,非法URL地址请求!"
Response.end
end if
end if
next
next
end if if Request.Form<>"" then
For Each Sql_Post In Request.Form
For SQL_Data= To Ubound(SQL_inj)
if instr(lcase(Request.Form(Sql_Post)),Sql_Inj(Sql_DATA))> Then
Response.Write "对不起,非法数据提交!"
Response.end
end if
next
next
end if if Request.Cookies<>"" then
For Each Sql_Post In Request.Cookies
For SQL_Data= To Ubound(SQL_inj)
if instr(lcase(Request.Cookies(Sql_Post)),Sql_Inj(Sql_DATA))> Then
Response.Write "对不起,非法URL地址请求!"
Response.end
end if
next
next
end if 'post过滤sql注入代防范及HTML防护开始
function nosql(str)
if not isnull(str) then
str=trim(str)
str=replace(str,";",";") '分号
str=replace(str,"'","'") '单引号
str=replace(str,"""","&quot;") '双引号
str=replace(str,"chr(9)","&nbsp;") '空格
str=replace(str,"chr(10)","<br>") '回车
str=replace(str,"chr(13)","<br>") '回车
str=replace(str,"chr(32)","&nbsp;") '空格
str=replace(str,"chr(34)","&quot;") '双引号
str=replace(str,"chr(39)","'") '单引号
str=Replace(str, "script", "&#115cript")'jscript
str=replace(str,"<","&lt;") '左<
str=replace(str,">","&gt;") '右>
str=replace(str,"(","(") '左(
str=replace(str,")",")") '右)
str=replace(str,"--","--") 'SQL注释符 str=replace(str,"net user","")
str=replace(str,"xp_cmdshell","")
str=replace(str,"/add","")
str=replace(str,"exec%20master.dbo.xp_cmdshell","")
str=replace(str,"net localgroup administrators","")
str=replace(str,"select","")
str=replace(str,"count","")
str=replace(str,"asc","")
str=replace(str,"char","")
str=replace(str,"mid","")
str=replace(str,":","")
str=replace(str,"insert","")
str=replace(str,"delete","")
str=replace(str,"drop","")
str=replace(str,"truncate","")
str=replace(str,"from","")
str=replace(str,"%","")
nosql=str
end if
end function

参考:

http://itlobo.com/articles/1123.html

http://www.aisenan.com/hack/aspfzrdm_fcookiezrdm_13.html

http://www.mkshy.com/networkTechnology/preventInjection.shtml

ASP防注入的更多相关文章

  1. asp防注入安全问题

    一.古老的绕验证漏洞虽然古老,依然存在于很多小程序之中,比如一些企业网站的后台,简单谈谈.这个漏洞出现在没有对接受的变量进行过滤,带入数据库判断查询时,造成SQL语句的逻辑问题.例如以下代码存在问题: ...

  2. SQL防注入程序 v1.0

    /// ***************C#版SQL防注入程序 v1.0************ /// *使用方法: /// 一.整站防注入(推荐) /// 在Global.asax.cs中查找App ...

  3. sql 防注入 维基百科

    http://zh.wikipedia.org/wiki/SQL%E8%B3%87%E6%96%99%E9%9A%B1%E7%A2%BC%E6%94%BB%E6%93%8A SQL攻击(SQL inj ...

  4. 简单实用的PHP防注入类实例

    这篇文章主要介绍了简单实用的PHP防注入类实例,以两个简单的防注入类为例介绍了PHP防注入的原理与技巧,对网站安全建设来说非常具有实用价值,需要的朋友可以参考下   本文实例讲述了简单实用的PHP防注 ...

  5. [转]PDO防注入原理分析以及使用PDO的注意事项

    原文:http://zhangxugg-163-com.iteye.com/blog/1835721 好文章不得不转. 我们都知道,只要合理正确使用PDO,可以基本上防止SQL注入的产生,本文主要回答 ...

  6. SQL防注入程序

    1.在Global.asax.cs中写入: protected void Application_BeginRequest(Object sender,EventArgs e){      SqlIn ...

  7. PDO防注入原理分析以及使用PDO的注意事项

    我们都知道,只要合理正确使用PDO,可以基本上防止SQL注入的产生,本文主要回答以下两个问题: 为什么要使用PDO而不是mysql_connect? 为何PDO能防注入? 使用PDO防注入的时候应该特 ...

  8. php防注入留言板(simple)

    新手学php,试手案例便是留言板.以前未连接数据库时,我是直接将用户输入的留言写入到一个txt,然后再从txt读取显示(~.~别鄙视). 最近学习了php访问MySQL数据库的一些知识,重写了一下留言 ...

  9. 万能写入sql语句,并且防注入

    通过perpare()方法和检查字段防sql注入. $pdo=new PDO('mysql:host=localhost;dbname=scms', 'root' ); $_POST=array('t ...

随机推荐

  1. 无法加载 DLL“rasapi32.dll”: 动态链接库(DLL)初始化例程失败。

    无法加载 DLL“rasapi32.dll”: 动态链接库(DLL)初始化例程失败. 在Asp.Net项目中使用WebClient或HttpWebRequest时出现以上错误 解决方案:把以下代码放在 ...

  2. android-async-http

    安装 http://blog.csdn.net/wangwei_cq/article/details/9453345 包内的一些基本的参数 http://www.cnblogs.com/manuose ...

  3. WTL汉化版2013.10.15

    汉化内容: 2013.10.15 版本:当前可下载Trunk最新版,wtl-code-467-trunk.zip 汉化内容: 1.应用向导的部分汉化,考虑到部分词汇的表述问题,只汉化无影响部分 2.资 ...

  4. HDU 5379 Mahjong tree

    题意:在一棵有n个节点的树上放编号从1到n的麻将,要求每个点的儿子节点之间的编号连续,每棵子树内的编号连续. 解法:手推一组样例之后就可以得到如下结论然后从根节点一边讨论一边搜就好了. 当一个节点只有 ...

  5. Java SE 6 新特性: Java DB 和 JDBC 4.0

    http://www.ibm.com/developerworks/cn/java/j-lo-jse65/index.html 长久以来,由于大量(甚至几乎所有)的 Java 应用都依赖于数据库,如何 ...

  6. 编程式事务、XML配置事务、注解实现事务

    Spring2.0框架的事务处理有两大类: 1 编码式事务 , 这个不说. 2 声明式事务 , 就说这个. 声明式事务又有三种实现方法: 1 (第一种) 最早的方法,用TransactionProxy ...

  7. Android入门:用HttpClient模拟HTTP的GET和POST请求

    一.HttpClient介绍   HttpClient是用来模拟HTTP请求的,其实实质就是把HTTP请求模拟后发给Web服务器:   Android已经集成了HttpClient,因此可以直接使用: ...

  8. 六种排序的C++实现

    class SortNum { public: SortNum(); virtual ~SortNum(); void exchange(int& b,int& c);//交换数据 v ...

  9. [OFBiz]开发 三

    1. Debug不要在Eclipse中使用Ant来启动ofbiz, 因为在Eclipse中无法kill掉Ant的进程,而ofbiz又没有提供stop的方法.(有一个hook shutdown的方法,但 ...

  10. <转>DNS服务系列之二:DNS区域传送漏洞的安全案例

    DNS区域传送(DNS zone transfer)指的是一台备用服务器使用来自主服务器的数据刷新自己的域(zone)数据库.这为运行中的DNS服务提供了一定的冗余度,其目的是为了防止主的域名服务器因 ...