返回列表 回复 发帖

网马批量替换代码

是一个asp,上传后就可用了。比手动清除木马快多了,可自定义目录。
  1. <%
  2. Server.ScriptTimeOut = 999999999
  3. %>
  4. <script language = "JavaScript" type="text/javascript">
  5. function CheckForm(){
  6.   if (document.myform.Pathstr.value==''){
  7.     alert('请输入查找目录!');
  8.     document.myform.Pathstr.focus();
  9.     return false;
  10.   }
  11.   return true;  
  12. }
  13. </script>
  14. <table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>
  15.     <tr class='title'>
  16.         <td colspan='10'><Strong>文件内容在线批量替换</Strong></td></tr></table></td>
  17.     </tr>
  18. </table>
  19. <%
  20. Dim sAction,inum1,inum2,Pathstr1,thnum
  21. Dim strOld,strNew
  22.     strOld=trim(Request("strOld"))
  23.     strNew=trim(Request("strNew"))
  24.     thnum=trim(Request("thnum"))
  25.     if thnum="" then thnum=0
  26.     thnum=Clng(thnum)

  27.     inum1=0
  28.     inum2=0

  29. sAction=Trim(Request("Action"))
  30. if sAction="" then
  31.     Call step1()
  32. Elseif sAction="step1" then
  33.     Call step2()
  34. End if
  35. %>
  36. <br/>
  37. <%
  38. Sub step1()%>
  39. <form method="post" name="myform" onSubmit="return CheckForm();"  action="Replace.asp" target="_self">
  40. <table width='100%' border='0' align='center' cellpadding='2' cellspacing='1' class='border'>
  41.     <tr class='title'><td height='22' colspan='2' align='center'><strong>文件内容批量替换设置</strong></td></tr>
  42.     <tr class='tdbg'><td height='40' width=70 align='right'>查找目录:</td><td height='40'><input name="Pathstr" type="text" value="/HTML/" size="72">(请填写相对路径,如/HTML/Article/)<br/>
  43.     <Input name='searchtype' type='radio' id='searchtype' value='1' checked> 包含子目录
  44.     <Input name='searchtype' type='radio' id='searchtype' value='0'> 不包含子目录
  45.    
  46.     </td></tr>
  47.     <tr class='tdbg'><td height='40' align='right'>文件类型:</td><td height='40'><input name="FileType" type="text" value="txt|htm|html|shtml|asp|php|cgi" size="72">(要进行替换的文件后缀名,以|分隔,留空为不限)</td></tr>
  48.     <tr class='tdbg'><td height='40' align='right'>替换数量:</td><td height='40'><input name="thnum" type="text" value="" size="72"> 替换多少条数据,0或不填写为不限</td></tr>
  49.     <tr class='tdbg'><td height='40' align='right'>将 字 符:</td><td height='40'><textarea name="strOld" cols="60" rows="4"></textarea><font color=red> *</font></td></tr>
  50.     <tr class='tdbg'><td height='40' align='right'>替 换 成:</td><td height='40'><textarea name="strNew" cols="60" rows="4"></textarea></td></tr>
  51.     <tr class='tdbg'><td height='40' align='right'>注意事项:</td><td height='40'>    1、请备份您的原始文件。<br/>2、本操作的更新时间视您数据的多少以及服务器(或本地机器)的配置决定,如果数据很多,更新可能很慢,在这过程千万不能刷新页面或关闭浏览器,如果出现超时或者错误提示,请使用备份数据重新进行操作。</td></tr>
  52.     <tr class='tdbg'><td height='40' colspan='2' align='center'><input type='hidden' name='Action' value='step1'><input type="submit" name="Submit" value="开始替换"></td></tr>
  53. </table>
  54. </form>
  55. <%End Sub%>


  56. <%
  57. Sub step2()
  58.     Dim sFso,stheFolder,stheFile,Pathstr,SearchType
  59.     SearchType=Clng(trim(Request("SearchType")))
  60.     Pathstr=trim(Request("Pathstr"))
  61.     Pathstr1=Replace(Server.MapPath("/"),"\","/")
  62.     if SearchType=0 then
  63.         Call DoReplace(Server.MapPath(Pathstr),strOld,strNew)        
  64.     Else
  65.         bianli(Server.MapPath(Pathstr))
  66.     End if
  67.     Response.write "替换结束!本次共查找到"&inum1&"个文件,成功替换"&inum2&"个"

  68. End sub
  69. Sub DoReplace(Pathstr,strOld,strNew)
  70.     if inum1>=thnum and thnum>0 then Exit Sub
  71.     Pathstr=Replace(Pathstr,"\","/")
  72.     if right(Pathstr,1)<>"/" and right(Pathstr,1)<>"\" then Pathstr=Pathstr&"/"
  73.     Pathstr=Replace(Pathstr,"//","/")
  74.     dim c,theFile,theFolder,strFileType,fso,TruePath,FileType,FileType1,isTrue,i,InStream,Out,Out1,FileObject,Tempstr
  75.     Response.Flush()'刷新
  76.     FileType =trim(Request("FileType"))
  77.     if FileType<>"" then
  78.         FileType1=Split("|"&FileType&"|","|")
  79.         isTrue=False
  80.     Else
  81.         isTrue=True
  82.     End if
  83.     Set fso = Server.CreateObject("Scripting.FileSystemObject")
  84.     Set theFolder=fso.GetFolder(Pathstr)
  85.     For Each theFile In theFolder.Files
  86.         c=c+1
  87.         strFileType=lcase(mid(theFile.Name,instrrev(theFile.Name,".")+1))
  88.         if FileType<>"" then
  89.             isTrue=False
  90.             for i=0 to Ubound(FileType1)
  91.                 if Ucase(FileType1(i))=Ucase(strFileType) then isTrue=True
  92.             Next
  93.         Else
  94.             isTrue=True
  95.         End if
  96.         if isTrue=True Then
  97.             Response.write Replace("<li>正在查找第 <font color=red><Strong>"&inum1+1&"</Strong></font> 个文件:"&Pathstr&theFile.Name&" ",Pathstr1,"")
  98.         
  99.             Set FileObject=Server.CreateObject("Scripting.FileSystemObject")
  100.             Set Out=FileObject.OpenTextFile(Pathstr&theFile.Name,1,FALSE,FALSE)
  101.                 tempstr= Out.readall
  102.             Out.Close
  103.             if  instr(tempstr,strOld)<>0 then
  104.                 Set Out1=FileObject.CreateTextFile(Pathstr&theFile.Name,True,FALSE)
  105.                     Out1.Write(Replace(tempstr,strOld,strNew))
  106.                 Out1.Close
  107.                 Response.write "<font color=green>替换成功!</font>"
  108.                 inum2=inum2+1
  109.             'Else
  110.                 'Response.write "<font color=black>无匹配内容!</font>"
  111.             End if
  112.             Response.write "</li><br/>"
  113.             '………………………………………………
  114.             If Response.IsClientConnected Then
  115.                 Response.Flush
  116.             Else
  117.                 Response.End
  118.             End If
  119.             '………………………………………………
  120.             inum1=inum1+1
  121.             if inum1>=thnum and thnum>0 then Exit For
  122.         end if
  123.     Next

  124. End sub

  125. function bianli(path)
  126.     Dim fso,objFolder,objSubFolders,objSubFolder,nowpath
  127.         Call DoReplace(path,strOld,strNew)
  128.         set fso=server.CreateObject("scripting.filesystemobject")     
  129.         on error resume next
  130.         set objFolder=fso.GetFolder(path)
  131.         set objSubFolders=objFolder.Subfolders
  132.         for each objSubFolder in objSubFolders
  133.             nowpath=path + "/" + objSubFolder.name
  134.             Call DoReplace(nowpath,strOld,strNew)
  135.             bianli(nowpath)'递归
  136.         next
  137.         set objFolder=nothing
  138.         set objSubFolders=nothing
  139.         set fso=nothing
  140. end function

  141. %>
复制代码
返回列表