


ASP數(shù)據(jù)庫被掛馬的編程處理方法
數(shù)據(jù)庫被掛馬我相信很多人都碰到過。在這里,我講下我處理的方法。
第一步:為現(xiàn)有數(shù)據(jù)庫做好備份。
第二步:執(zhí)行如下ASP文件,這樣就可以去掉數(shù)據(jù)庫當中的JS木馬:
注:conn.asp自己去寫了。
'這里放入JS木馬內(nèi)容:請記得改為自己數(shù)據(jù)庫中的JS木馬內(nèi)容。
<!--#include file="conn.asp"-->
<%
Server.TimeOut=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 "<br>"
End If
rstSchema.MoveNext
k=k+1
Loop
response.Write "執(zhí)行成功"
%>
如果數(shù)據(jù)庫表很多的話,上面的遍歷數(shù)據(jù)庫結(jié)構(gòu)未執(zhí)行完就被IIS給停止了。在這時候可以在:
If rstSchema("TABLE_TYPE")="TABLE" Then
當中適當加入k值的范圍,如:
If rstSchema("TABLE_TYPE")="TABLE" k>10 and k<20 Then
這樣的話就一次只操作9個表。
第三步:
根據(jù)數(shù)據(jù)庫JS注入的特性(會包括<、</>和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'表單提交時的檢測For Each F_Post In Request.Form If (Instr(LCase(Request.Form(F_Post)),"<")<>0 or Instr(LCase(Request.Form(F_Post)),"</>")<>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)),"<")<>0 or Instr(LCase(Request.Form(F_Get)),"</>")<>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 "< Language=Java>alert('禁止執(zhí)行,非法操作。');</>" Response.End()
End If
關鍵字:ASP、數(shù)據(jù)庫、掛馬、編程
新文章:
- CentOS7下圖形配置網(wǎng)絡的方法
- CentOS 7如何添加刪除用戶
- 如何解決centos7雙系統(tǒng)后丟失windows啟動項
- CentOS單網(wǎng)卡如何批量添加不同IP段
- CentOS下iconv命令的介紹
- Centos7 SSH密鑰登陸及密碼密鑰雙重驗證詳解
- CentOS 7.1添加刪除用戶的方法
- CentOS查找/掃描局域網(wǎng)打印機IP講解
- CentOS7使用hostapd實現(xiàn)無AP模式的詳解
- su命令不能切換root的解決方法
- 解決VMware下CentOS7網(wǎng)絡重啟出錯
- 解決Centos7雙系統(tǒng)后丟失windows啟動項
- CentOS下如何避免文件覆蓋
- CentOS7和CentOS6系統(tǒng)有什么不同呢
- Centos 6.6默認iptable規(guī)則詳解