<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#Include File="cbfconn.asp"-->
<!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>木马检查工具</title>
</head>


<body>
<link href="admin/img/Style.Css" rel="stylesheet" type="text/css"><%
dim Report
if session("cbf001A_D_M_I_N")<>"" and session("cbfADM_n_id")<>"" then
%>

　<table border="1" width="100%" id="table1" style="border-width: 0px">
	<tr>
		<td style="border-style: none; border-width: medium" align="center">
<fieldset style="border:1px solid #C0C0C0; padding:2px; width:748px; height:100%">
	<legend>
			<span style="font-size: 9pt">&nbsp;<font color="#E1E1E1">■</font><font color="#C0C0C0">■</font></span><font color="#FFFFFF"><span style="background-color: #808080"><font style="font-size: 10pt">
			</font>
			<font style="font-size: 9pt">
			木马检查工具
			</font>
			</span>
			</font>
			<span style="font-size: 9pt"><font color="#C0C0C0">■</font><font color="#E1E1E1">■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■</font></span></legend><%

	if request.QueryString("act")<>"scan" then
%>	
				<form action="?act=scan" method="post">
				<table border="1" width="100%" id="table5" style="border-width: 0px">
					<tr>
						<td style="border-style: none; border-width: medium" width="25%" height="33">
						<p align="right"><span style="font-size: 9pt">填入你要检查的路径：&nbsp; </span>
						</td>
						<td style="border-style: none; border-width: medium" width="73%" height="33">
						<p align="left"><span style="font-size: 9pt">
				<input name="path" type="text" style="border:1px solid #999" value="." size="30" /></span></td>
					</tr>
					<tr>
						<td style="border-style: none; border-width: medium" colspan="2">
						<p align="left"><span style="font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * 
						网站根目录的相对路径，填“\”即检查整个网站；“.”为程序所在目录
				</span>
						</td>
					</tr>
					<tr>
						<td style="border-style: none; border-width: medium" colspan="2">　</td>
					</tr>
					<tr>
						<td style="border-style: none; border-width: medium" colspan="2">
						<p align="center">
				<input  onClick="{if(confirm('CBF001温馨提示：如果你的网站很大,那检查时需要花很长时间!')){this.document.forms.submit();return true;}return false;}" type="submit" value=" 开始扫描 " ></td>
					</tr>
				</table>
				<span style="font-size: 9pt">
				&nbsp;</span></form>
<%
	else
	
	
	ip = Request.ServerVariables("HTTP_X_FORWARDED_FOR" ) 
If ip = "" Then 
ip = Request.ServerVariables("REMOTE_ADDR" )
end if

admin_cbf001_txt_1="<div align='center'>　<table border='1' width='560' id='table5' style='border-collapse: collapse; border-right-width:0px; border-top-width:0px' cellpadding='0' bordercolor='#C0DAA7' cellspacing='0' height='195'><tr><td width='57%' height='11' style='border-left:1px solid #C0DAA7; border-right-style: none; border-right-width: medium' bgcolor='#C0DAA7' align='center'></td></tr><tr><td style='border-style:solid; border-width:1px; ' rowspan='2' align='center'><div align='center'><table border='1' width='71%' id='table6' style='border-width: 0px' cellspacing='0' cellpadding='0' height='5'><tr>"
admin_cbf001_txt_2="</td></tr></table></div></td></tr></table></div><div align='center'><table border='1' width='560' id='table7' style='border-width:0px; border-collapse: collapse' cellpadding='0' bordercolor='#C0DAA7' cellspacing='0' height='7'><tr><td width='86%' bgcolor='#C0DAA7' height='7' style='border-right-style: solid; border-right-width: 1px; border-bottom: 1px solid #C0DAA7' align='center'></td></tr></table></div>"
if session("后台权限管理101")<>"1" then
response.write""&admin_cbf001_txt_1&""
response.write"<td style='border-style: none; border-width: medium'><p align='center'>你没有<font color='#FF0000'><a href='/Security.asp'>木马检查工具</a></font>权限！因此你在使用时被系统拦截,如果你忘了管理员密码，请查看帮助教程里的管理员权限说明和增加管理员教程！请点击下返回到原来的网页↙</p>"
response.write"<p align='center'><a href=javascript:window.opener=null;history.back()><font color='#FF0000'><span style='text-decoration: none'>返回!</span></font></a>或登陆官方网站查看相当的问题!→<a target='_blank' href='http://cbf001.com/bbs'><font color='#008080'> 论坛</font></a>"
response.write""&admin_cbf001_txt_2&""
 
 '日志记录  
   count=""&session("cbfADM_n_id")&"</font>在使用<font color='#FF0000'><a href='/Security.asp'>木马检查工具</a></font></font></b>时因不够权限此操作被系统拦截!"
   set rsb=server.createobject("adodb.recordset")
   rsb.open "select * from admin_g_s",conn,1,3
   rsb.addnew
   rsb("admin_id")=session("cbfADM_n_id")
   rsb("goip")=ip
   rsb("count")=count
   rsb.update
   rsb.close    

response.end
end if 

		server.ScriptTimeout = 600
		DimFileExt = "asp,cer,asa,cdx"
		Sun = 0
		SumFiles = 0
		SumFolders = 1
		if request.Form("path")="" then
			response.Write("No Hack")
			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" id="table2">
  <tr>
    <td class="CPanel" style="padding:5px;line-height:170%;clear:both;font-size:12px" height="73">

扫描完毕！一共检查文件夹<font color="#FF0000"><%=SumFolders%></font>个，文件<font color="#FF0000"><%=SumFiles%></font>个，发现可疑点<font color="#FF0000"><%=Sun%></font>个
	<table width="100%" border="0" cellpadding="0" cellspacing="0" id="table3">
	 <tr>
		 <td valign="top">
			 <table width="100%" border="1" cellpadding="0" cellspacing="0" style="padding:5px;line-height:170%;clear:both;font-size:12px; border-collapse:collapse" id="table4" bordercolor="#808080">
			 <tr>
			   <td width="20%">文件相对路径</td>
			   <td width="20%">特征码</td>
			   <td width="40%">描述</td>
			   <td width="20%"创建/修改时间</td>
			   </tr>
		     <%=Report%>
			 <br/>
			 </table></td>
	 </tr>
	</table>
</td></tr></table>
<%
timer2 = timer
thetime=cstr(int(((timer2-timer1)*10000 )+0.5)/10)
response.write "<br><font style='font-size: 9pt'>本页执行共用了"&thetime&"毫秒</font>"
	end if


%>
<hr color="#CCCCCC" size="1">
<div align="center"><span style="font-size: 9pt">提示危险组件时,站长必须检查!如果属于没有必要的请删除!</span></div>
		</td>
	</tr>
</table>
</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)) 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>文件包含执行"
	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>危险组件，一般被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>危险组件，一般被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文件是不会加密的。"&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()函数可以执行任意ASP代码，被一些后门利用。其形式一般是：ev"&"al(X)<br>但是javascript代码中也可以使用，有可能是误报。"&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()函数可以执行任意ASP代码，被一些后门利用。其形式一般是：ex"&"ecute(X)。<br>"&infiles&"</td><td>"&GetDateCreate(filepath)&"<br>"&GetDateModify(filepath)&"</td></tr>"
				Sun = Sun + 1
			End If
			Set regEx = Nothing
			
		'Check include file
		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
		
		'Check include virtual
		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
		
		'Check 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()函数执行的文件。请管理员自行检查。<br>"&infiles&"</td><td>"&GetDateCreate(filepath)&"<br>"&GetDateModify(filepath)&"</td></tr>"
			Sun = Sun + 1
		End If
		Set Matches = Nothing
		Set regEx = Nothing
		
		'Check 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函数使用了变形技术，仔细复查。"&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

'检查文件后缀，如果与预定的匹配即返回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
response.end
end if
%>