报告编号:B6-2020-092902
报告来源:360CERT
报告作者:360CERT
更新日期:2020-09-29
0x01 漏洞简述
2020年09月29日, 360CERT对Apache ofbiz组件的反序列化漏洞进行了分析,该漏洞编号为 CVE-2020-9496,漏洞等级:高危,漏洞评分:8.0。
Apache ofbiz 存在 反序列化漏洞,攻击者 通过 访问未授权接口,构造特定的xmlrpc http请求,可以造成 远程代码执行的影响。
0x02 风险等级
360CERT对该漏洞的评定结果如下
| 评定方式 | 等级 | 
|---|---|
| 威胁等级 | 高危 | 
| 影响面 | 一般 | 
| 360CERT评分 | 8.0分 | 
0x03 影响版本
- Apache Ofbiz:
0x04 漏洞详情
XML-RPC
XML-RPC是一种远程过程调用(RPC)协议,它使用XML对其调用进行编码,并使用HTTP作为传输机制。它是一种规范和一组实现,允许软件运行在不同的操作系统上,运行在不同的环境中,通过Internet进行过程调用。在XML-RPC中,客户端通过向实现XML-RPC并接收HTTP响应的服务器发送HTTP请求来执行RPC。
Demo
客户端
package org.apache.xmlrpc.demo.client;
import java.net.URL;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.apache.xmlrpc.client.XmlRpcSunHttpTransportFactory;
public class Client {
    public static void main(String[] args) throws Exception {
        // 创建客户端实例
        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        config.setServerURL(new URL("http://127.0.0.1:8081/xmlrpc"));
        XmlRpcClient client = new XmlRpcClient();
        client.setConfig(config);
        // 设置传输工厂类
        client.setTransportFactory(new XmlRpcSunHttpTransportFactory(client));
        // 创建远程方法的参数数组,通过指定远程方法名称进行调用
        Object[] params = new Object[]{new Integer(33), new Integer(9)};
        Integer result = (Integer) client.execute("Calculator.add", params);
        System.out.println(result);
    }
}
或者客户端使用动态代理的方式,通过ClientFactory,需要客户端和服务端都要有Adder的接口,具体实现类在服务端。
但要使用XML-RPC的动态代理功能,相应的服务器端的处理器类名称必须是Client端接口类的全名(含包名,该名称一般应该与Server端接口类全名一致),否则将会导致调用失败。
public class Client_Proxy {
    public static void main(String[] args) throws MalformedURLException {
        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        config.setServerURL(new URL("http://127.0.0.1:8081/xmlrpc"));
        XmlRpcClient client = new XmlRpcClient();
        client.setConfig(config);
        ClientFactory factory = new ClientFactory(client);
        Adder adder = (Adder) factory.newInstance(Adder.class);
        int sum = adder.add(2, 4);
        System.out.println(sum);
    }
}
Adder接口
package org.apache.xmlrpc.demo.proxy;
public interface Adder {
    public int add(int pNum1, int pNum2);
}
服务端
package org.apache.xmlrpc.demo.webserver;
import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcServer;
import org.apache.xmlrpc.server.XmlRpcServerConfigImpl;
import org.apache.xmlrpc.webserver.WebServer;
public class Server {
    private static final int port = 8081;
    public static void main(String[] args) throws Exception {
        WebServer webServer = new WebServer(port);
        XmlRpcServer xmlRpcServer = webServer.getXmlRpcServer();
        PropertyHandlerMapping phm = new PropertyHandlerMapping();
        /* Load handler definitions from a property file.
         * The property file might look like:
         *   Calculator=org.apache.xmlrpc.demo.Calculator
         *   org.apache.xmlrpc.demo.proxy.Adder=org.apache.xmlrpc.demo.proxy.AdderImpl
         */
        phm.load(Thread.currentThread().getContextClassLoader(),
                "MyHandlers.properties");
        /* You may also provide the handler classes directly,
         * like this:
         * phm.addHandler("Calculator",
         *     org.apache.xmlrpc.demo.Calculator.class);
         * phm.addHandler(org.apache.xmlrpc.demo.proxy.Adder.class.getName(),
         *     org.apache.xmlrpc.demo.proxy.AdderImpl.class);
         */
        phm.addHandler("Calculator",
                     org.apache.xmlrpc.demo.Calculator.class);
        xmlRpcServer.setHandlerMapping(phm);
        XmlRpcServerConfigImpl serverConfig =
                (XmlRpcServerConfigImpl) xmlRpcServer.getConfig();
        serverConfig.setEnabledForExtensions(true);
        serverConfig.setContentLengthOptional(false);
        webServer.start();
    }
}
服务端调用类
package org.apache.xmlrpc.demo;
public class Calculator {
    public int add(int i1, int i2) {
        return i1 + i2;
    }
    public int subtract(int i1, int i2) {
        return i1 - i2;
    }
}
在服务端还需要创建一个MyHandlers.properties。
启动服务端之后,运行客户端。

抓取流量。动态代理和普通的流量都是一样的。

客户端向/xmlrpc发了一个POST请求,请求的内容为:
>
    >Calculator.add 
    >>
    >
        >33 
     
    >
    >
        >9 
     
     
 
每个XML-RPC请求都以XML元素元素。 param XML元素可以包含许多数据类型。
服务端响应的内容为
 xmlns:ex="http://ws.apache.org/xmlrpc/namespaces/extensions">
    >>
    >
        >42 
     
     
 
初始化RequestHandler
注:`ofbiz 17.12.03`版本的`commons-beanutils`依赖版本是`1.9.3`
在第一次加载ControlServlet的时候,会调用init进行初始化,此时会通过getRequestHandler来初始化RequestHandler。

调用getControllerConfigURL方法,

该方法从配置文件/WEB-INF/controller.xml中获取定义好的请求映射的列表,这里会遍历所有webapp的controller.xml配置文件。

其中,定义xmlrpc的配置,没有设置对应的auth选项,默认为false,不需要身份验证,这也是之后修复的一个点。
 uri="xmlrpc" track-serverhit="false" track-visit="false">
         https="false"/>
         type="xmlrpc"/>
         name="error" type="none"/>
         name="success" type="none"/>
         
官方文档给出的配置文件的tag:

然后实例化ViewFactory和EventFactory。

先看实例化ViewFactory,会根据配置文件里的type是view属性中对应的值,遍历出所需要的Viewerhandler,并且进行init初始化。然后存入map。

webtools下的配置文件就存在9中type。

接着实例化EventFactory,同样遍历出
 

