SpiderLabs Blog

Protecting Your Sites from Apache.Commons Vulnerabilities

Written by | Dec 21, 2015 9:06:00 AM

Overview

A few weeks ago, FoxGlove Security released this important blog post that includes several Proof-of-Concepts for exploiting Java unserialized vulnerabilities.

A remote attacker can gain Remote Code Execution by sending a specially crafted payload to any endpoint expecting a serialized Java object. In some cases, the attack may be executed from an unauthorized and unauthenticated host. Apache Foundation released this detailed description.

 

Which common application servers are vulnerable?

FoxGlove provides POC for attacks on the following servers:

  • WebSphere Application Server - CVE-2015-7450
  • Oracle WebLogic - CVE 2015-4852
  • JBoss Application Server - CVE-2015-7501
  • Jenkins CI - Continuous Integration and DevOps platform
  • OpenNMS - Open Source Network Management Software

As these are application frameworks, URLs are vulnerable depending on actual implementation. However, there are common endpoints that may be exposed. In JBOSS, invoker/JMXInvokerServlet may be exposed, which is a bad idea but not uncommon.

 

Which other applications are at risk?

Any custom Java application server that receives Java Serialized Objects and uses the Apache.Common.Collections library. For example, Legacy web applications developed with the JSF (Java Server Faces) Library. However, this vulnerability can possibly be exploited in Java applications which do not use Apache.Common.Collections. As quoted in the Apache Foundation blog:

"In these rather unfortunate situations, people have looked at the sample exploits. Frohoff provided "gadget chains" in sample payloads which combine classes from the Groovy runtime, Spring framework, or Apache Commons Collection. It is quite certain that you can combine more classes to exploit this weakness, but those are the chains readily available to attackers today."

We might be facing an evolving threat, based on using "gadget chains" from additional libraries. A recent update here lists possible vulnerabilities in many other libraries. This includes some common libraries: JSF 2.2, JasperReports, Apache Hadoop, OpenJPA, Apache Jena, Mule, Hadoop MapReduce, HBase and several others.

 

Known publicly available exploits

For JBoss Application Server - CVE-2015-7501 - there is already a publicly available exploit. There is also a publicly available Java tool that builds a payload to execute any command, as well as a public listing of vulnerable servers as detected by Shodan.

 

General Guidelines for mitigation

  • For In-House Java Applications, Update Apache commons-collection.
  • For the top known vulnerable apps listed in the FoxGlove post, apply vendor fixes as they become available.

 

Guidelines for ModSecurity supported customers

You can write a SecRule to protect known endpoints that receive Java Serialized Objects. For example, to protect endpoint "invoker/JmxInvoker, the rule could be written as follows:

SecRule REQUEST_LINE "@contains /invoker/JmxInvoker" "chain,phase:2,block,t:none,t:urlDecodeUni,capture, /

logdata:'%{matched_var}',severity:'9',id:999999,msg:'Apache-Commons', tag:'Apache-commons'"

SecRule REQUEST_BODY "@pmFromFile java_servuln.data"...

The relevant transformation should be used based on the location. For example, use  t:base64Decode when required. Java_servuln.data should include the following strings:

org/​apache/​commons/​collections/​Transformer

org.​apache.​commons.​collections.​Transformer

org.​apache.​commons.​collections.​functors.​InvokerTransformer

org/​apache/​commons/​collections4/​functors/​InvokerTransformer

org.​apache.​commons.​collections4.​functors.​InvokerTransformer

org/​codehaus/​groovy/​runtime/​ConvertedClosure

org.​codehaus.​groovy.​runtime.​ConvertedClosure

com/​sun/​org/​apache/​xalan/​internal/​xsltc/​trax/​TemplatesImpl

com.​sun.​org.​apache.​xalan.​internal.​xsltc.​trax.​TemplatesImpl

In practice, it is difficult to determine which URIs to protect. We recommend customers perform an architecture review to determine where Java Serialization is used, and perform some profiling for known good data sent to these URIs, to avoid False Positives. Note that as stated in the "Which other applications are at risk?" section, it is impossible to cover all possible cases as additional libraries may be vulnerable.

 

Additional detail - How to mitigate Oracle Weblogic 0-day CVE-2015-4852?

We have also received questions regarding this CVE. This relates to JAVA RMI (Remote Method Invocation) used by Oracle WebLogic for Java-To-Java communication (including with admin console) over T3 binary protocol, port 7001. The best mitigation is to block access to 7001 port on this server from external networks or unknown IP addresses. The method depends on the customer architecture, and can be achieved by either configuring your firewall or other networking equipment with proper access control rules. Users of Weblogic can read up on the configuration for their environment over in this blog post.