多语言展示
当前在线:1818今日阅读:113今日分享:31

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

.net作为一种热门的程序编译语言,受到了越来越多朋友的关注,本文为大家详细介绍ASP网站数据库被挂木马的处理办法。都是我自己的一些经验之谈,如果有不对的地方还希望大家及时指出来!
方法/步骤
1

为现有数据库做好备份 这点是很多朋友都知道的,基本正常的网站每隔一段时间都会进行一次备份。这点就不多啰嗦了。

2

执行如下ASP文件 ,这样就可以去掉数据库当中的JS木马 注:conn.asp自己去写了。'这里放入JS木马内容:请记得改为自己数据库中的JS木马内容。<%Server.ScriptTimeOut=180Set rstSchema = conn.OpenSchema(20)k=1Do Until rstSchema.EOF '遍历数据库表If rstSchema('TABLE_TYPE')='TABLE' Thenresponse.write K&'.'&rstSchema('TABLE_NAME') & ':' '显示表名Set rs=Server.CreateObject('ADODB.Recordset') sql='select * from [' & rstSchema ('TABLE_NAME')&']'rs.open sql,conn,1,3For i=0 to rs.fields.count-1 '遍历表中字段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 IfNextresponse.write '
'End IfrstSchema.MoveNextk=k+1Loopresponse.Write '执行成功'%> 如果数据库表很多的话,上面的遍历数据库结构未执行完就 被IIS给停止了。在这时候可以在If rstSchema ('TABLE_TYPE')='TABLE' Then当中适当加 入k值的范围,如:If rstSchema('TABLE_TYPE') ='TABLE' k>10 and k<20 Then这样的话就一次 只操作9个表。

3

根据数据库JS注入的特性 在conn.asp里面 放入如下代码:Function Cheack_Sqljs()'防止数据库外链JS 注入:true为发现外链JS注入。Dim F_Post,F_GetIf Request.Form<>'' Then'表单提交时的检测For Each F_Post In Request.FormIf (Instr(LCase(Request.Form (F_Post)),'0 or Instr(LCase(Request.Form (F_Post)),'')<>0) and Instr(LCase (Request.Form(F_Post)),'http://')<>0 ThenCheack_Sqljs=TrueExit ForEnd IfNextEnd IfIf Request.QueryString<>'' Then'QueryString 提交时的检测For Each F_Get In Request.QueryStringIf (Instr(LCase(Request.Form (F_Get)),'0 or Instr(LCase(Request.Form (F_Get)),'')<>0) and Instr(LCase (Request.Form(F_Get)),'http://')<>0 ThenCheack_Sqljs=TrueExit ForEnd IfNextEnd IfEnd FunctionFunction CheckDataFrom()'检查提交数据来源:True为数据从站外提交过来 的CheckDataFrom=Trueserver_v1=Cstr(Request.ServerVariables ('HTTP_REFERER'))server_v2=Cstr(Request.ServerVariables ('SERVER_NAME'))end ifEnd FunctionIf Cheack_Sqljs or CheckDataFrom ThenResponse.Write ''Response.End()End If

推荐信息