[asp]数据库被挂马的ASP处理方法

作者:红心男孩 来源:蓝色理想 时间:2009-03-09 13:00:00 

数据库被挂马我相信很多人都碰到过。在这里,我讲下我处理的方法。

第一步:为现有数据库做好备份。

第二步

执行如下ASP文件,这样就可以去掉数据库当中的JS木马:

注:conn.asp自己去写了。

'这里放入JS木马内容:请记得改为自己数据库中的JS木马内容。
<!--#include file="conn.asp"-->
<%
Server.ScriptTimeOut=180
Set rstSchema = conn.OpenSchema(20)
k=1
Do Until rstSchema.EOF '遍历数据库表
    If rstSchema("TABLE_TYPE")="TABLE" Then
        response.write K&".<font color=red><b>"&rstSchema("TABLE_NAME") & "</b></font>:" '显示表名
        Set rs=Server.CreateObject("ADODB.Recordset")
        sql="select * from [" & rstSchema("TABLE_NAME")&"]"
        rs.open sql,conn,1,3
        For i=0 to rs.fields.count-1 '遍历表中字段
           If int(rs(i).Type)=129 or int(rs(i).Type)=130 or int(rs(i).Type)=200 or int(rs(i).Type)=201 or int(rs(i).Type)=202 or int(rs(i).Type)=203 Then'只处理字段类型为字符型的字段
            conn.execute("update ["&rstSchema("TABLE_NAME")&"] set "&rs(i).name&" =replace(cast("&rs(i).name&" as varchar(8000)),'这里放入JS木马内容','')")
            response.write rs(i).name &" "&rs(i).Type &" "'显示执行过的字段名。
          End If
        Next
        response.write "<br>"
    End If
    rstSchema.MoveNext
    k=k+1
Loop
response.Write "执行成功"
%>

如果数据库表很多的话,上面的遍历数据库结构未执行完就被IIS给停止了。在这时候可以在

If rstSchema("TABLE_TYPE")="TABLE" Then

当中适当加入k值的范围,如:

If rstSchema("TABLE_TYPE")="TABLE" k>10 and k<20 Then

这样的话就一次只操作9个表。

第三步

根据数据库JS注入的特性(会包括<script、</script>和http://这样的字符),
在conn.asp里面放入如下代码:


Function Cheack_Sqljs()'防止数据库外链JS注入:true为发现外链JS注入。
    Dim F_Post,F_Get
    Cheack_Sqljs=False
    If Request.Form<>"" Then'表单提交时的检测
        For Each F_Post In Request.Form
            If (Instr(LCase(Request.Form(F_Post)),"<script")<>0 or Instr(LCase(Request.Form(F_Post)),"</script>")<>0) and Instr(LCase(Request.Form(F_Post)),"http://")<>0 Then
                Cheack_Sqljs=True
                Exit For
            End If
        Next
    End If
    If Request.QueryString<>"" Then'QueryString提交时的检测
        For Each F_Get In Request.QueryString
            If (Instr(LCase(Request.Form(F_Get)),"<script")<>0 or Instr(LCase(Request.Form(F_Get)),"</script>")<>0) and Instr(LCase(Request.Form(F_Get)),"http://")<>0 Then
                Cheack_Sqljs=True
                Exit For
            End If
        Next
    End If
End Function
Function CheckDataFrom()'检查提交数据来源:True为数据从站外提交过来的
    CheckDataFrom=True
    server_v1=Cstr(Request.ServerVariables("HTTP_REFERER"))
    server_v2=Cstr(Request.ServerVariables("SERVER_NAME"))
    if mid(server_v1,8,len(server_v2))<>server_v2 then
        CheckDataFrom=False
    end if
End Function
If Cheack_Sqljs or CheckDataFrom Then
   Response.Write "<Script Language=JavaScript>alert('禁止执行,非法操作。');</Script>"
   Response.End()
End If

标签:木马,挂马,数据库,asp
0
投稿

猜你喜欢

  • 维护服务器安全的七大技巧

    2012-03-26 19:04:34
  • 未来在拐角:成功站长改写落魄岁月

    2009-03-11 17:53:00
  • QQ2009 正式版SP6优先体验启动 下载QQ2009正式版SP6

    2009-12-02 11:56:00
  • 最近淘宝上最流行的骗术

    2008-07-18 12:16:00
  • Linux系统下的动态DNS服务配置方法详解

    2010-01-04 19:20:00
  • 什么是 POP3 POP3 命令简介

    2010-03-24 18:31:00
  • Google AdSense 高价中文关键词(参考)

    2009-02-13 12:46:00
  • 防范ASP木马的十大基本原则

    2007-09-14 10:50:00
  • 选择邮件服务器十二要素(2)

    2007-09-19 13:52:00
  • DEDE5.35.3软件下载突破12个链接限制的方法

    2009-02-15 09:27:00
  • 在Windows Server下集成Apache、Tomcat和IIS

    2008-04-17 14:23:00
  • 两种隐性的无效广告展示

    2008-07-27 16:57:00
  • 友情链接 让我们的网站快速发展

    2008-06-05 12:46:00
  • Win2003架设WEB服务器

    2007-03-26 10:58:00
  • 谷歌每小时收入200万美元 神秘的团队

    2008-06-05 13:19:00
  • 百度算法松动 开始逐步解封部分站点

    2007-11-23 00:05:00
  • 简单而又效的网页标题的写法

    2007-11-29 13:07:00
  • Godaddy主机空间IP被封了怎么办?

    2010-04-08 12:47:00
  • 配置Telnet服务与配置Ftp服务

    2009-12-07 19:23:00
  • 网站优化如何操作 做好九个方面基础工作

    2008-12-30 10:12:00
  • asp之家 网站运营 m.aspxhome.com