Skip to content
XXE Write-up Advanced

Analysis Environment

The EJBTaglibDescriptor class in WebLogic parses XML during deserialisation, so a crafted serialised object could trigger an XML external entity (XXE) attack. An attacker could make the server fetch external entities, reading local files and sending their contents to a server the attacker controls.

medium.com

Published on medium.com

This vulnerability is similar to several XXE vulnerabilities submitted by @Matthias Kaiser before, and EJBTaglibDescriptor should be the one that he missed. You can refer to the previous XXE analysis.

Knownsec 404 team, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

WebLogic's EJB-to-JSP support ships a deployment descriptor class, EJBTaglibDescriptor, that is serialisable and is deserialised by the server. The class lives at weblogic.jar!\weblogic\servlet\ejb2jsp\dd\EJBTaglibDescriptor.class and inherits from java\io\Externalizable, so its own writeExternal and readExternal methods run automatically whenever an instance is serialised or deserialised.

This is the same family of bugs as several XXE issues that @Matthias Kaiser had submitted against WebLogic before; EJBTaglibDescriptor is the class he missed. The author, Longofo of the Knownsec 404 Team, and @Badcode decompiled all the WebLogic JAR packages and searched for classes matching the characteristics of the earlier XXE findings, which is how this class was found: it parses XML during deserialisation. Oracle released the October 2019 Critical Patch Update.

Setup

The analysis and reproduction were done on:

  • Windows 10
  • WebLogic 10.3.6.0.190716, with the July 2019 patch installed
  • Jdk160_29, the JDK bundled with WebLogic 10.3.6.0.190716

The tools were a decompiler for the WebLogic JARs, and an HTTP server plus an FTP server under the researcher's control to receive the out-of-band requests.

Finding it

The starting point is the class hierarchy. Because EJBTaglibDescriptor implements Externalizable, the subclass's writeExternal and readExternal are invoked automatically during serialisation and deserialisation.

From the original on medium.com

Looking at readExternal, the code calls ObjectIutput.readUTF to read a String from the deserialised data and then calls the load method with it.

From the original on medium.com

Inside load, the string is parsed with DocumentBuilder.parse. That is the suspicious point: XML supplied inside attacker-controlled serialised data is handed to a parser, which is the classic shape of an XXE vulnerability.

On the writing side, writeExternal calls the object's own toString, which in turn calls its own toXML method.

From the original on medium.com

toXML converts this.beans into the corresponding XML data. Building a payload through the normal serialisation path is awkward, because the XML has to come out of the bean structure. The serialisation operation, however, is under the attacker's control, so the simplest route is to modify the logic of writeExternal directly and generate the malicious serialised data from there.

From the original on medium.com

Exploitation

Step 1: rewrite writeExternal to generate the payload

The researcher rewrote the writeExternal function in EJBTaglibDescriptor so that serialising the object emits the malicious data instead of the legitimate bean XML.

From the original on medium.com

Step 2: send the payload to the server

The generated serialised object was sent to the WebLogic server.

From the original on medium.com

The HTTP server and the FTP server under the researcher's control both received requests: an my.dtd request and win.ini data.

From the original on medium.com

The HTTP server received the my.dtd request and the FTP server received win.ini data.

Step 3: observe the server response

The server, running the latest patch available at the time (July), returned an error message.

From the original on medium.com

Root cause

readExternal takes a String straight out of the deserialised stream with ObjectIutput.readUTF and passes it to load, which parses it with DocumentBuilder.parse. The string is parsed with DocumentBuilder.parse, so there may be an XXE vulnerability here.

Impact

An attacker who can deliver a crafted serialised EJBTaglibDescriptor to the server can make it issue requests to arbitrary hosts, as demonstrated by the my.dtd fetch, and can read local files whose contents are then sent out over a second channel, as demonstrated by win.ini arriving on the FTP server. The impact is therefore file disclosure and out-of-band interaction, as demonstrated by the my.dtd request and the win.ini data.

Fix

Oracle addressed the issue in the October 2019 Critical Patch Update. The report does not describe the code change itself.

Variants to test

The technique generalises to any Externalizable or Serializable class in a product's JARs that parses XML during deserialisation:

  1. Decompile the shipped JARs and grep for DocumentBuilder, SAXParser, XMLReader, SAXReader and similar parser construction inside classes that implement Externalizable or define readObject.
  2. For each hit, check whether the parsed input comes from the stream (for example readUTF, readObject, byte arrays) rather than from a trusted local resource. A positive result is a class whose readExternal or readObject feeds stream data into a parser.
  3. Build a serialised instance with a rewritten writeExternal (or a crafted stream) containing a DOCTYPE with an external entity, and point the entity at a listener you control. A positive result is an HTTP request for your DTD arriving at that listener.
  4. Chain the DTD to a file:// entity and an exfiltration channel such as FTP. A positive result is the target file's content appearing on your server.
  5. Repeat against the latest patch level: the July-patched server here returned an error message, so an error response alone does not prove the parser is safe.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 9 min read.

What happened, in plain words

A security researcher found a way to make a Java application server called WebLogic read files and make network requests. The trick relies on a feature of the server that turns serialised Java objects back into live objects, and on a class inside WebLogic that parses XML text during that process. XML is a text format for structured data, a bit like a very strict form with opening and closing tags. When a parser (the program that reads XML) is allowed to fetch extra pieces of a document from other places, an attacker can point those pieces at files on the server or at servers they control. That class of bug is called XXE, short for XML External Entity.

The researcher, Longofo of the Knownsec 404 Team, worked with @Badcode. They decompiled every JAR package shipped with WebLogic. A JAR is a zip file full of compiled Java code; decompiling means turning that compiled code back into readable source code. They searched the decompiled code for classes that looked like several earlier XXE bugs reported by @Matthias Kaiser, and found one he had missed: EJBTaglibDescriptor. Oracle released the October 2019 patch set, called a Critical Patch Update (CPU).

Background you need first

A few ideas come up again and again, so here they are from scratch.

Java and classes. Java is a programming language. A class is a blueprint for an object, and an object is a live thing built from that blueprint, holding data and code. WebLogic is a Java application server: a program that runs other people's web applications for them.

Serialisation. When Java wants to save an object to disk or send it over a network, it can turn it into a stream of bytes. That is serialisation. Turning the bytes back into a working object is deserialisation. Think of it like packing furniture flat for shipping and reassembling it at the other end. If an attacker can supply the flat-pack box, they control what gets reassembled.

Externalizable. Java has a standard interface (a contract a class can sign up to) called Externalizable. A class that implements it promises to provide two methods, writeExternal and readExternal, and Java calls them automatically when the object is serialised or deserialised. The class does not get a choice: the methods run as part of the process.

XML and parsers. XML looks like <name>value</name>. A parser reads that text and builds a structured document from it. XML has a feature called a Document Type Definition (DTD), declared with <!DOCTYPE ...>, which can define entities. An entity is a named placeholder that gets replaced by other content when the document is parsed. If an entity points at a URL, the parser fetches that URL. That is useful for sharing common definitions, and dangerous when the XML comes from an attacker.

XXE. XML External Entity is the bug where an attacker supplies XML whose DTD defines an entity pointing at a file (file:///...) or at a server they control. The parser fetches it and substitutes the content. If the substituted content is then sent somewhere the attacker can see, the file has been stolen. A common trick is to have the first fetch pull in a DTD from the attacker's server, and that DTD defines a second entity that reads a local file and sends it out over FTP. FTP is an old file transfer protocol; here it is simply a second network channel the attacker can watch.

Out-of-band. When the attacker does not see the server's response directly, they watch a server they control for incoming connections. Those connections are the out-of-band signal that the attack worked.

Patch and CPU. A patch is an update that fixes bugs. Oracle ships security fixes in scheduled bundles called Critical Patch Updates. A server at a given patch level has all fixes released up to that point.

The setup

The analysis and the reproduction were done on:

  • Windows 10
  • WebLogic 10.3.6.0.190716, with the July 2019 patch installed
  • Jdk160_29, the JDK bundled with WebLogic 10.3.6.0.190716

A JDK is the Java Development Kit, the set of tools for writing and compiling Java code. The tools used were a decompiler for the WebLogic JARs, and an HTTP server plus an FTP server under the researcher's control to receive the out-of-band requests. An HTTP server is the kind of program that serves web pages; here it is used purely to log incoming requests.

Finding the bug

The starting point is the class hierarchy, meaning which class inherits behaviour from which other class. EJBTaglibDescriptor lives at weblogic.jar!\weblogic\servlet\ejb2jsp\dd\EJBTaglibDescriptor.class and inherits from java\io\Externalizable. Because of that, the subclass's writeExternal and readExternal are invoked automatically during serialisation and deserialisation.

From the original on medium.com

The image shows the class declaration, where the inheritance from Externalizable is visible.

Looking at readExternal, the code calls ObjectIutput.readUTF to read a String from the deserialised data and then calls the load method with it. readUTF reads a piece of text out of the byte stream; the name in the report is spelled ObjectIutput, with the letters transposed, exactly as it appears in the decompiled code.

From the original on medium.com

The images show the logic of writeExternal and readExternal, and then the readExternal body where the string is read and passed to load.

Inside load, the string is parsed with DocumentBuilder.parse. That is the suspicious point: XML supplied inside attacker-controlled serialised data is handed to a parser, which is the classic shape of an XXE vulnerability. DocumentBuilder is Java's standard XML parser class, and parse is the method that reads the XML text.

On the writing side, writeExternal calls the object's own toString, which in turn calls its own toXML method.

From the original on medium.com

toXML converts this.beans into the corresponding XML data. Building a payload through the normal serialisation path is awkward, because the XML has to come out of the bean structure. A payload is the malicious input an attacker sends. The serialisation operation, however, is under the attacker's control, so the simplest route is to modify the logic of writeExternal directly and generate the malicious serialised data from there.

From the original on medium.com

Exploitation

Step 1: rewrite writeExternal to generate the payload

The researcher rewrote the writeExternal function in EJBTaglibDescriptor so that serialising the object emits the malicious data instead of the legitimate bean XML. The reason for doing this rather than hand-crafting bytes is that the normal path would require building a bean structure whose toXML output happens to be the malicious XML. Rewriting the method skips that work: the attacker controls the code that produces the bytes, so the bytes can be anything.

From the original on medium.com

Step 2: send the payload to the server

The generated serialised object was sent to the WebLogic server.

From the original on medium.com

The HTTP server and the FTP server under the researcher's control both received requests: an my.dtd request and win.ini data.

From the original on medium.com

The HTTP server received the my.dtd request and the FTP server received win.ini data. win.ini is a configuration file that exists on Windows systems. Exfiltration means getting data out of the target and into the attacker's hands.

Step 3: observe the server response

The server, running the latest patch available at the time (July), returned an error message.

From the original on medium.com

An error message is not proof that the parser is safe. The out-of-band requests in step 2 are the proof that the parser processed the payload; the error is just what the server said afterwards.

Root cause

readExternal takes a String straight out of the deserialised stream with ObjectIutput.readUTF and passes it to load, which parses it with DocumentBuilder.parse. The string is parsed with DocumentBuilder.parse, so there may be an XXE vulnerability here.

Impact

An attacker who can deliver a crafted serialised EJBTaglibDescriptor to the server can make it issue requests to arbitrary hosts, as demonstrated by the my.dtd fetch, and can read local files whose contents are then sent out over a second channel, as demonstrated by win.ini arriving on the FTP server. The impact is therefore file disclosure and out-of-band interaction, as demonstrated by the my.dtd request and the win.ini data.

Fix

Oracle addressed the issue in the October 2019 Critical Patch Update. The report does not describe the code change itself.

Variants to test

The technique generalises to any Externalizable or Serializable class in a product's JARs that parses XML during deserialisation. Serializable is the other standard Java contract for serialisation; it uses a method called readObject instead of readExternal.

  1. Decompile the shipped JARs and grep for DocumentBuilder, SAXParser, XMLReader, SAXReader and similar parser construction inside classes that implement Externalizable or define readObject. Grep means searching text for a pattern.
  2. For each hit, check whether the parsed input comes from the stream (for example readUTF, readObject, byte arrays) rather than from a trusted local resource. A positive result is a class whose readExternal or readObject feeds stream data into a parser.
  3. Build a serialised instance with a rewritten writeExternal (or a crafted stream) containing a DOCTYPE with an external entity, and point the entity at a listener you control. A positive result is an HTTP request for your DTD arriving at that listener.
  4. Chain the DTD to a file:// entity and an exfiltration channel such as FTP. A positive result is the target file's content appearing on your server.
  5. Repeat against the latest patch level: the July-patched server here returned an error message, so an error response alone does not prove the parser is safe.

Glossary

  • API: a defined way for one program to ask another program to do something, like a menu of allowed requests.
  • Bean: a Java object that holds data and follows certain naming conventions; here, the data that toXML turns into XML.
  • Class: a blueprint in Java that describes what an object holds and what it can do.
  • CPU (Critical Patch Update): Oracle's scheduled bundle of security fixes, released on a fixed calendar.
  • Decompile: turn compiled program code back into readable source code.
  • Deserialisation: turning a stream of bytes back into a live object.
  • DTD (Document Type Definition): the part of an XML document that defines entities and structure, declared with <!DOCTYPE ...>.
  • Entity: a named placeholder in XML that the parser replaces with other content, which may be fetched from a URL.
  • Exfiltration: getting data out of a target system and into the attacker's hands.
  • Externalizable: a Java interface whose writeExternal and readExternal methods are called automatically during serialisation and deserialisation.
  • FTP: an old protocol for transferring files between computers; here used as a second channel to receive stolen data.
  • HTTP server: a program that answers web requests; here used to log requests the target makes.
  • Interface: a contract in Java that a class can sign up to, promising to provide certain methods.
  • JAR: a zip archive containing compiled Java code and resources.
  • JDK (Java Development Kit): the tools for writing and compiling Java code.
  • JVM: the Java Virtual Machine, the program that runs compiled Java code.
  • Out-of-band: observing an attack's effect through a separate channel, such as a server the attacker controls, rather than through the direct response.
  • Parser: a program that reads structured text, such as XML, and builds a document from it.
  • Patch: an update that fixes bugs in software.
  • Payload: the malicious input an attacker sends to trigger a bug.
  • readObject: the method Java calls during deserialisation of a Serializable class.
  • Serialisation: turning a live object into a stream of bytes for storage or transport.
  • Serializable: a Java interface that marks a class as serialisable using Java's default mechanism.
  • String: a piece of text in Java.
  • WebLogic: Oracle's Java application server, which runs web applications.
  • XML: a text format for structured data using opening and closing tags.
  • XXE (XML External Entity): a vulnerability where attacker-supplied XML causes the parser to fetch external entities, leading to file disclosure or requests to arbitrary hosts.

Similar reports

View all

Same bug class and techniques, clearest first.

XML external entities (XXE)

The lesson behind this report.

An XML parser resolves entities the attacker defines, reading local files or making the server send requests.