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

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

还考虑了script注入。

代码如下:

  1. 'Asp防注入代码
  2. SQL_injdata =lcase(":|;|>|<|--|sp_|xp_|\|dir|cmd|^|(|)|+|$|'")
  3. SQL_injdata =SQL_injdata&lcase("|copy|format|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare|script")
  4. SQL_inj = split(SQL_Injdata,"|")
  5.  
  6. if Request.QueryString<>"" then
  7. For Each SQL_Get In Request.QueryString
  8. For SQL_Data= To Ubound(SQL_inj)
  9. if not IsNumeric(Request.QueryString(SQL_Get)) then
  10. if instr(lcase(Request.QueryString(SQL_Get)),Sql_Inj(Sql_DATA))> Then
  11. Response.Write "对不起,非法URL地址请求!"
  12. Response.end
  13. end if
  14. end if
  15. next
  16. next
  17. end if
  18.  
  19. if Request.Form<>"" then
  20. For Each Sql_Post In Request.Form
  21. For SQL_Data= To Ubound(SQL_inj)
  22. if instr(lcase(Request.Form(Sql_Post)),Sql_Inj(Sql_DATA))> Then
  23. Response.Write "对不起,非法数据提交!"
  24. Response.end
  25. end if
  26. next
  27. next
  28. end if
  29.  
  30. if Request.Cookies<>"" then
  31. For Each Sql_Post In Request.Cookies
  32. For SQL_Data= To Ubound(SQL_inj)
  33. if instr(lcase(Request.Cookies(Sql_Post)),Sql_Inj(Sql_DATA))> Then
  34. Response.Write "对不起,非法URL地址请求!"
  35. Response.end
  36. end if
  37. next
  38. next
  39. end if
  40.  
  41. 'post过滤sql注入代防范及HTML防护开始
  42. function nosql(str)
  43. if not isnull(str) then
  44. str=trim(str)
  45. str=replace(str,";",";") '分号
  46. str=replace(str,"'","'") '单引号
  47. str=replace(str,"""","&quot;") '双引号
  48. str=replace(str,"chr(9)","&nbsp;") '空格
  49. str=replace(str,"chr(10)","<br>") '回车
  50. str=replace(str,"chr(13)","<br>") '回车
  51. str=replace(str,"chr(32)","&nbsp;") '空格
  52. str=replace(str,"chr(34)","&quot;") '双引号
  53. str=replace(str,"chr(39)","'") '单引号
  54. str=Replace(str, "script", "&#115cript")'jscript
  55. str=replace(str,"<","&lt;") '左<
  56. str=replace(str,">","&gt;") '右>
  57. str=replace(str,"(","(") '左(
  58. str=replace(str,")",")") '右)
  59. str=replace(str,"--","--") 'SQL注释符
  60.  
  61. str=replace(str,"net user","")
  62. str=replace(str,"xp_cmdshell","")
  63. str=replace(str,"/add","")
  64. str=replace(str,"exec%20master.dbo.xp_cmdshell","")
  65. str=replace(str,"net localgroup administrators","")
  66. str=replace(str,"select","")
  67. str=replace(str,"count","")
  68. str=replace(str,"asc","")
  69. str=replace(str,"char","")
  70. str=replace(str,"mid","")
  71. str=replace(str,":","")
  72. str=replace(str,"insert","")
  73. str=replace(str,"delete","")
  74. str=replace(str,"drop","")
  75. str=replace(str,"truncate","")
  76. str=replace(str,"from","")
  77. str=replace(str,"%","")
  78. nosql=str
  79. end if
  80. 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. UVa 699 The Falling Leaves

    题意:给出按先序输入的一颗二叉树,分别求出从左到右的相同横坐标上的节点的权值之和 递归建树,然后用sum数组分别统计每一个横坐标上的权值之和 感觉建树都在递归递归递归= =慢慢理解吧 #include ...

  2. js 时间转成时间戳对比;My97DatePicker日历控件时间格式;Date.parse Firefox火狐浏览器返回Nan的解决办法

    有个情况,我在显示时间的时候是需要显示为  2013年8月15日 14时28分15秒 但是假如我用js去获取到这个时间,并且想进行时间对比的时候,这个时间2013年8月15日 14时28分15秒根本就 ...

  3. Java知识点:内部类

    内部类class文件命名规则 普通内部类.静态内部类:<Outer>\$<Inner>.class,其中<Outer>为外部类类名,<Inner>为内部 ...

  4. codevs 3123 高精度练习之超大整数乘法

    fft. #include<iostream> #include<cstdio> #include<cstring> #include<complex> ...

  5. Jabber/XMPP协议与架构

    一.概述 由Jeremie Miller于1998年开始这个项目.Jabber是一个开放源码形式组织产生的网络实时通信协议,第一个公开版本于2000年5月发行.Jabber已经由IETF XMPP协议 ...

  6. [HTML Q&A][转]使pre的内容自动换行

    <pre> 元素可定义预格式化的文本.被包围在 pre 元素中的文本通常会保留空格和换行符.而文本也会呈现为等宽字体. <pre> 标签的一个常见应用就是用来表示计算机的源代码 ...

  7. C# Read/Write another Process' Memory z

    http://www.codeproject.com/Articles/670373/Csharp-Read-Write-another-Process-Memory This article aim ...

  8. again

    建立一个IPC连接: net use \\192.168.0.5\ipc$ "123456" /u:administrator

  9. Rust 中的继承与代码复用

    在学习Rust过程中突然想到怎么实现继承,特别是用于代码复用的继承,于是在网上查了查,发现不是那么简单的. C++的继承 首先看看c++中是如何做的. 例如要做一个场景结点的Node类和一个Sprit ...

  10. 【C#】字符串与字符数组

    字符串与字符数组的相互转换. 字符串转换成字符数组: string ss="abcdefg"; char[] cc=ss.ToCharArray();     字符数组转换成字符串 ...