ASP防注入
因为在改进公司的一套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,"""",""") '双引号
- str=replace(str,"chr(9)"," ") '空格
- str=replace(str,"chr(10)","<br>") '回车
- str=replace(str,"chr(13)","<br>") '回车
- str=replace(str,"chr(32)"," ") '空格
- str=replace(str,"chr(34)",""") '双引号
- str=replace(str,"chr(39)","'") '单引号
- str=Replace(str, "script", "script")'jscript
- str=replace(str,"<","<") '左<
- str=replace(str,">",">") '右>
- 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防注入的更多相关文章
- asp防注入安全问题
一.古老的绕验证漏洞虽然古老,依然存在于很多小程序之中,比如一些企业网站的后台,简单谈谈.这个漏洞出现在没有对接受的变量进行过滤,带入数据库判断查询时,造成SQL语句的逻辑问题.例如以下代码存在问题: ...
- SQL防注入程序 v1.0
/// ***************C#版SQL防注入程序 v1.0************ /// *使用方法: /// 一.整站防注入(推荐) /// 在Global.asax.cs中查找App ...
- 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 ...
- 简单实用的PHP防注入类实例
这篇文章主要介绍了简单实用的PHP防注入类实例,以两个简单的防注入类为例介绍了PHP防注入的原理与技巧,对网站安全建设来说非常具有实用价值,需要的朋友可以参考下 本文实例讲述了简单实用的PHP防注 ...
- [转]PDO防注入原理分析以及使用PDO的注意事项
原文:http://zhangxugg-163-com.iteye.com/blog/1835721 好文章不得不转. 我们都知道,只要合理正确使用PDO,可以基本上防止SQL注入的产生,本文主要回答 ...
- SQL防注入程序
1.在Global.asax.cs中写入: protected void Application_BeginRequest(Object sender,EventArgs e){ SqlIn ...
- PDO防注入原理分析以及使用PDO的注意事项
我们都知道,只要合理正确使用PDO,可以基本上防止SQL注入的产生,本文主要回答以下两个问题: 为什么要使用PDO而不是mysql_connect? 为何PDO能防注入? 使用PDO防注入的时候应该特 ...
- php防注入留言板(simple)
新手学php,试手案例便是留言板.以前未连接数据库时,我是直接将用户输入的留言写入到一个txt,然后再从txt读取显示(~.~别鄙视). 最近学习了php访问MySQL数据库的一些知识,重写了一下留言 ...
- 万能写入sql语句,并且防注入
通过perpare()方法和检查字段防sql注入. $pdo=new PDO('mysql:host=localhost;dbname=scms', 'root' ); $_POST=array('t ...
随机推荐
- UVa 699 The Falling Leaves
题意:给出按先序输入的一颗二叉树,分别求出从左到右的相同横坐标上的节点的权值之和 递归建树,然后用sum数组分别统计每一个横坐标上的权值之和 感觉建树都在递归递归递归= =慢慢理解吧 #include ...
- js 时间转成时间戳对比;My97DatePicker日历控件时间格式;Date.parse Firefox火狐浏览器返回Nan的解决办法
有个情况,我在显示时间的时候是需要显示为 2013年8月15日 14时28分15秒 但是假如我用js去获取到这个时间,并且想进行时间对比的时候,这个时间2013年8月15日 14时28分15秒根本就 ...
- Java知识点:内部类
内部类class文件命名规则 普通内部类.静态内部类:<Outer>\$<Inner>.class,其中<Outer>为外部类类名,<Inner>为内部 ...
- codevs 3123 高精度练习之超大整数乘法
fft. #include<iostream> #include<cstdio> #include<cstring> #include<complex> ...
- Jabber/XMPP协议与架构
一.概述 由Jeremie Miller于1998年开始这个项目.Jabber是一个开放源码形式组织产生的网络实时通信协议,第一个公开版本于2000年5月发行.Jabber已经由IETF XMPP协议 ...
- [HTML Q&A][转]使pre的内容自动换行
<pre> 元素可定义预格式化的文本.被包围在 pre 元素中的文本通常会保留空格和换行符.而文本也会呈现为等宽字体. <pre> 标签的一个常见应用就是用来表示计算机的源代码 ...
- C# Read/Write another Process' Memory z
http://www.codeproject.com/Articles/670373/Csharp-Read-Write-another-Process-Memory This article aim ...
- again
建立一个IPC连接: net use \\192.168.0.5\ipc$ "123456" /u:administrator
- Rust 中的继承与代码复用
在学习Rust过程中突然想到怎么实现继承,特别是用于代码复用的继承,于是在网上查了查,发现不是那么简单的. C++的继承 首先看看c++中是如何做的. 例如要做一个场景结点的Node类和一个Sprit ...
- 【C#】字符串与字符数组
字符串与字符数组的相互转换. 字符串转换成字符数组: string ss="abcdefg"; char[] cc=ss.ToCharArray(); 字符数组转换成字符串 ...