Skip to content
RCE Write-up Advanced

CVE-2020-2551: Unauthenticated Remote Code Execution in IIOP protocol via Malicious JNDI Lookup

The IIOP protocol in WebLogic deserialises untrusted data, allowing an attacker to trigger a JNDI lookup to a malicious server. This could lead to remote code execution if the target JDK version permits loading remote codebases.

medium.com

Published on medium.com

According to the advisory, this bug is triggered via the processing of IIOP protocol. Therefore, thanks to some preliminary analyses (listed below under References), the PoC is easy to build and the RCE is pretty straightforward.

Boik Su, 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. 5 min read.

Context

CVE-2020-2551 is a remote code execution bug in Oracle WebLogic Server that is triggered through the processing of the IIOP protocol. The advisory describes the RCE as being achieved via a malicious JNDI lookup. The write-up notes that the PoC is easy to build once the protocol path is understood.

To explain why the bug works, the write-up first walks through the distributed-object technologies involved: RMI, CORBA, IIOP and RMI-IIOP.

RMI

Remote Method Invocation has existed since JDK 1.1. It lets a developer invoke a method on a remote server as though the object were local. Both sides have to fulfil some prerequisites for this to work.

Taken from http://blog.neoit.my/java/java-rmi-simple-server-example-using-terminal/ From the original on medium.com

CORBA

Common Object Request Broker Architecture is a standard defined by the Object Management Group (OMG), designed to let systems deployed on diverse platforms communicate. CORBA uses an interface definition language (IDL) to specify the interfaces an object presents to the outside world, and then specifies a mapping from IDL to a concrete implementation language such as C++ or Java.

IIOP

IIOP is CORBA's communication protocol, using TCP/IP as the transport. It specifies a standard for client and server communication.

RMI-IIOP

Java programmers previously had to choose between RMI and CORBA/IIOP (Java IDL) for distributed programming. RMI-IIOP combines the ease of use of RMI style with CORBA's cross-language interoperability.

This figure shows the relationships for objects that use IIOP between a client and WebLogic Server From the original on medium.com

Setup

The write-up does not describe a lab build, target version, account or tooling beyond the PoC itself. The exploit path runs through the weblogic.jndi.WLInitialContextFactory context factory. The payload's behaviour depends heavily on the JDK or WebLogic version running on the target, which is covered under the JDK version question below.

Finding it

The entry point is the Context Factory. It is the key to initiating a normal IIOP request that carries adversarial data and so triggers the bug. Following the initialisation of this factory all the way down shows that it does almost the same things as using the CORBA library directly.

From the original on medium.com
Follow all the way down…
Just like how the CORBA initiates the ORB and gets the ref of Naming Service

That gives a way to trigger the vulnerability. The second half of the chain is com.bea.core.repackaged.springframework.transaction.jta.JtaTransactionManager. The advisory says the RCE is achieved via a malicious JNDI lookup, and this class is what performs it: JtaTransactionManager played the role of the JNDI Injection trigger in CVE-2018-3191, and it is used again here because WebLogic does not blacklist it.

Exploitation

Step 1: the deserialisation stack

The stack frame recorded during the deserialisation process shows how the IIOP input reaches the JNDI lookup:

Text
lookupUserTransaction:565, JtaTransactionManager (com.bea.core.repackaged.springframework.transaction.jta)initUserTransactionAndTransactionManager:444, JtaTransactionManager (com.bea.core.repackaged.springframework.transaction.jta)readObject:1198, JtaTransactionManager (com.bea.core.repackaged.springframework.transaction.jta) <-- JtaTransactionManager#readObjectinvoke0:-1, NativeMethodAccessorImpl (sun.reflect)invoke:62, NativeMethodAccessorImpl (sun.reflect)invoke:43, DelegatingMethodAccessorImpl (sun.reflect)invoke:498, Method (java.lang.reflect)readObject:314, ObjectStreamClass (weblogic.utils.io) <-- ObjectStreamClass#readObjectreadValueData:281, ValueHandlerImpl (weblogic.corba.utils)readValue:93, ValueHandlerImpl (weblogic.corba.utils)read_value:2128, IIOPInputStream (weblogic.iiop) <-- JtaTransactionManagerread_value:1936, IIOPInputStream (weblogic.iiop)...readValue:93, ValueHandlerImpl (weblogic.corba.utils)read_value:2128, IIOPInputStream (weblogic.iiop) <-- Proxyread_value:1936, IIOPInputStream (weblogic.iiop)read_value_internal:220, AnyImpl (weblogic.corba.idl)read_value:115, AnyImpl (weblogic.corba.idl)read_any:1648, IIOPInputStream (weblogic.iiop) <-- bind_any()read_any:1641, IIOPInputStream (weblogic.iiop)_invoke:58, _NamingContextAnyImplBase (weblogic.corba.cos.naming)invoke:249, CorbaServerRef (weblogic.corba.idl)invoke:230, ClusterableServerRef (weblogic.rmi.cluster)run:522, BasicServerRef$1 (weblogic.[redacted])doAs:363, AuthenticatedSubject (weblogic.security.[redacted])runAs:146, SecurityManager (weblogic.security.service)handleRequest:518, BasicServerRef (weblogic.[redacted])...

Read from the bottom up, the request arrives through BasicServerRef.handleRequest, is dispatched through the CORBA server reference, and reaches _NamingContextAnyImplBase._invoke, which calls read_any on the IIOP input stream. The Any value is read through AnyImpl, which reads a value through ValueHandlerImpl and IIOPInputStream. The first value read is a Proxy, and the second is the JtaTransactionManager itself. ObjectStreamClass#readObject then invokes JtaTransactionManager#readObject, which calls initUserTransactionAndTransactionManager and finally lookupUserTransaction, the JNDI lookup.

From the original on medium.com
Step 1 ~ 3
Step 4 ~ 6
Step 7 ~ 8
Step 9: JNDI Injection

The annotated frames break the chain into steps: steps 1 to 3, steps 4 to 6, steps 7 to 8, and step 9, the JNDI injection itself.

Step 2: the NAT problem

A common obstacle is that the internal IP assigned by NAT is not reachable from the outside, and WebLogic servers are often installed and run behind a NAT firewall. Running the provided PoC against such a target produces a timeout.

From the original on medium.com
Operation timed out due to internal IP

To make the PoC work as expected, the responding IP has to be amended. This can be done by modifying the raw packet, or by intercepting and amending it in the library.

Change the socket’s address to the one accessible from the outside From the original on medium.com

Step 3: choosing the JNDI gadget for the target's JDK

The payload depends heavily on the JDK or WebLogic version in use. Before October 2018, using the LDAP protocol was the best gadget for exploiting JNDI injection. From Oracle JDK 11.0.1, 8u191, 7u201 and 6u211 onwards this changed: the property com.sun.jndi.ldap.object.trustURLCodebase defaults to false, and the bypass for that restriction was assigned CVE-2018-3149. The first attempt should therefore still be LDAP; if the target runs a newer JDK, the tricks for exploiting JNDI injections in Java can be tried instead.

Root cause

The IIOP naming path deserialises attacker-supplied values. The Any value carried in the naming request is read through IIOPInputStream and ValueHandlerImpl, and the deserialisation of a JtaTransactionManager object invokes its readObject, which performs a JNDI lookup on an attacker-controlled name. WebLogic does not blacklist JtaTransactionManager, even though it was already known as a JNDI injection trigger from CVE-2018-3191, so the class remains available as a gadget on the deserialisation path. The lookup is the malicious JNDI lookup through which the advisory says RCE is achieved.

Impact

An attacker who can reach the IIOP handling of a vulnerable WebLogic Server can trigger remote code execution through a malicious JNDI lookup. The practical reach depends on network placement: when the server sits behind NAT and its internal address is not reachable from the outside, the PoC times out until the responding IP is amended. The choice of gadget also depends on the target's JDK or WebLogic version, since newer JDKs disable remote codebase loading over LDAP by default.

Fix

The write-up does not describe a patch or configuration change.

Variants to test

  1. Send an IIOP naming request whose Any value carries a serialised JtaTransactionManager with an attacker-controlled lookup name. A positive result is a stack that reaches lookupUserTransaction through JtaTransactionManager#readObject, and an outbound lookup to the attacker's service.
  2. Repeat the same request against a target behind NAT with the responding IP amended, either in the raw packet or by intercepting it in the library. A positive result is that the timeout disappears and the lookup arrives.
  3. Try the LDAP gadget first, then, if the target runs a newer JDK, the alternative JNDI injection techniques. A positive result is code execution through whichever path the JDK still permits.

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. 13 min read.

What happened, in plain words

Oracle WebLogic Server is a program that companies use to run their Java web applications. A bug was found in it, tracked as CVE-2020-2551, that lets someone who can reach the server over the network run their own code on it, without logging in first. The write-up calls this remote code execution, or RCE.

The way in is a network protocol called IIOP. A protocol is simply an agreed set of rules for how two computers talk to each other, like the rules of a phone call: who speaks first, what words are allowed, how the call ends. IIOP is one of the protocols WebLogic listens on.

The advisory says the code execution is achieved through a malicious JNDI lookup. JNDI is Java's built-in address book: a program asks it for a name, and it returns the thing that name points to. If an attacker can choose the name, they can make the server fetch something from a machine the attacker controls. The write-up's point is that once you understand the protocol path, building a proof of concept (PoC, a small program that demonstrates the bug) is easy.

To explain why the bug works, the write-up first walks through four related technologies: RMI, CORBA, IIOP and RMI-IIOP. We will do the same, from zero.

RMI

Remote Method Invocation has existed since JDK 1.1. A JDK is the Java Development Kit, the bundle of tools and libraries you install to run and build Java programs. RMI lets a developer invoke a method on a remote server as though the object were local. A method is a named action a piece of software can perform, and an object is a bundle of data plus the methods that work on it. So RMI is like calling a colleague's extension and asking them to do something, while the phone makes it feel as if they were sitting next to you. Both sides have to fulfil some prerequisites for this to work: each side must know how to describe the objects being passed and how to reach the other.

Taken from http://blog.neoit.my/java/java-rmi-simple-server-example-using-terminal/ From the original on medium.com

The image shows a simple RMI server example being run from a terminal, taken from a blog post about setting up such a server.

CORBA

Common Object Request Broker Architecture is a standard defined by the Object Management Group (OMG), designed to let systems deployed on diverse platforms communicate. A standard here means a written agreement that many vendors implement, so their products can interoperate. Think of it as a common language agreed at an international conference so that people from different countries can do business without each learning the other's tongue.

CORBA uses an interface definition language (IDL) to specify the interfaces an object presents to the outside world. An interface is the public list of actions an object offers, like the menu in a restaurant: it tells you what you can order without showing you the kitchen. IDL is a separate, neutral language for writing that menu down, so it can then be translated into whatever programming language the implementer uses. CORBA then specifies a mapping from IDL to a concrete implementation language such as C++ or Java. A mapping is a set of translation rules: this IDL word becomes that C++ word, and so on.

IIOP

IIOP is CORBA's communication protocol, using TCP/IP as the transport. TCP/IP is the basic postal system of the internet: it moves packets of data between machines. IIOP specifies a standard for client and server communication, meaning it says exactly what bytes go back and forth and in what order when a CORBA client talks to a CORBA server.

RMI-IIOP

Java programmers previously had to choose between RMI and CORBA/IIOP (Java IDL) for distributed programming. Distributed programming means writing software whose parts run on different machines. RMI-IIOP combines the ease of use of RMI style with CORBA's cross-language interoperability. Interoperability means different systems can work together. In everyday terms, RMI was a comfortable local phone system that only worked between your own offices, and CORBA was an international switchboard that worked with everyone but was fiddly to use. RMI-IIOP is the phone that has the comfortable handset and still dials abroad.

This figure shows the relationships for objects that use IIOP between a client and WebLogic Server From the original on medium.com

The figure shows the relationships for objects that use IIOP between a client and WebLogic Server.

Setup

The write-up does not describe a lab build, target version, account or tooling beyond the PoC itself. The exploit path runs through the weblogic.jndi.WLInitialContextFactory context factory. A context factory is a piece of code whose job is to create the starting point, the context, from which a program looks names up in JNDI. The payload's behaviour depends heavily on the JDK or WebLogic version running on the target, which is covered under the JDK version question below.

Finding it

The entry point is the Context Factory. It is the key to initiating a normal IIOP request that carries adversarial data and so triggers the bug. Adversarial data means input crafted on purpose to make the receiving program misbehave. Following the initialisation of this factory all the way down shows that it does almost the same things as using the CORBA library directly. Initialisation is the setup work a program does when it creates an object, before the object is ready to be used.

From the original on medium.com
Follow all the way down…
Just like how the CORBA initiates the ORB and gets the ref of Naming Service

The screenshots follow the call chain down through the factory's initialisation, ending at the point where, just like CORBA, it starts the ORB (the object request broker, the part that routes requests to the right object) and obtains a reference to the Naming Service, the service that maps names to objects.

That gives a way to trigger the vulnerability. The second half of the chain is com.bea.core.repackaged.springframework.transaction.jta.JtaTransactionManager. The advisory says the RCE is achieved via a malicious JNDI lookup, and this class is what performs it. A class is a blueprint in Java from which objects are made. JtaTransactionManager played the role of the JNDI Injection trigger in CVE-2018-3191, and it is used again here because WebLogic does not blacklist it. A blacklist is a list of things a program refuses to accept; because this class is not on WebLogic's list, it is still accepted from the network.

Exploitation

Step 1: the deserialisation stack

Deserialisation is the reverse of saving an object: a program takes a stream of bytes and rebuilds the object from it. If the bytes come from an attacker, the attacker effectively gets to choose what object is rebuilt and with what contents. A stack frame, or stack trace, is the list of function calls a program was in the middle of, innermost first, which developers read to see how execution arrived somewhere. The stack frame recorded during the deserialisation process shows how the IIOP input reaches the JNDI lookup:

Text
lookupUserTransaction:565, JtaTransactionManager (com.bea.core.repackaged.springframework.transaction.jta)initUserTransactionAndTransactionManager:444, JtaTransactionManager (com.bea.core.repackaged.springframework.transaction.jta)readObject:1198, JtaTransactionManager (com.bea.core.repackaged.springframework.transaction.jta) <-- JtaTransactionManager#readObjectinvoke0:-1, NativeMethodAccessorImpl (sun.reflect)invoke:62, NativeMethodAccessorImpl (sun.reflect)invoke:43, DelegatingMethodAccessorImpl (sun.reflect)invoke:498, Method (java.lang.reflect)readObject:314, ObjectStreamClass (weblogic.utils.io) <-- ObjectStreamClass#readObjectreadValueData:281, ValueHandlerImpl (weblogic.corba.utils)readValue:93, ValueHandlerImpl (weblogic.corba.utils)read_value:2128, IIOPInputStream (weblogic.iiop) <-- JtaTransactionManagerread_value:1936, IIOPInputStream (weblogic.iiop)...readValue:93, ValueHandlerImpl (weblogic.corba.utils)read_value:2128, IIOPInputStream (weblogic.iiop) <-- Proxyread_value:1936, IIOPInputStream (weblogic.iiop)read_value_internal:220, AnyImpl (weblogic.corba.idl)read_value:115, AnyImpl (weblogic.corba.idl)read_any:1648, IIOPInputStream (weblogic.iiop) <-- bind_any()read_any:1641, IIOPInputStream (weblogic.iiop)_invoke:58, _NamingContextAnyImplBase (weblogic.corba.cos.naming)invoke:249, CorbaServerRef (weblogic.corba.idl)invoke:230, ClusterableServerRef (weblogic.rmi.cluster)run:522, BasicServerRef$1 (weblogic.[redacted])doAs:363, AuthenticatedSubject (weblogic.security.[redacted])runAs:146, SecurityManager (weblogic.security.service)handleRequest:518, BasicServerRef (weblogic.[redacted])...

Each line has the form method:line, class (package). The method is the action being run, the number after the colon is the line in the source file, the class is the blueprint it belongs to, and the package is the folder-like grouping the class lives in. The arrows mark the interesting transitions.

Read from the bottom up, the request arrives through BasicServerRef.handleRequest, is dispatched through the CORBA server reference, and reaches _NamingContextAnyImplBase._invoke, which calls read_any on the IIOP input stream. The Any value is read through AnyImpl, which reads a value through ValueHandlerImpl and IIOPInputStream. Any is CORBA's container for a value of any type: it carries the value plus a note saying what type it is, so the receiver knows how to rebuild it. The first value read is a Proxy, and the second is the JtaTransactionManager itself. A Proxy is a stand-in object that forwards calls to something else. ObjectStreamClass#readObject then invokes JtaTransactionManager#readObject, which calls initUserTransactionAndTransactionManager and finally lookupUserTransaction, the JNDI lookup. readObject is the method Java calls automatically when rebuilding an object from bytes, which is exactly why a class that does something dangerous in readObject is useful to an attacker.

From the original on medium.com
Step 1 ~ 3
Step 4 ~ 6
Step 7 ~ 8
Step 9: JNDI Injection

The annotated frames break the chain into steps: steps 1 to 3, steps 4 to 6, steps 7 to 8, and step 9, the JNDI injection itself.

Step 2: the NAT problem

NAT, network address translation, is the trick a router uses to let many machines share one public internet address. Each machine gets an internal address that only works inside the local network. A common obstacle is that the internal IP assigned by NAT is not reachable from the outside, and WebLogic servers are often installed and run behind a NAT firewall. Running the provided PoC against such a target produces a timeout.

From the original on medium.com
Operation timed out due to internal IP

The screenshots show the operation timing out because the server handed back an internal IP address.

To make the PoC work as expected, the responding IP has to be amended. This can be done by modifying the raw packet, or by intercepting and amending it in the library. A raw packet is the actual chunk of network data as it goes over the wire; intercepting means catching it in transit and changing it before passing it on. In plain terms, the server's reply contains a return address that is useless from outside, so the attacker rewrites that address to one they can reach.

Change the socket’s address to the one accessible from the outside From the original on medium.com

The screenshot shows the socket's address being changed to one accessible from the outside.

Step 3: choosing the JNDI gadget for the target's JDK

The payload depends heavily on the JDK or WebLogic version in use. A gadget, in security slang, is a piece of existing code that can be bent to do something its authors did not intend. Before October 2018, using the LDAP protocol was the best gadget for exploiting JNDI injection. LDAP is a directory protocol, a kind of phone book service; JNDI can be pointed at an LDAP server, and older JDKs would happily download and run code from the address that server returned. From Oracle JDK 11.0.1, 8u191, 7u201 and 6u211 onwards this changed: the property com.sun.jndi.ldap.object.trustURLCodebase defaults to false, and the bypass for that restriction was assigned CVE-2018-3149. A property is a named setting a Java program reads at runtime; setting this one to false tells Java not to trust code downloaded from a URL given by an LDAP server. The first attempt should therefore still be LDAP; if the target runs a newer JDK, the tricks for exploiting JNDI injections in Java can be tried instead.

Root cause

The IIOP naming path deserialises attacker-supplied values. Authentication is the step where a system checks who you are, usually with a password. The Any value carried in the naming request is read through IIOPInputStream and ValueHandlerImpl, and the deserialisation of a JtaTransactionManager object invokes its readObject, which performs a JNDI lookup on an attacker-controlled name. WebLogic does not blacklist JtaTransactionManager, even though it was already known as a JNDI injection trigger from CVE-2018-3191, so the class remains available as a gadget on the deserialisation path. The lookup is the malicious JNDI lookup through which the advisory says RCE is achieved.

Impact

An attacker who can reach the IIOP handling of a vulnerable WebLogic Server can trigger remote code execution through a malicious JNDI lookup. The practical reach depends on network placement: when the server sits behind NAT and its internal address is not reachable from the outside, the PoC times out until the responding IP is amended. The choice of gadget also depends on the target's JDK or WebLogic version, since newer JDKs disable remote codebase loading over LDAP by default.

Fix

The write-up does not describe a patch or configuration change.

Variants to test

  1. Send an IIOP naming request whose Any value carries a serialised JtaTransactionManager with an attacker-controlled lookup name. A positive result is a stack that reaches lookupUserTransaction through JtaTransactionManager#readObject, and an outbound lookup to the attacker's service.
  2. Repeat the same request against a target behind NAT with the responding IP amended, either in the raw packet or by intercepting it in the library. A positive result is that the timeout disappears and the lookup arrives.
  3. Try the LDAP gadget first, then, if the target runs a newer JDK, the alternative JNDI injection techniques. A positive result is code execution through whichever path the JDK still permits.

Glossary

  • API: a defined set of actions one program offers to another, like a menu of things you are allowed to ask for.
  • Adversarial data: input crafted on purpose to make the receiving program misbehave.
  • Authentication: the step where a system checks who you are, usually with a password.
  • Blacklist: a list of things a program refuses to accept.
  • Class: a blueprint in Java from which objects are made.
  • Context factory: code that creates the starting point from which a program looks names up in JNDI.
  • CORBA: Common Object Request Broker Architecture, a standard for letting systems on different platforms communicate.
  • CVE: a public identifier for a known security vulnerability.
  • Deserialisation: rebuilding an object from a stream of bytes; the reverse of saving it.
  • Distributed programming: writing software whose parts run on different machines.
  • Gadget: existing code that can be bent to do something its authors did not intend.
  • IDL: interface definition language, a neutral language for describing what an object offers.
  • IIOP: CORBA's communication protocol, running over TCP/IP.
  • Initialisation: the setup work a program does when creating an object, before it is ready to use.
  • Interface: the public list of actions an object offers.
  • Interoperability: the ability of different systems to work together.
  • JDK: Java Development Kit, the tools and libraries used to run and build Java programs.
  • JNDI: Java's built-in address book, mapping names to objects and services.
  • JNDI injection: making a program perform a JNDI lookup on a name the attacker chose.
  • LDAP: a directory protocol, a kind of phone book service.
  • Method: a named action a piece of software can perform.
  • NAT: network address translation, letting many machines share one public address with internal addresses of their own.
  • Object: a bundle of data plus the methods that work on it.
  • ORB: object request broker, the part of CORBA that routes requests to the right object.
  • Package: a folder-like grouping for Java classes.
  • PoC: proof of concept, a small program that demonstrates a bug.
  • Property: a named setting a Java program reads at runtime.
  • Protocol: an agreed set of rules for how two computers talk.
  • Proxy: a stand-in object that forwards calls to something else.
  • RCE: remote code execution, running your own code on someone else's machine.
  • readObject: the method Java calls automatically when rebuilding an object from bytes.
  • RMI: Remote Method Invocation, calling a method on a remote server as if it were local.
  • RMI-IIOP: a combination of RMI's ease of use with CORBA's cross-language interoperability.
  • Stack frame / stack trace: the list of function calls a program was in the middle of, innermost first.
  • TCP/IP: the basic transport of the internet, moving packets between machines.
  • Timeout: giving up after waiting too long for a reply.
  • WebLogic Server: Oracle's program for running Java web applications.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.