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 ...
随机推荐
- bzoj3983
显然我们得到这样几个结论 1.每次攻击对方一定是攻击最大的 2.自己合并也是合并最大和次大的 我们只要穷举下一开始是攻击还是合并,之后就是能攻击先攻击否则就合并 ..] of int64; var a ...
- Parallel并行运算实例
并行运算Parallel,是.net 4.0版本里添加的新处理方式,主要充分利用CPU.任务并发的模式来达到提高运算能力.简单理解为每个CPU都在处理任务,而不会让它们空闲下来. 直接看实例: nam ...
- LeetCode: JumpGame 1 and 2
Title : Given an array of non-negative integers, you are initially positioned at the first index of ...
- UVA 10047 The Monocycle
大白图论第二题··· 题意:独轮车的轮子被均分成五块,每块一个颜色,每走过一个格子恰好转过一个颜色. 在一个迷宫中,只能向前走或者左转90度或右转90度(我曾天真的认为是向左走和向右走···),每个操 ...
- POJ 3977 Subset
Subset Time Limit: 30000MS Memory Limit: 65536K Total Submissions: 3161 Accepted: 564 Descriptio ...
- Keep the Customer Satisfied
题意: n个订单,每个订单有完成需要的天数,和限制的天数,求最多能完成多少订单 分析: 先按限制日期升序排列,若当前订单不能完成,和上面已选中的订单中需要天数中最大的比较,若比它小,则替换他. #in ...
- Authentication with SignalR and OAuth Bearer Token
Authentication with SignalR and OAuth Bearer Token Authenticating connections to SignalR is not as e ...
- Fedora22(Gnome桌面)安装Chrome
1.从官网上(http://www.google.cn/chrome/)下载到相对应系统版本的rpm包.这里我的是: google-chrome-stable_current_x86_64.rpm 此 ...
- cxf 动态创建客户端,局域网能正常调用服务端,外网不能访问
- Spark RDD概念学习系列之Spark的算子的分类(十一)
Spark的算子的分类 从大方向来说,Spark 算子大致可以分为以下两类: 1)Transformation 变换/转换算子:这种变换并不触发提交作业,完成作业中间过程处理. Transformat ...