ASP網站中資料庫被掛木馬的解決方案_木馬相關

來源:互聯網
上載者:User

本文我們詳細介紹了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資料庫被掛木馬時的編程處理方法就介紹到這裡了,希望本次的介紹能夠帶給您一些收穫,謝謝!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.