ASP網(wǎng)站中數(shù)據(jù)庫被掛木馬的解決方案
本文我們?cè)敿?xì)介紹了ASP數(shù)據(jù)庫被掛木馬的詳細(xì)解決方案之編程處理的方法,解決方案分為以下三步:
第一步:
為現(xiàn)有數(shù)據(jù)庫做好備份。
第二步:
執(zhí)行如下ASP文件,這樣就可以去掉數(shù)據(jù)庫當(dāng)中的JS木馬:
注:conn.asp自己去寫了。
'這里放入JS木馬內(nèi)容:請(qǐng)記得改為自己數(shù)據(jù)庫中的JS木馬內(nèi)容。
<!--#include file="conn.asp"-->
<%
Server.ScriptTimeOut=180 Set rstSchema = conn.OpenSchema(20)
k=1
Do Until rstSchema.EOF '遍歷數(shù)據(jù)庫表
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木馬內(nèi)容','')") response.write rs(i).name &" "&rs(i).Type &" "'顯示執(zhí)行過的字段名。
End If
Next
response.write "
"
End If
rstSchema.MoveNext
kk=k+1
Loop
response.Write "執(zhí)行成功"
%> 如果數(shù)據(jù)庫表很多的話,上面的遍歷數(shù)據(jù)庫結(jié)構(gòu)未執(zhí)行完就被IIS給停止了。在這時(shí)候可以在:
If rstSchema("TABLE_TYPE")="TABLE" Then
當(dāng)中適當(dāng)加入k值的范圍,如:
If rstSchema("TABLE_TYPE")="TABLE" k>10 and k<20 Then
這樣的話就一次只操作9個(gè)表。
第三步:
根據(jù)數(shù)據(jù)庫JS注入的特性(會(huì)包括<script、</script>和http://這樣的字符),在conn.asp里面放入如下代碼:
Function Cheack_Sqljs()'防止數(shù)據(jù)庫外鏈JS注入:true為發(fā)現(xiàn)外鏈JS注入。
Dim F_Post,F_Get
Cheack_Sqljs=False
If Request.Form<>"" Then'表單提交時(shí)的檢測(cè)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提交時(shí)的檢測(cè)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()'檢查提交數(shù)據(jù)來源:True為數(shù)據(jù)從站外提交過來的
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('禁止執(zhí)行,非法操作。');</Script>" Response.End()
End If 關(guān)于ASP數(shù)據(jù)庫被掛木馬時(shí)的編程處理方法就介紹到這里了,希望本次的介紹能夠帶給您一些收獲,謝謝!
- ASP連接Access數(shù)據(jù)庫的幾種方法
- ASP連接SQL2005數(shù)據(jù)庫連接代碼
- 完美解決ASP 不能更新。數(shù)據(jù)庫或?qū)ο鬄橹蛔x。
- asp.net連接查詢SQL數(shù)據(jù)庫并把結(jié)果顯示在網(wǎng)頁上(2種方法)
- asp中用insert into語句向數(shù)據(jù)庫插入記錄(添加信息)的方法
- Win7 ASP連接數(shù)據(jù)庫“未找到提供程序.該程序可能未正確安裝”問題
- asp連接mysql數(shù)據(jù)庫詳細(xì)實(shí)現(xiàn)代碼
- ASP.NET 6種常用數(shù)據(jù)庫的連接方法
- asp 刪除數(shù)據(jù)庫記錄的代碼
- asp.net中EXCEL數(shù)據(jù)導(dǎo)入到數(shù)據(jù)庫的方法
相關(guān)文章
用asp實(shí)現(xiàn)的iframe批量替換工具
用asp實(shí)現(xiàn)的iframe批量替換工具...2007-09-09

