Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 网站建设 > 网页制作 > asp防SQL注入程序优化版本
【标  题】:asp防SQL注入程序优化版本
【关键字】:asp,SQL
【来  源】:http://blog.csdn.net/firstaking/archive/2007/03/05/1521279.aspx

asp防SQL注入程序优化版本

Your Ad Here

建立一个名称为“SqlIn”的access数据库。

在数据库中建立一个名称为“SqlIn”的表,表结构如下

SqlIn_ID(自动编号)
SqlIn_IP(注入ip记录)
SqlIn_WEB(注入的web)
SqlIn_TIME(注入时间)
SqlIn_FS(数据传送方式)
SqlIn_CS(提交内容)
SqlIn_SJ(注入字符)

建立一个名为SqlIn.asp的网页,在其他asp网页中引用该网页就可以达到防止sql注入。

将下面语句放在最开始
<!--#include file="相对路径/sqlin.asp"--> 

<% '--------定义部份------------------
Dim wy_conn,wy_connstr,wy_in,wy_inf,wy_Post,wy_xh,wy_Get
'自定义需要过滤的字串,用 "@" 分隔
wy_in = "'@*@declare"'@and@exec@insert@select@delete@update@count@*@chr@mid@master@truncate@char@declare
wy_inf = split(wy_in,"@")
'--------POST部份------------------
 wy_connstr="Data Source="&server.MapPath("/sqlin/sqlin.mdb")&";Provider=Microsoft.Jet.OLEDB.4.0;"
set wy_conn=server.CreateObject("adodb.connection")
 wy_conn.open wy_connstr
 
If Request.Form<>"" Then
  For Each wy_Post In Request.Form
     For wy_xh=0 To Ubound(wy_inf)
         If Instr(LCase(Request.Form(wy_Post)),wy_inf(wy_xh))<>0 Then
           wy_conn.Execute("insert into SqlIn(Sqlin_IP,SqlIn_Web,SqlIn_FS,SqlIn_CS,SqlIn_SJ) values('"&Request.ServerVariables("REMOTE_ADDR")&"','"&Request.ServerVariables("URL")&"','POST','"&wy_Post&"','"&replace(Request.Form(wy_Post),"'","''")&"')")
             response.Write(" 参数中包含非法字符<br>" & _
                    "操作IP:" & Request.ServerVariables("REMOTE_ADDR")& "<br>" & _
                      "操作时间:" & Now& "<br> "& _
                    "操作页面:" &Request.ServerVariables("URL")& "<br> "& _
                    "提交方式:POST<br>"& _
                    "提交参数:" &wy_Post & "<br>"& _
                    "提交数据:" &Request.Form(wy_Post)& "<br>"& _
                          "<a  href=""javascript:history.go(-1)"">返回</a>")
     wy_conn.close
              Set wy_conn = Nothing    
     response.End()
        End If
       Next
  Next
End If

'---------GET部分-------------
If Request.QueryString<>"" Then
   For Each wy_Get In Request.QueryString
      For wy_xh=0 To Ubound(wy_inf)
         If Instr(LCase(Request.QueryString(wy_Get)),wy_Inf(wy_xh))<>0 Then
              wy_conn.Execute("insert into SqlIn(Sqlin_IP,SqlIn_Web,SqlIn_FS,SqlIn_CS,SqlIn_SJ) values('"&Request.ServerVariables("REMOTE_ADDR")&"','"&Request.ServerVariables("URL")&"','GET','"&wy_Get&"','"&replace(Request.QueryString(wy_Get),"'","''")&"')")
             response.Write(" 参数中包含非法字符<br>" & _
                       "操作IP:" & Request.ServerVariables("REMOTE_ADDR")& "<br>" & _
                        "操作时间:" & Now& "<br> "& _
                       "操作页面:" &Request.ServerVariables("URL")& "<br> "& _
                       "提交方式:GET<br>"& _
                       "提交参数:" &wy_Get & "<br>"& _
                       "提交数据:" &Request.Form(wy_Get)& "<br>"& _
                             "<a  href=""javascript:history.go(-1)"">返回</a>") 
       wy_conn.close
                Set wy_conn = Nothing 
                response.End()
          End If
       Next
   Next
End If
wy_conn.close
Set wy_conn = Nothing
%>

XML傳送與接收:【上一篇】
ADO游标类型和锁类型使用参考:【下一篇】
【相关文章】
  • asp插入图片的一种模式
  • asp之formatnumber函数
  • ASP生成过渡色的子程序!
  • Mysql分页查询通用存储过程
  • 删除SQL数据库中事务日志方法
  • mysql存储过程及c#调用标准版
  • asp.net 中 使用 ado 的 Recordset GetString 函数 By shawl.qiu
  • 花了一段时间整理和使用的提高ASP.NET效率的几个方面(希望大家拍砖)
  • Asp.NET 生成随机码
  • 分页代码及相应SQL效率的分析(附:测试报告结果)
  • 【随机文章】
  • DWF文件简介、创建、设置和查看
  • Jasper的调试报告
  • 像素按钮的制作方法
  • CS/AIX的安装和配置
  • 基于myFaces的JSF技术使用中的一些经验(三)--使用myFaces的建立一个xml文件的树形表示
  • SUN软件包管理的命令:pkginfo、pkgadd和pkgrm
  • Apache commons-Email中文问题的解决办法
  • SQL SERVER 2000系统支持的跟踪函数
  • qemu
  • lsof使用技巧
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.