当前位置: 首页 > 图文教程 > 网络编程 > ASP > ASP网站数据库被挂木马的处理办法

ASP
实例详解ASP中断开记录集的使用方法
代码指导用ASP木马实现FTP和解压缩
防范脚本入侵,你做好准备了吗?
ASP中检查没有数据提交的页面
ASP程序代码执行时间统计类
ASP实现将长的标题用省略号收尾
ASP常用代码剪辑
在ASP中利用“正则表达式” 对象实现UBB风格的论坛
ASP批量生成静态页
ASP生成柱型体,折线图,饼图源代码
马克斯电影站生成Rss Feed的代码
ASP怎么谈到应用到类的?
ASP:判断访问是否来自搜索引擎的函数
ASP代码:rs.open语句详细说明
用asp自动解析网页中的图片地址
ASP:True or False,明明白白你的If语句流程
ASP实现在提交表单到数据库的同时发邮件通知
“Web 匿名用户”帐户密码的位置
ASP分页效果之优化
使用新云cms过程中的问题总结

ASP网站数据库被挂木马的处理办法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 76 ::
收藏到网摘: n/a

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

相关文章:什么是电脑肉鸡?(新手应该知道)

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

第二步

执行如下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