首页 | 心情日记 | 建站心得 | 编程技术 | 大盘分析 | 股市信息 | 学习园地 | 电脑技巧 | 物流外贸 | 另类其它 | 站长推荐 | 给我留言 | 相册

用户登陆
用户:
密码:
 
不保存保存一天
保存一月保存一年

站点日历
73 2024 - 3 48
     12
3456789
10111213141516
17181920212223
24252627282930
31


站点统计

最新评论

日志搜索

 标题   内容


域名空间服务商投诉该找谁? 无法读取源文件或磁盘解决方案
未知 防止SQL注入全功能版本(GET,POST,COOKIES通杀)   [ 日期:2009-12-19 11:33:08 ]   [ 来自:本站原创 ]

海外邮件中继,海外退信中继,美国高速VPS,不限流量VPN,邮局维护和管理,邮件网关,EMOS邮件中继,POSTFIX邮件中继,Winwebmail邮件中继,Winmail邮件中继,DBMail邮件中继,JDMail邮件中继,Exchange邮件中继,MDaemon邮件中继 淘宝店:http://shantan.taobao.com 云邮科技官网:www.yunrelay.com

【字体设置:
以前我发布过一个防止SQL注入的代码,但是现在发现代码还不是很成熟,仅仅可以防止GET的方式的SQL注入,现在把它更新一下,可以同时防止GET,POST,COOKIES攻击的注入:
<%
On Error Resume Next 
Dim strTemp,hk 

If Trim(Request.QueryString) <> "" Then strTemp =Trim(Request.QueryString)
If Trim(Request.Form) <> "" Then strTemp =Trim(Request.Form) 
If Trim(Request.Cookies) <> "" Then strTemp =Trim(Request.Cookies) 
 
strTemp = LCase(strTemp) 
hk=0 
If Instr(strTemp,"%")<>0 then hk=1 
If Instr(strTemp,"count(")<>0 then hk=1 
If Instr(strTemp,"asc(")<>0 then hk=1 
If Instr(strTemp,"mid(")<>0 then hk=1 
If Instr(strTemp,"char(")<>0 then hk=1 
If Instr(strTemp,"xp_cmdshell")<>0 then hk=1 
If Instr(strTemp,"'")<>0 then hk=1 
If Instr(strTemp,"<")<>0 then hk=1 
If Instr(strTemp,"exec")<>0 then hk=1 
If Instr(strTemp,"declare")<>0 then hk=1 
If Instr(strTemp,"char")<>0 then hk=1 
If Instr(strTemp,"@")<>0 then hk=1 
if hk=1 then 
response.write"<center>请勿试图通过提交特殊的字符来注入本站,你的操作已被记录!<br><br>"
response.write"如果你有意见,可以到这里留言:<font color=red><a href=http://www.030904.com/gbook/index.asp>我要留言

</a><br><br>"
response.write "你访问的IP地址是:"&userip
response.end
hk=0 
End If
%>

如果要更高级的代码,建议大家使用下面的,通过正则表达式来计算的,这样可能更有效的防止SQL注入了,也一样是可以防止GET,POST,COOKIES方式的:
<%
Response.Buffer = True   '缓存页面
'防范get注入
If Request.QueryString <> ""   Then StopInjection(Request.QueryString)
'防范post注入
If Request.Form <> ""   Then StopInjection(Request.Form)
'防范cookies注入
If Request.Cookies <> ""   Then StopInjection(Request.Cookies) 

'正则子函数
Function StopInjection(Values)
Dim regEx
Set regEx = New RegExp
     regEx.IgnoreCase = True
     regEx.Global = True
     regEx.Pattern = "'|;|#|([\s\b+()]+(select|update|insert|delete|declare|@|exec|dbcc|alter|drop|create|backup|if|else|end|and|or|add|set|open|close|use|begin|retun|as|go|exists)[\s\b+]*)"
     Dim sItem, sValue
     For Each sItem In Values
         sValue = Values(sItem)
         If regEx.Test(sValue) Then
             Response.Write "<Script Language=javascript>alert('非法注入!你的行为已被记录!!');history.back(-1);</Script>"
             Response.End
         End If
     Next
     Set regEx = Nothing
End function
%>


暂时没有评论
   发表评论 - 不要忘了输入验证码哦!
作者: 用户:  密码:  我要注册 验证码: 
为防止广告注册机程序,验证码不会自动显示,请点击此处显示或者(刷新)验证码!
评论:

禁止表情
禁止UBB
禁止图片
识别链接
识别关键字
确定发布?
最多可以输入200个字,目前你已经输入了0个字;你今日还可以发表10条评论!
 
   

CopyRight © 2008-2010 广东金融学院030904班 All Rights Reserved
Powered by www.030904.com