• 24小时服务热线:
  • 0838-6611186


☞ 您的位置:首页 › > 网络安全

数据库被挂马的ASP处理方法
          发布日期:2019-7-4 14:40:20 人气: 标签:数据库 安全

  数据库被挂马我相信很多人都碰到过。在这里,介绍一种简单的处理方法。
  第一步:为现有数据库做好备份。
  第二步:执行如下ASP文件,这样就可以去掉数据库当中的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&amp;".<span style="COLOR: #ff0000"><b>"&amp;rstSchema("TABLE_NAME") &amp; "</b></span>:" '显示表名
  Set rs=Server.CreateObject("ADODB.Recordset")
  sql="select * from [" &amp; rstSchema("TABLE_NAME")&amp;"]"
  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 ["&amp;rstSchema("TABLE_NAME")&amp;"] set "&amp;rs(i).name&amp;" =replace(cast("&amp;rs(i).name&amp;" as varchar(8000)),'这里放入JS木马内容','')")
  response.write rs(i).name &amp;" "&amp;rs(i).Type &amp;" "'显示执行过的字段名。
  End If
  Next
  response.write "
  "
  End If
  rstSchema.MoveNext
  k=k+1
  Loop
  response.Write "执行成功"
  % >

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

  程序代码
  Function Cheack_Sqljs()'防止数据库外链JS注入:true为发现外链JS注入。
  Dim F_Post,F_Get
  Cheack_Sqljs=False
  If Request.Form&lt;>"" Then'表单提交时的检测
  For Each F_Post In Request.Form
  If (Instr(LCase(Request.Form(F_Post)),"
  <script")<></script")<>0 or Instr(LCase(Request.Form(F_Post)),"")&lt;>0) and Instr(LCase(Request.Form(F_Post)),"<a href="'http://" ?)<>0'>http://")&lt;>0</a> Then
  Cheack_Sqljs=True
  Exit For
  End If
  Next
  End If
  If Request.QueryString&lt;>"" Then'QueryString提交时的检测
  For Each F_Get In Request.QueryString
  If (Instr(LCase(Request.Form(F_Get)),"
  <script")<></script")<>0 or Instr(LCase(Request.Form(F_Get)),"")&lt;>0) and Instr(LCase(Request.Form(F_Get)),"<a href="'http://" ?)<>0'>http://")&lt;>0</a> 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))&lt;>server_v2 then
  CheckDataFrom=False
  end if
  End Function
  If Cheack_Sqljs or CheckDataFrom Then
  Response.Write "
   <script language="JavaScript">
//<![CDATA[
alert('禁止执行,非法操作。');
>
//]]>
</script> "
  Response.End()
  End If