程序员

ASP网站中数据库被挂木马的解决方案

作者:admin 2021-04-18 我要评论

本文我们详细介绍了ASP数据库被挂木马的详细解决方案之编程处理的方法,解决方案分为以下三步: 第一步: 为现有数据库做好备份。 第二步: 执行如下ASP文件,这...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

本文我们详细介绍了ASP数据库被挂木马的详细解决方案之编程处理的方法,解决方案分为以下三步:

第一步:

为现有数据库做好备份。

第二步:

执行如下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 
 
kk=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 orInstr(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数据库被挂木马时的编程处理方法就介绍到这里了,希望本次的介绍能够带给您一些收获,谢谢!


原文链接:https://m.jb51.net/article/72123.htm

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • 四两拨千斤——你不知道的VScode编码Ty

    四两拨千斤——你不知道的VScode编码Ty

  • 我是如何在 Vue 项目中做代码分割的

    我是如何在 Vue 项目中做代码分割的

  • position:sticky 粘性定位的几种巧妙应

    position:sticky 粘性定位的几种巧妙应

  • 从零到一搭建React组件库

    从零到一搭建React组件库