ApereoCAS 4.1.x ~ 4.1.6中,数据传输过程使用硬编码加解密,并在服务端进行反序列化操作,导致漏洞

而4.1.6以上版本的密钥为手动配置或随机生成,如果能读到tomcat启动目录下的cas日志或/WEB-INF/cas.properties也可拿到密钥进行反序列化,差别最多只是加密过程不同而已

分析

根据web.xml找到相应的Servlet,在org.springframework.web.servlet.FrameworkServlet

跟进this.processRequest(,将我们的request传入到了this.doService(

继续跟,在org.springframework.web.servlet.DispatcherServlet

程序对request进行了一点处理然后进入this.doDispatch(

request进入到ha.handle(中,跟进org.springframework.webflow.mvc.servlet.FlowHandlerAdapter

程序从request当中获取了flowExecutionKey,也就是我们传入的execution参数,接着将其传入this.flowExecutor.resumeExecution(,跟进org.springframework.webflow.executor.FlowExecutorImpl

flowExecutionKey先被传入了this.executionRepository.parseFlowExecutionKe(当中进行合法性的校检,满足类似0-0-0-0-0_[base64]即可进入到后面的this.executionRepository.getFlowExecution(,在org.jasig.spring.webflow.plugin.ClientFlowExecutionRepository

这里取出base64数据,然后传入this.transcoder.decode(,在org.jasig.spring.webflow.plugin.EncryptedTranscoder

可以看到数据经过解码后,最终进入了反序列化的入口。这里我们关注下解密方式this.cipherBean.decrypt(

从上面代码大致可以看到加解密用的是org.cryptacular.bean.BufferedBlockCipherBean类,该类为对称加密,且这里密钥是直接硬编码的spring-webflow-client-repo-1.0.0.jar!\etc\keystore.jceks

利用

ApereoCAS 4.1.x ~ 4.1.6中自带有commons-collections4-4.0.jar,利用cc链构造恶意类,再利用org.jasig.spring.webflow.plugin.EncryptedTranscoder中的encode(Object o)加密然后base64编码下即可

另外这篇文章中提到可利用其中的一个静态方法获取到HttpServletRequest和HttpServletResponse,用于命令回显

1
2
3
ExternalContext ec = org.springframework.webflow.context.ExternalContextHolder.getExternalContext();
HttpServletRequest request = (HttpServletRequest) ec.getNativeRequest();
HttpServletResponse response = (HttpServletResponse) ec.getNativeResponse();

复现

替换payload,注意进行url编码

Reference

https://mvnrepository.com/artifact/org.jasig.cas/cas-server-webapp
https://www.anquanke.com/post/id/198842
http://www.00theway.org/2020/01/04/apereo-cas-rce/