Protecting Your Sites from Apache.Commons Vulnerabilities

Overview

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

A remote attacker can gain Remote Code Execution by sending 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 vulnerable depend 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 which receives Java Serialized Objects and uses the Apache.Common.Collections library. For example, Legacy web applications developed with 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 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 "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 configuration for their environment over in this blog post.

Trustwave reserves the right to review all comments in the discussion below. Please note that for security and other reasons, we may not approve comments containing links.