Trustwave's 2024 Retail Report Series Highlights Alarming E-Commerce Threats and Growing Fraud Against Retailers. Learn More

Trustwave's 2024 Retail Report Series Highlights Alarming E-Commerce Threats and Growing Fraud Against Retailers. Learn More

Services
Managed Detection & Response

Eliminate active threats with 24/7 threat detection, investigation, and response.

Co-Managed SOC (SIEM)

Maximize your SIEM investment, stop alert fatigue, and enhance your team with hybrid security operations support.

Advisory & Diagnostics

Advance your cybersecurity program and get expert guidance where you need it most.

Penetration Testing

Test your physical locations and IT infrastructure to shore up weaknesses before exploitation.

Database Security

Prevent unauthorized access and exceed compliance requirements.

Email Security

Stop email threats others miss and secure your organization against the #1 ransomware attack vector.

Digital Forensics & Incident Response

Prepare for the inevitable with 24/7 global breach response in-region and available on-site.

Firewall & Technology Management

Mitigate risk of a cyberattack with 24/7 incident and health monitoring and the latest threat intelligence.

Solutions
BY TOPIC
Microsoft Security
Unlock the full power of Microsoft Security
Offensive Security
Solutions to maximize your security ROI
Rapidly Secure New Environments
Security for rapid response situations
Securing the Cloud
Safely navigate and stay protected
Securing the IoT Landscape
Test, monitor and secure network objects
Why Trustwave
About Us
Awards and Accolades
Trustwave SpiderLabs Team
Trustwave Fusion Security Operations Platform
Trustwave Security Colony
Partners
Technology Alliance Partners
Key alliances who align and support our ecosystem of security offerings
Trustwave PartnerOne Program
Join forces with Trustwave to protect against the most advance cybersecurity threats

CVE-2014-0050: Exploit with Boundaries, Loops without Boundaries

In this article I will discuss CVE-2014-0050: Apache Commons FileUpload and Apache Tomcat Denial-of-Service in detail. The article reviews the vulnerability's technical aspects in depth and includes recommendations that can help administrators defend from future exploitation of this security issue.

How do we know about this vulnerability?

About five days ago, Mark Thomas, a Project Management Committee Member and Committer in the Apache Tomcat project, sent an email about the accidentally leaked vulnerability (CVE-2014-0050) which allows attackers to take down your Tomcat-deployed web sites and web services. "This issue was reported responsibly to the Apache Software Foundation via JPCERT but an error in addressing an e-mail led to the unintended early disclosure of this issue," Thomas said in his email.

An hour prior to sending the email, Thomas populated the Apache Commons FileUpload project SVN with code fixes. The most significant difference I detected was in the "MultipartStream" class code of the package:

http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/MultipartStream.java?r1=1564788&r2=1565143&diff_format=h

12483_eb95960f-e1b4-4f18-b629-0ea3483bc300

The fixed code has an extra "if" condition (line number 330) that validates the length of the multipart boundary to be shorter than 4091 characters, raising an exception if that's not the case. The calculation is as follows:

boundary.length > bufSize – 1 – BOUNDARY_PREFIX.length = 4096 – 1 – 4 = 4091

Note: parts of the code were copied into the org.apache.tomcat.util.http.fileupload package in Apache Tomcat, causing it to be affected.

What is Multipart?

Multipart is often used in HTTP for the purpose of uploading files (more details can be found in RFC 2046). When your application needs to send a file to the server that has binary data, or data that might interfere with the structure of the HTTP message, it is possible to use a multipart content-type and setup a magic line to separate between values. This magic line is the boundary value and should be random enough that it doesn't appear in the actual content sent.

Note the complexity of the boundary value in the following example of a file upload request generated by Google Chrome. Such complexity reduces the chances of the boundary appearing in the binary blob of the file being uploaded, so the different parts of the message can be easily detected even by the human eye:

11764_c8b21f58-29a5-405d-ba38-4916520c5149

Creating the exploit

So let's get Apache Tomcat installed and try to send more than 4091 characters in the boundary field to the Apache Tomcat Manager application. Such a request might look like this:

12410_e8bb0ae6-59c6-481d-b823-77c01ccd3211

I submitted the above request four times (one for each CPU) and this was the result:

10123_7b10fadf-b3a9-46ea-8f97-26d035c61b37

The Tomcat process reached 100 percent CPU usage, and remained at levels higher than 95 percent CPU until I stopped the service.

Why is this happening?

When you are writing loops, check your boundaries. When you are writing endless loops, check your boundaries even more carefully.

While parsing the multipart message, the following "for" loop is used by the MultipartStream class:

11325_b33f0563-38aa-45d0-8909-2d7ddafe82a8

The innocent-looking "for" loop above is an endless loop. It is "family related" to the famous "while(true)" loop. The developer's intention was to exit this loop either by raising an exception (line 1003) or by returning a value (line 1014), unfortunately when the boundary is longer than 4091 characters (as explained earlier) and the body is longer than 4096 characters (so it can potentially contain the boundary), neither would ever occur.

The Irony

I have to say a few words about the Irony. We can safely say that this bug is all about a field read from the request which the programmer failed to validate its permitted boundaries. However, the field's name is Boundary.

How to tell if you are vulnerable?

1) You are using Apache Tomcat 7.0-7.0.50 or 8.0-8.0.1 and your code utilizes Servlet 3.0 specifications (for example, "request.getPart" or "request.getParts" methods)

2) You are using Apache Commons FileUpload < 1.3.1

To be honest, these libraries are so commonly used that you might not even know that your site is vulnerable.

I wrote a small Ruby proof-of-concept exploit to help administrators try and recreate the Denial-of-Service state on QA and staging environments. This can help administrators and developers understand if a certain URL is vulnerable to the attack (but needs to be tested on all URLs).

The tool can also assist white-hat security professionals that are required to confirm the vulnerability throughout an engagement.

Download CVE-2014-0050

 

Defend yourself

Trustwave Spiderlabs research team recommends taking the following actions:

A) Once available, update your software to one of the following versions:

    1. Apache Commons FileUpload 1.3.1
    2. Apache Tomcat 7.0.51
    3. Apache Tomcat 8.0.2

B) You may choose to apply the appropriate patch:

  1. Apache Commons FileUpload: http://svn.apache.org/r1565143
  2. Apache Tomcat 8: http://svn.apache.org/r1565163
  3. Apache Tomcat 7: http://svn.apache.org/r1565169

 

ModSecurity Commercial Rule Set

The ModSecurity commercial rule set was updated and protects against the attack.

 

WebDefend

It is possible to add the following user defined rule in block mode to detect and mitigate the attack:

SecRule REQUEST_HEADERS:Content-Type "@rx .{4000}"

For more information on how to create user-defined rules, please refer to http://blog.spiderlabs.com/2013/04/restricting-adobe-cq-admin-logins-with-trustwave-wafs.html

Note: Due to the low chances of a false detection (false positive) and the simplicity of the exploit, we highly recommend setting this rule to BLOCK and disabling simulation mode for this rule if you are concerned about Denial-of-Service (and suspect that your site is using one of the affected technologies).

ABOUT TRUSTWAVE

Trustwave is a globally recognized cybersecurity leader that reduces cyber risk and fortifies organizations against disruptive and damaging cyber threats. Our comprehensive offensive and defensive cybersecurity portfolio detects what others cannot, responds with greater speed and effectiveness, optimizes client investment, and improves security resilience. Learn more about us.

Latest Intelligence

Discover how our specialists can tailor a security program to fit the needs of
your organization.

Request a Demo