在線掃描探測檢查asp站點(diǎn)木馬后門的程序
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
'設(shè)置登陸密碼,使用前務(wù)必修改此密碼
PASSWORD = "www.pifoo.com"
'其他掃描設(shè)置
DimFileExt = "asp,cer,asa,cdx" '文件類型擴(kuò)展名列表,不在此列表的將不被掃描
maxfilesize= 51200 '500K,超過此文件大小的文件(一般不是木馬),將不被掃描
timeout=600 '如果掃描超過600秒,腳本將終止
'jspadmin@asp.web.csdn=阿笨狗=飛云 修改于2006.07.07
'獲取最新修改版本,請(qǐng)關(guān)注http://www.pifoo.com
'QQ:33323489 Email:subaoliang@etang.com Guestbook:http://www.pifoo.com/lyb
dim Report
if request.QueryString("act")="login" then
if request.Form("pifoo") = PASSWORD then session("pifoo")="#)\'www.pifoo.com"
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>asp木馬、后門探測器</title>
</head>
<body>
<%If Session("pifoo") <>"#)\'www.pifoo.com" then%>
<form name="form1" method="post" action="?act=login">
<div align="center">Password:
<input name="pifoo" type="password" size="15">
<input type="submit" name="Submit" value="提交">
</div>
</form>
<%
else
if request.QueryString("act")<>"scan" then
%>
<form action="?act=scan" method="post">
<b>填入你要檢查的路徑:</b>
<input name="path" type="text" style="border:1px solid #999" value="." size="30" />
<br>
* 網(wǎng)站根目錄的相對(duì)路徑,填"\"即檢查整個(gè)網(wǎng)站;"."為程序所在目錄
<br>
<br>
<input type="submit" value=" 開始掃描 " style="background:#fff;border:1px solid #999;padding:2px 2px 0px 2px;margin:4px;border-width:1px 3px 1px 3px" />
</form>
<%
else
server.ScriptTimeout = timeout
Sun = 0
SumFiles = 0
SumFolders = 1
if request.Form("path")="" then
response.Write("沒有發(fā)現(xiàn)被入侵的跡象.")
response.End()
end if
timer1 = timer
if request.Form("path")="\" then
TmpPath = Server.MapPath("\")
elseif request.Form("path")="." then
TmpPath = Server.MapPath(".")
else
TmpPath = Server.MapPath("\")&"\"&request.Form("path")
end if
Call ShowAllFile(TmpPath)
%>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="CContent">
<tr>
<th>ASP木馬、后門、漏洞掃描探測
</tr>
<tr>
<td class="CPanel" style="padding:5px;line-height:170%;clear:both;font-size:12px">
<div id="updateInfo" style="background:ffffe1;border:1px solid #89441f;padding:4px;display:none"></div>
掃描完畢!一共檢查文件夾<font color="#FF0000"><%=SumFolders%></font>個(gè),文件<font color="#FF0000"><%=SumFiles%></font>個(gè),發(fā)現(xiàn)可疑點(diǎn)<font color="#FF0000"><%=Sun%></font>個(gè)
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top">
<table width="100%" border="1" cellpadding="0" cellspacing="0" style="padding:5px;line-height:170%;clear:both;font-size:12px">
<tr>
<td width="20%">文件相對(duì)路徑</td>
<td width="20%">特征碼</td>
<td width="40%">描述</td>
<td width="20%">創(chuàng)建/修改時(shí)間</td>
</tr>
<p>
<%=Report%>
<br/></p>
</table></td>
</tr>
</table>
</td></tr></table>
<%
timer2 = timer
thetime=cstr(int(((timer2-timer1)*10000 )+0.5)/10)
response.write "<br><font size=""2"">本頁執(zhí)行共用了"&thetime&"毫秒</font>"
end if
end if
%>
<hr>
<div align="center"><br>
Modified by <a target=_blank>jspadmin</a> at 2006.07.07
</div>
</body>
</html>
<%
'遍歷處理path及其子目錄所有文件
Sub ShowAllFile(Path)
Set FSO = createObject("Scripting.FileSystemObject")
if not fso.FolderExists(path) then exit sub
Set f = FSO.GetFolder(Path)
Set fc2 = f.files
For Each myfile in fc2
If CheckExt(FSO.GetExtensionName(path&"\"&myfile.name)) and (myfile.size<=maxfilesize) Then
Call ScanFile(Path&Temp&"\"&myfile.name, "")
SumFiles = SumFiles + 1
End If
Next
Set fc = f.SubFolders
For Each f1 in fc
ShowAllFile path&"\"&f1.name
SumFolders = SumFolders + 1
Next
Set FSO = Nothing
End Sub
'檢測文件
Sub ScanFile(FilePath, InFile)
If InFile <> "" Then
Infiles = "該文件被<a href=""http://"&Request.Servervariables("server_name")&"\"&InFile&""" target=_blank>"& InFile & "</a>文件包含執(zhí)行"
End If
Set FSOs = createObject("Scripting.FileSystemObject")
on error resume next
set ofile = fsos.OpenTextFile(FilePath)
filetxt = Lcase(ofile.readall())
If err Then Exit Sub end if
if len(filetxt)>0 then
'特征碼檢查
temp = "<a href=""http://"&Request.Servervariables("server_name")&"\"&replace(FilePath,server.MapPath("\")&"\","",1,1,1)&""" target=_blank>"&replace(FilePath,server.MapPath("\")&"\","",1,1,1)&"</a>"
'Check "WScr"&DoMyBest&"ipt.Shell"
If instr( filetxt, Lcase("WScr"&DoMyBest&"ipt.Shell") ) or Instr( filetxt, Lcase("clsid:72C24DD5-D70A"&DoMyBest&"-438B-8A42-98424B88AFB8") ) then
Report = Report&"<tr><td>"&temp&"</td><td>WScr"&DoMyBest&"ipt.Shell 或者 clsid:72C24DD5-D70A"&DoMyBest&"-438B-8A42-98424B88AFB8</td><td>危險(xiǎn)組件,一般被ASP木馬利用。"&infiles&"</td><td>"&GetDatecreate(filepath)&"<br>"&GetDatemodify(filepath)&"</td></tr>"
Sun = Sun + 1
End if
'Check "She"&DoMyBest&"ll.Application"
If instr( filetxt, Lcase("She"&DoMyBest&"ll.Application") ) or Instr( filetxt, Lcase("clsid:13709620-C27"&DoMyBest&"9-11CE-A49E-444553540000") ) then
Report = Report&"<tr><td>"&temp&"</td><td>She"&DoMyBest&"ll.Application 或者 clsid:13709620-C27"&DoMyBest&"9-11CE-A49E-444553540000</td><td>危險(xiǎn)組件,一般被ASP木馬利用。"&infiles&"</td><td>"&GetDatecreate(filepath)&"<br>"&GetDatemodify(filepath)&"</td></tr>"
Sun = Sun + 1
End If
'Check .Encode
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Global = True
regEx.Pattern = "@\s*LANGUAGE\s*=\s*[""]?\s*(vbscript|jscript|javascript).encode\b"
If regEx.Test(filetxt) Then
Report = Report&"<tr><td>"&temp&"</td><td>(vbscript|jscript|javascript).Encode</td><td>似乎腳本被加密了,一般ASP文件是不會(huì)加密的。"&infiles&"</td><td>"&GetDatecreate(filepath)&"<br>"&GetDatemodify(filepath)&"</td></tr>"
Sun = Sun + 1
End If
'Check my ASP backdoor :(
regEx.Pattern = "\bEv"&"al\b"
If regEx.Test(filetxt) Then
Report = Report&"<tr><td>"&temp&"</td><td>Ev"&"al</td><td>e"&"val()函數(shù)可以執(zhí)行任意ASP代碼,被一些后門利用。其形式一般是:ev"&"al(X)<br>但是javascript代碼中也可以使用,有可能是誤報(bào)。"&infiles&"</td><td>"&GetDatecreate(filepath)&"<br>"&GetDatemodify(filepath)&"</td></tr>"
Sun = Sun + 1
End If
'Check exe&cute backdoor
regEx.Pattern = "[^.]\bExe"&"cute\b"
If regEx.Test(filetxt) Then
Report = Report&"<tr><td>"&temp&"</td><td>Exec"&"ute</td><td>e"&"xecute()函數(shù)可以執(zhí)行任意ASP代碼,被一些后門利用。其形式一般是:ex"&"ecute(X)。<br>"&infiles&"</td><td>"&GetDatecreate(filepath)&"<br>"&GetDatemodify(filepath)&"</td></tr>"
Sun = Sun + 1
End If
Set regEx = Nothing
'檢查包含文件
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Global = True
regEx.Pattern = "<!--\s*#include\s*file\s*=\s*"".*"""
Set Matches = regEx.Execute(filetxt)
For Each Match in Matches
tFile = Replace(Mid(Match.Value, Instr(Match.Value, """") + 1, Len(Match.Value) - Instr(Match.Value, """") - 1),"/","\")
If Not CheckExt(FSOs.GetExtensionName(tFile)) Then
Call ScanFile( Mid(FilePath,1,InStrRev(FilePath,"\"))&tFile, replace(FilePath,server.MapPath("\")&"\","",1,1,1) )
SumFiles = SumFiles + 1
End If
Next
Set Matches = Nothing
Set regEx = Nothing
'檢查虛擬目錄
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Global = True
regEx.Pattern = "<!--\s*#include\s*virtual\s*=\s*"".*"""
Set Matches = regEx.Execute(filetxt)
For Each Match in Matches
tFile = Replace(Mid(Match.Value, Instr(Match.Value, """") + 1, Len(Match.Value) - Instr(Match.Value, """") - 1),"/","\")
If Not CheckExt(FSOs.GetExtensionName(tFile)) Then
Call ScanFile( Server.MapPath("\")&"\"&tFile, replace(FilePath,server.MapPath("\")&"\","",1,1,1) )
SumFiles = SumFiles + 1
End If
Next
Set Matches = Nothing
Set regEx = Nothing
'檢查特殊命令:Server&.Execute|Transfer
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Global = True
regEx.Pattern = "Server.(Exec"&"ute|Transfer)([ \t]*|\()"".*"""
Set Matches = regEx.Execute(filetxt)
For Each Match in Matches
tFile = Replace(Mid(Match.Value, Instr(Match.Value, """") + 1, Len(Match.Value) - Instr(Match.Value, """") - 1),"/","\")
If Not CheckExt(FSOs.GetExtensionName(tFile)) Then
Call ScanFile( Mid(FilePath,1,InStrRev(FilePath,"\"))&tFile, replace(FilePath,server.MapPath("\")&"\","",1,1,1) )
SumFiles = SumFiles + 1
End If
Next
Set Matches = Nothing
Set regEx = Nothing
'Check Server&.Execute|Transfer
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Global = True
regEx.Pattern = "Server.(Exec"&"ute|Transfer)([ \t]*|\()[^""]\)"
If regEx.Test(filetxt) Then
Report = Report&"<tr><td>"&temp&"</td><td>Server.Exec"&"ute</td><td>不能跟蹤檢查Server.e"&"xecute()函數(shù)執(zhí)行的文件。請(qǐng)管理員自行檢查。<br>"&infiles&"</td><td>"&GetDatecreate(filepath)&"<br>"&GetDatemodify(filepath)&"</td></tr>"
Sun = Sun + 1
End If
Set Matches = Nothing
Set regEx = Nothing
'檢查createobject命令 Crea"&"teObject
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Global = True
regEx.Pattern = "createO"&"bject[ |\t]*\(.*\)"
Set Matches = regEx.Execute(filetxt)
For Each Match in Matches
If Instr(Match.Value, "&") or Instr(Match.Value, "+") or Instr(Match.Value, """") = 0 or Instr(Match.Value, "(") <> InStrRev(Match.Value, "(") Then
Report = Report&"<tr><td>"&temp&"</td><td>Creat"&"eObject</td><td>Crea"&"teObject函數(shù)使用了變形技術(shù),仔細(xì)復(fù)查。"&infiles&"</td><td>"&GetDatecreate(filepath)&"<br>"&GetDatemodify(filepath)&"</td></tr>"
Sun = Sun + 1
exit sub
End If
Next
Set Matches = Nothing
Set regEx = Nothing
end if
set ofile = nothing
set fsos = nothing
End Sub
'檢查文件后綴,如果與預(yù)定的匹配即返回TRUE
Function CheckExt(FileExt)
If DimFileExt = "*" Then CheckExt = True
Ext = Split(DimFileExt,",")
For i = 0 To Ubound(Ext)
If Lcase(FileExt) = Ext(i) Then
CheckExt = True
Exit Function
End If
Next
End Function
Function GetDatemodify(filepath)
Set fso = createObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filepath)
s = f.DateLastModified
set f = nothing
set fso = nothing
GetDatemodify = s
End Function
Function GetDatecreate(filepath)
Set fso = createObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filepath)
s = f.Datecreated
set f = nothing
set fso = nothing
GetDatecreate = s
End Function
%>
【asp木馬探測器】-在線掃描探測檢查asp站點(diǎn)木馬后門的程序
可以在線掃描檢查探測站點(diǎn)內(nèi)的所有asp程序代碼,檢測代碼中是否含有危險(xiǎn)代碼
目前檢測的特征碼有:CreateObject、Execute、Shell.Application、WScript.Shell、Eval、include......等。
對(duì)程序的改進(jìn)是:增加擴(kuò)展名后綴列表自定義、掃描文件大小限制、掃描超時(shí)限制、session驗(yàn)證改復(fù)雜了一點(diǎn)點(diǎn)......
具體請(qǐng)自己打開原始代碼查看。
使用后,要么及時(shí)刪除,要么將登陸密碼改掉,盡量改復(fù)雜點(diǎn)。(雖然這個(gè)程序不會(huì)直接提供在線打開文件的功能,但仍然有可能被hacker利用)
準(zhǔn)備下一個(gè)修改版本加入檢查iframe特征碼的功能,目前太多站點(diǎn)都是被人掛了iframe,當(dāng)然,那只是表現(xiàn),具體漏洞根源還是在程序或其他方面。
點(diǎn)擊這里下載asp木馬探測器 [注意:解壓密碼和默認(rèn)登陸密碼都是www.pifoo.com]
原作者:雷客圖
jspadmin=阿笨狗=飛云 修改于2006.07.07
'獲取最新修改版本,請(qǐng)關(guān)注
相關(guān)文章
asp實(shí)現(xiàn)本周的一周時(shí)間列表的代碼
原理也相對(duì)簡單,就是利用date函數(shù)獲取日期,然后通過固定的字符串?dāng)?shù)組進(jìn)行替換。2009-02-02談動(dòng)態(tài)多行多列,循環(huán)行和列,輸出M行N列的ASP代碼
2008-03-03用ASP應(yīng)用程序?qū)崿F(xiàn)自己的UrlDeCode
URL編碼是指為了將信息通過URL進(jìn)行傳輸,所以必須將某些含有特殊意義的字符進(jìn)行替換的一種編碼方式,在asp中我們都知道有一個(gè)Server.URLEncode的函數(shù)可以完成這個(gè)功能。2006-08-08