Skip to content
RCE Write-up Advanced

Weblogic CVE-2023-21931 vulnerability exploration technique: post-deserialization exploitation

The report describes two post-deserialization vulnerabilities in Oracle WebLogic (CVE-2023-21931 and CVE-2023-21839) where malicious JNDI lookups are triggered after deserialization, allowing remote code execution. An attacker could exploit these to load a custom JNDI address and execute arbitrary commands.

Goby Follow

Published on github.com

gobysec / Weblogic Public

Goby (@GobySec), on github.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. 8 min read.

Context

WebLogic deserialisation research has traditionally concentrated on the trigger point of deserialisation itself: maliciously crafted serialised data is passed to methods such as readObject(), readResolve() or readExternal() to reach the attacker's goal. This article looks at a different phase. Some code paths involve deserialisation but do not execute anything malicious while the object is being deserialised, so they are easily dismissed as unexploitable during routine research. The idea explored here is the "post-deserialisation" vulnerability: a seemingly harmless deserialisation is followed by an operation that uses the deserialised object, and that later operation is where the attack actually fires.

The concrete example given is the JNDI naming path. If a vulnerability is not triggered after a bind() or rebind() operation, other methods such as lookup() or lookupLink() can be tried to trigger it. Using this approach the researchers found two WebLogic post-deserialisation vulnerabilities, CVE-2023-21931 and CVE-2023-21839, both confirmed by Oracle. The article analyses the attack process with lookup() as the trigger and then walks through both CVEs.

Setup

The article lists the Vulfocus WebLogic images used as the research environment. The images used are:

Bash
docker pull vulfocus/vcpe-1.0-a-oracle-weblogic:12.2.1.2.0-jdk-release
docker pull vulfocus/vcpe-1.0-a-oracle-weblogic:12.2.1.1.0-jdk-release
docker pull vulfocus/vcpe-1.0-a-oracle-weblogic:12.2.1.3.0-jdk-release
docker pull vulfocus/vcpe-1.0-a-oracle-weblogic:12.2.1.4.0-jdk-release
docker pull vulfocus/vcpe-1.0-a-oracle-weblogic:12.2.1.0.0-jdk-release
docker pull vulfocus/vcpe-1.0-a-oracle-weblogic:14.1.1.0.0-jdk-release
docker pull vulfocus/vcpe-1.0-a-oracle-weblogic:12.1.2.0.0-jdk-release
docker pull vulfocus/vcpe-1.0-a-oracle-weblogic:12.1.3.0.0-jdk-release
docker pull vulfocus/vcpe-1.0-a-oracle-weblogic:[redacted]-jdk-release

Both vulnerabilities were integrated into Goby, with command execution and shell functionality added. The demonstrations in the article were produced with Goby Beta 2.4.7, which supports scanning and verification for the Goby Red Team and Missed Scan versions.

Finding it

The starting observation is that conventional research stops at the deserialisation call itself. The researchers instead traced what happens after a naming operation completes. In WebLogic, when no vulnerability is triggered after bind() or rebind(), the lookup() and lookupLink() methods are worth trying, because they reach a different code path that processes the deserialised object.

Tracing the call stack for lookup() gives the following sequence:

  1. After receiving a request, WebLogic parses the incoming data using the invoke() method in the BasicServerRef class.
  2. Using the _invoke() method, WebLogic executes the resolve_any() method based on the passed-in method name of resolve_any.
  3. In the resolve_any() method, the incoming binding name is resolved using the resolveObject() method.
  4. In the resolveObject() method, the lookup() method is called based on the context information.
  5. Based on the context information, a series of lookup() method calls are made in classes such as WLContextImpl, WLEventContextImpl, RootNamingNode, ServerNamingNode and BasicNamingNode, resulting in the resolveObject() method call in the BasicNamingNode class.
  6. Since the obj passed into the resolveObject() method is not an instance of the NamingNode class and the mode value defaults to 1, the getObjectInstance() method in the WLNamingManager class is called.
From the original on github.com

The trace ends in WLNamingManager.getObjectInstance(), which calls the getReferent() method on the passed-in object according to its interface type, completing the invocation of lookup() at the vulnerability trigger point. Both CVEs are triggered through the two branches of getObjectInstance().

Exploitation

CVE-2023-21931: the LinkRef branch

The trigger point of CVE-2023-21931 is the getObjectInstance() method of the WLNamingManager class. When the passed-in boundObject is an implementation class of LinkRef, the getLinkName() method of boundObject is called, and the lookup() method performs remote JNDI loading on the linkAddrType address returned by getLinkName(). When instantiating the LinkRef class, a JNDI address can be passed to linkAddrType through the class constructor, so the lookup() call can be pointed at a custom JNDI address.

Java
package weblogic.[redacted];
public final class WLNamingManager {
    public static Object getObjectInstance(Object boundObject, Name name, Context ctx, Hashtable env) throws NamingException {
        if (boundObject instanceof ClassTypeOpaqueReference) {
						......
        } else if (boundObject instanceof LinkRef) {
            String linkName = ((LinkRef)boundObject).getLinkName();
            InitialContext ic = null;
            try {
                ic = new InitialContext(env);
                boundObject = ic.lookup(linkName);  // vulnerability trigger point
            } catch (NamingException var15) {
              ......
            } finally {......}
        }
    }
}

The vulnerability lies in the construction of a JNDI address within the LinkRef class, which is a native Java class. Using the constructor of LinkRef, the value of the linkAddrType variable can be controlled, and the getLinkName() method then returns linkAddrType as a string.

Java
package javax.naming;
public class LinkRef extends Reference {
    static final String linkClassName = LinkRef.class.getName();
    static final String linkAddrType = "LinkAddress";

    public LinkRef(Name linkName) {
        super(linkClassName, new StringRefAddr(linkAddrType, linkName.toString()));
    }

    public LinkRef(String linkName) {
        super(linkClassName, new StringRefAddr(linkAddrType, linkName));
    }

    public String getLinkName() throws NamingException {
        if (className != null && className.equals(linkClassName)) {
            RefAddr addr = get(linkAddrType);
            if (addr != null && addr instanceof StringRefAddr) {
                return (String)((StringRefAddr)addr).getContent();
            }
        }
        throw new MalformedLinkException();
    }
}
From the original on github.com

In this chain, the deserialisation processes of the rebind() and lookup() methods do not execute malicious operations. The vulnerability fires after deserialisation is complete, when getObjectInstance() in WLNamingManager calls lookup() and performs a remote malicious load of the JNDI address.

The demonstration shows the CVE-2023-21931 exploit in Goby, including command execution and shell access.

CVE-2023-21839: the OpaqueReference branch

ForeignOpaqueReference is an implementation class of the OpaqueReference interface. It declares two private variables, jndiEnvironment and remoteJNDIName, and two constructors. The parameterised constructor receives env and remoteJNDIName and assigns them to those two private variables.

The getReferent() method in ForeignOpaqueReference implements the OpaqueReference interface. In it, retVal = context.lookup(this.remoteJNDIName); performs a remote load of the JNDI address held in the class's remoteJNDIName variable, which leads to the deserialisation vulnerability.

Java
package weblogic.[redacted];
public class ForeignOpaqueReference implements OpaqueReference, Serializable {
    private Hashtable jndiEnvironment;
    private String remoteJNDIName;
        ......
    public ForeignOpaqueReference(String remoteJNDIName, Hashtable env) {
        this.remoteJNDIName = remoteJNDIName;
        this.jndiEnvironment = env;
    }
    public Object getReferent(Name name, Context ctx) throws NamingException {
        InitialContext context;
        if (this.jndiEnvironment == null) {
            context = new InitialContext();
        } else {
            Hashtable properties = this.decrypt();
            context = new InitialContext(properties);
        }
        Object retVal;
        try {
            retVal = context.lookup(this.remoteJNDIName);   // vulnerability point
        } finally {
            context.close();
        }
        return retVal;
    }
    ......
}

The OpaqueReference interface has two abstract methods, getReferent() and toString():

Java
package weblogic.jndi;
public interface OpaqueReference {
    Object getReferent(Name var1, Context var2) throws NamingException;
    String toString();
}

The getReferent() method of ForeignOpaqueReference is called from WLNamingManager. In getObjectInstance(), if the passed-in boundObject implements the OpaqueReference interface, the object's getReferent() method is called as follows: boundObject = ((OpaqueReference)boundObject).getReferent(name, ctx);. Because ForeignOpaqueReference implements OpaqueReference, its getReferent() method is called, leading to the deserialisation vulnerability.

Java
package weblogic.[redacted];
public final class WLNamingManager {
	public static Object getObjectInstance(Object boundObject, Name name, Context ctx, Hashtable env) throws NamingException {
        if (boundObject instanceof ClassTypeOpaqueReference) {
						......
        } else if (boundObject instanceof OpaqueReference) {
            boundObject = ((OpaqueReference)boundObject).getReferent(name, ctx);
        } else if (boundObject instanceof LinkRef) {
      ...
        }
    }
}
From the original on github.com

As with CVE-2023-21931, no malicious operation is executed during deserialisation. The vulnerability is triggered after deserialisation completes, by the lookup() call inside getReferent() in ForeignOpaqueReference.

The demonstration shows the CVE-2023-21839 exploit in Goby, again with command execution and shell access.

Root cause

Both bugs sit in WLNamingManager.getObjectInstance(), which takes an object that has just been deserialised and dispatches on its type. Two of those branches hand control to attacker-influenced data:

  • The LinkRef branch calls getLinkName() on the deserialised object and passes the returned string straight to ic.lookup(linkName). Because LinkRef is a native Java class whose constructor stores an arbitrary string as the LinkAddress reference address, the attacker controls the JNDI address that is looked up.
  • The OpaqueReference branch calls getReferent(name, ctx) on the deserialised object. ForeignOpaqueReference implements that interface and its getReferent() performs context.lookup(this.remoteJNDIName), with remoteJNDIName set through the constructor.

In both cases the deserialisation step itself is benign, which is why a review focused only on readObject() and similar methods misses them. The dangerous operation is the naming lookup that follows, reached through the lookup() path described above.

Impact

An attacker who can supply the serialised object to the naming service can cause WebLogic to perform a remote JNDI load from an address of their choosing. In the researchers' own tooling this was turned into command execution and shell access. The article does not state which versions are affected beyond the images listed, nor does it give a CVSS score or bounty.

Fix

Oracle fixed both issues: CVE-2023-21931 was officially fixed on 18 April 2023 and CVE-2023-21839 on 16 January 2023. The article does not describe the code change itself.

Variants to test

  • Other naming operations. Where bind() or rebind() does not trigger anything, try lookup() and lookupLink() against the same service.
  • Other getObjectInstance() branches. The article notes both CVEs come from two branches of WLNamingManager.getObjectInstance(). Enumerate the remaining branches and check whether any of them call a method on the deserialised object that uses attacker-controlled fields.
  • Other classes implementing OpaqueReference. ForeignOpaqueReference is one implementation; look for others whose getReferent() performs a remote operation using instance fields.
  • Other classes extending Reference like LinkRef. Look for reference types whose stored address is returned by a getter and then passed to a lookup.
  • Post-deserialisation timing. Instrument the deserialisation path to confirm that no malicious action occurs during readObject() and that the action happens only after the naming operation.

Timeline

CVE-2023-21931:

  • 12 August 2022: vulnerability reported to official channels
  • 19 August 2022: vulnerability officially confirmed
  • 18 April 2023: vulnerability officially fixed

CVE-2023-21839:

  • 31 July 2022: vulnerability reported to official channels
  • 5 August 2022: vulnerability officially confirmed
  • 16 January 2023: vulnerability officially fixed

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

What happened, in plain words

Oracle WebLogic is a Java application server: a program that runs web applications for an organisation and answers requests from browsers and other programs. Like any server, it has bugs, and some of those bugs let an outsider make it run code of the outsider's choosing.

A large family of WebLogic bugs lives in deserialisation. To understand that word, start with serialisation: turning a live object in a program's memory (say, a customer record) into a stream of bytes so it can be saved to disk or sent over a network. Deserialisation is the reverse: taking that stream of bytes and rebuilding the object in memory. If an attacker can hand the server a stream of bytes they crafted themselves, the server will faithfully rebuild whatever object the bytes describe, and some objects do dangerous things when they are rebuilt.

Most research on these bugs looks at the exact moment the object is rebuilt. This article looks at a different moment: what the server does with the object after it has been rebuilt. The authors call this a post-deserialisation vulnerability. The rebuilding step looks harmless, so a quick review passes it by, but a later step takes a value out of the rebuilt object and uses it to fetch something from a remote address. That later fetch is the attack.

The two bugs described are CVE-2023-21931 and CVE-2023-21839. A CVE is a public catalogue number for a known security flaw, so anyone can look it up. Both were reported to Oracle and confirmed by Oracle. The article traces how the lookup() operation in WebLogic's naming service reaches the dangerous code, then walks through both bugs.

Background concepts, from zero

Before the technical part, a few ideas come up again and again.

  • Java class and object. A class is a blueprint written in code; an object is one thing built from that blueprint while the program runs. LinkRef is a class; a particular LinkRef holding a particular address is an object.
  • Interface. A contract that says "any class claiming to implement me must provide these methods". Other code can then treat any such object the same way without knowing its exact class. OpaqueReference is an interface in this article.
  • Method. A named action a class can perform, such as lookup() or getLinkName(). When code "calls" a method, it asks the object to perform that action.
  • JNDI. Java Naming and Directory Interface: a standard way for Java programs to look things up by name, like a phone book. You give it a name, it gives you back the thing registered under that name. A JNDI address is such a name, and it can point at a remote server, which is why it matters here: if an attacker controls the name, they control where the server connects.
  • bind(), rebind(), lookup(), lookupLink(). Operations on that phone book. bind() adds a name, rebind() replaces an existing name, lookup() fetches what is registered under a name, and lookupLink() follows a link stored under a name.
  • Call stack. The chain of method calls currently in progress: method A called method B, which called method C. "Tracing the call stack" means following that chain to see how the program arrived at a particular line of code.
  • Constructor. The special method that runs when a new object is created, used to fill in its starting values.
  • instanceof. A Java check that asks "is this object an instance of that class?" It is how the code in this article decides which branch to take.
  • Goby. A security scanning tool that the researchers used to package the exploits and demonstrate them.

The idea: look after deserialisation, not only during it

Conventional research on WebLogic deserialisation passes maliciously crafted serialised data to methods such as readObject(), readResolve() or readExternal(), which run while the object is being rebuilt, and tries to reach the attacker's goal from there. The authors point out that some code paths involve deserialisation but run nothing malicious during the rebuild, so they are easily written off as unexploitable.

The trick is to keep going. If nothing happens after a bind() or rebind() operation, try other operations on the same service, such as lookup() or lookupLink(). Those reach different code that takes the just-rebuilt object and acts on it. That is where the attack fires.

Using this approach the researchers found the two WebLogic bugs, CVE-2023-21931 and CVE-2023-21839, both confirmed by Oracle. The article analyses the attack process with lookup() as the trigger and then walks through both.

The test environment

The article lists WebLogic images from the Vulfocus environment. Vulfocus provides ready-made, deliberately vulnerable machines, so a researcher does not have to install and configure the product by hand. The images used are pulled with Docker, a tool that downloads and runs such prebuilt machines:

Bash
docker pull vulfocus/vcpe-1.0-a-oracle-weblogic:12.2.1.2.0-jdk-release
docker pull vulfocus/vcpe-1.0-a-oracle-weblogic:12.2.1.1.0-jdk-release
docker pull vulfocus/vcpe-1.0-a-oracle-weblogic:12.2.1.3.0-jdk-release
docker pull vulfocus/vcpe-1.0-a-oracle-weblogic:12.2.1.4.0-jdk-release
docker pull vulfocus/vcpe-1.0-a-oracle-weblogic:12.2.1.0.0-jdk-release
docker pull vulfocus/vcpe-1.0-a-oracle-weblogic:14.1.1.0.0-jdk-release
docker pull vulfocus/vcpe-1.0-a-oracle-weblogic:12.1.2.0.0-jdk-release
docker pull vulfocus/vcpe-1.0-a-oracle-weblogic:12.1.3.0.0-jdk-release
docker pull vulfocus/vcpe-1.0-a-oracle-weblogic:[redacted]-jdk-release

Line by line: each line asks Docker to download one image. docker pull is the download command. The part after the colon is the tag, which names a specific WebLogic version and Java runtime, for example 12.2.1.2.0-jdk-release. The nine lines cover WebLogic [redacted] through [redacted], 14.1.1.0.0, 12.1.2.0.0, 12.1.3.0.0 and 10.3.6.0.

Both bugs were integrated into Goby, with command execution and shell functionality added, so the tool can not only detect the flaw but also run commands on the target and provide shell access. The demonstrations were produced with Goby Beta 2.4.7, which supports scanning and verification for the Goby Red Team and Missed Scan versions.

Finding it: tracing lookup()

The starting observation is that conventional research stops at the deserialisation call itself. The researchers instead traced what happens after a naming operation completes. In WebLogic, when nothing is triggered after bind() or rebind(), the lookup() and lookupLink() methods are worth trying, because they reach a different code path that processes the deserialised object.

Tracing the call stack for lookup() gives this sequence:

  1. After receiving a request, WebLogic parses the incoming data using the invoke() method in the BasicServerRef class.
  2. Using the _invoke() method, WebLogic executes the resolve_any() method based on the passed-in method name of resolve_any.
  3. In the resolve_any() method, the incoming binding name is resolved using the resolveObject() method.
  4. In the resolveObject() method, the lookup() method is called based on the context information.
  5. Based on the context information, a series of lookup() method calls are made in classes such as WLContextImpl, WLEventContextImpl, RootNamingNode, ServerNamingNode and BasicNamingNode, resulting in the resolveObject() method call in the BasicNamingNode class.
  6. Since the obj passed into the resolveObject() method is not an instance of the NamingNode class and the mode value defaults to 1, the getObjectInstance() method in the WLNamingManager class is called.
From the original on github.com

In plain words: a request arrives, gets parsed, and is routed by its method name to resolve_any(). That resolves the name the client asked for, which leads through a chain of naming classes, each calling the next lookup(), until BasicNamingNode.resolveObject() runs. There, a type check fails (the object is not a NamingNode) and a default setting (mode is 1) sends execution to WLNamingManager.getObjectInstance(). The screenshot shows this chain of calls.

The trace ends in WLNamingManager.getObjectInstance(), which calls the getReferent() method on the passed-in object according to its interface type, completing the invocation of lookup() at the vulnerability trigger point. Both CVEs are triggered through the two branches of getObjectInstance().

Exploitation

CVE-2023-21931: the LinkRef branch

The trigger point of CVE-2023-21931 is the getObjectInstance() method of the WLNamingManager class. When the passed-in boundObject is an implementation class of LinkRef, the getLinkName() method of boundObject is called, and the lookup() method performs remote JNDI loading on the linkAddrType address returned by getLinkName(). When instantiating the LinkRef class, a JNDI address can be passed to linkAddrType through the class constructor, so the lookup() call can be pointed at a custom JNDI address.

Java
package weblogic.[redacted];
public final class WLNamingManager {
    public static Object getObjectInstance(Object boundObject, Name name, Context ctx, Hashtable env) throws NamingException {
        if (boundObject instanceof ClassTypeOpaqueReference) {
						......
        } else if (boundObject instanceof LinkRef) {
            String linkName = ((LinkRef)boundObject).getLinkName();
            InitialContext ic = null;
            try {
                ic = new InitialContext(env);
                boundObject = ic.lookup(linkName);  // vulnerability trigger point
            } catch (NamingException var15) {
              ......
            } finally {......}
        }
    }
}

Line by line:

  • package weblogic.[redacted]; says which folder of the codebase this class belongs to.
  • public final class WLNamingManager { declares the class; final means it cannot be extended by another class.
  • The getObjectInstance(...) line declares a method that receives four things: boundObject (the object that was just deserialised), name, ctx (a naming context) and env (environment settings), and may throw a NamingException if the lookup fails.
  • if (boundObject instanceof ClassTypeOpaqueReference) { is the first branch: if the object is of that type, do something the article elides with .......
  • } else if (boundObject instanceof LinkRef) { is the branch that matters here: if the object is a LinkRef, run the block below.
  • String linkName = ((LinkRef)boundObject).getLinkName(); asks the object for its stored link name and keeps it in a string. asks the object for its stored link name and keeps it in a string
  • InitialContext ic = null; prepares a variable for a naming context, initially empty.
  • ic = new InitialContext(env); creates the naming context using the supplied environment settings.
  • boundObject = ic.lookup(linkName); // vulnerability trigger point is the dangerous line: it looks up the attacker-controlled name, which can make the server connect to a remote address of the attacker's choosing. The comment in the code marks it as the trigger point.
  • The catch and finally blocks handle errors and cleanup; the article elides their bodies.

The vulnerability lies in the construction of a JNDI address within the LinkRef class, which is a native Java class. Using the constructor of LinkRef, the value of the linkAddrType variable can be controlled, and the getLinkName() method then returns linkAddrType as a string.

Java
package javax.naming;
public class LinkRef extends Reference {
    static final String linkClassName = LinkRef.class.getName();
    static final String linkAddrType = "LinkAddress";

    public LinkRef(Name linkName) {
        super(linkClassName, new StringRefAddr(linkAddrType, linkName.toString()));
    }

    public LinkRef(String linkName) {
        super(linkClassName, new StringRefAddr(linkAddrType, linkName));
    }

    public String getLinkName() throws NamingException {
        if (className != null && className.equals(linkClassName)) {
            RefAddr addr = get(linkAddrType);
            if (addr != null && addr instanceof StringRefAddr) {
                return (String)((StringRefAddr)addr).getContent();
            }
        }
        throw new MalformedLinkException();
    }
}

Line by line:

  • package javax.naming; places this class in Java's standard naming package, which is why the article calls it a native Java class: it ships with Java, not with WebLogic.
  • public class LinkRef extends Reference { declares a class that builds on Reference, a standard container for an address.
  • static final String linkClassName = LinkRef.class.getName(); stores the class's own name in a constant.
  • static final String linkAddrType = "LinkAddress"; stores the label under which the address is kept: the literal string LinkAddress.
  • The first constructor, public LinkRef(Name linkName), takes a name object and calls super(...) to store it as a StringRefAddr under the LinkAddress label, converting the name to a string with linkName.toString().
  • The second constructor, public LinkRef(String linkName), does the same with a plain string. does the same with a plain string
  • public String getLinkName() throws NamingException { declares the getter that returns the stored address.
  • if (className != null && className.equals(linkClassName)) { checks that the object really is a LinkRef before returning anything.
  • RefAddr addr = get(linkAddrType); fetches the entry stored under LinkAddress.
  • if (addr != null && addr instanceof StringRefAddr) { checks that an entry exists and is a string address.
  • return (String)((StringRefAddr)addr).getContent(); returns the stored string, which is the attacker's address.
  • throw new MalformedLinkException(); is reached if the checks fail, meaning the object is not a well-formed link.
From the original on github.com

In this chain, the deserialisation processes of the rebind() and lookup() methods do not execute malicious operations. The vulnerability fires after deserialisation is complete, when getObjectInstance() in WLNamingManager calls lookup() and performs a remote malicious load of the JNDI address. That is the whole point of the article: the rebuild is quiet, the follow-up lookup is not.

The demonstration shows the CVE-2023-21931 exploit in Goby, including command execution and shell access.

CVE-2023-21839: the OpaqueReference branch

ForeignOpaqueReference is an implementation class of the OpaqueReference interface. It declares two private variables, jndiEnvironment and remoteJNDIName, and two constructors. The parameterised constructor receives env and remoteJNDIName and assigns them to those two private variables.

The getReferent() method in ForeignOpaqueReference implements the OpaqueReference interface. In it, retVal = context.lookup(this.remoteJNDIName); performs a remote load of the JNDI address held in the class's remoteJNDIName variable, which leads to the deserialisation vulnerability.

Java
package weblogic.[redacted];
public class ForeignOpaqueReference implements OpaqueReference, Serializable {
    private Hashtable jndiEnvironment;
    private String remoteJNDIName;
        ......
    public ForeignOpaqueReference(String remoteJNDIName, Hashtable env) {
        this.remoteJNDIName = remoteJNDIName;
        this.jndiEnvironment = env;
    }
    public Object getReferent(Name name, Context ctx) throws NamingException {
        InitialContext context;
        if (this.jndiEnvironment == null) {
            context = new InitialContext();
        } else {
            Hashtable properties = this.decrypt();
            context = new InitialContext(properties);
        }
        Object retVal;
        try {
            retVal = context.lookup(this.remoteJNDIName);   // vulnerability point
        } finally {
            context.close();
        }
        return retVal;
    }
    ......
}

Line by line:

  • package weblogic.[redacted]; places the class in WebLogic's internal naming package.
  • public class ForeignOpaqueReference implements OpaqueReference, Serializable { declares a class that promises to honour the OpaqueReference contract and can be serialised, which is what allows it to arrive as attacker-supplied bytes.
  • private Hashtable jndiEnvironment; and private String remoteJNDIName; are the two private fields: environment settings and the remote name to look up.
  • The constructor public ForeignOpaqueReference(String remoteJNDIName, Hashtable env) copies its two arguments into those fields with this.remoteJNDIName = remoteJNDIName; and this.jndiEnvironment = env;.
  • public Object getReferent(Name name, Context ctx) throws NamingException { is the method the interface requires.
  • InitialContext context; prepares a naming context variable.
  • if (this.jndiEnvironment == null) { context = new InitialContext(); } creates a default context when no environment was supplied.
  • else { Hashtable properties = this.decrypt(); context = new InitialContext(properties); } decrypts the stored environment and builds the context from it.
  • retVal = context.lookup(this.remoteJNDIName); // vulnerability point is the dangerous line: it looks up the remote name, performing a remote JNDI load. The comment marks it as the vulnerability point.
  • finally { context.close(); } closes the context whether or not the lookup succeeded.
  • return retVal; hands back whatever the lookup produced.

The OpaqueReference interface has two abstract methods, getReferent() and toString():

Java
package weblogic.jndi;
public interface OpaqueReference {
    Object getReferent(Name var1, Context var2) throws NamingException;
    String toString();
}

Line by line: package weblogic.jndi; places the interface in WebLogic's naming package. public interface OpaqueReference { declares the contract. The two lines inside are the required methods: getReferent(Name var1, Context var2) must return an object and may throw a NamingException, and toString() must return a string. Any class claiming to implement OpaqueReference must provide both.

The getReferent() method of ForeignOpaqueReference is called from WLNamingManager. In getObjectInstance(), if the passed-in boundObject implements the OpaqueReference interface, the object's getReferent() method is called as follows: boundObject = ((OpaqueReference)boundObject).getReferent(name, ctx);. Because ForeignOpaqueReference implements OpaqueReference, its getReferent() method is called, leading to the deserialisation vulnerability.

Java
package weblogic.[redacted];
public final class WLNamingManager {
	public static Object getObjectInstance(Object boundObject, Name name, Context ctx, Hashtable env) throws NamingException {
        if (boundObject instanceof ClassTypeOpaqueReference) {
						......
        } else if (boundObject instanceof OpaqueReference) {
            boundObject = ((OpaqueReference)boundObject).getReferent(name, ctx);
        } else if (boundObject instanceof LinkRef) {
      ...
        }
    }
}

Line by line: this is the same getObjectInstance() method as before, now showing the other branch. The first branch handles ClassTypeOpaqueReference and is elided. The second branch, } else if (boundObject instanceof OpaqueReference) {, catches any object that implements the interface, and boundObject = ((OpaqueReference)boundObject).getReferent(name, ctx); calls its getReferent() method. The third branch handles LinkRef, as in the previous bug. So the same method contains both attack paths, one per branch.

From the original on github.com

As with CVE-2023-21931, no malicious operation is executed during deserialisation. The vulnerability is triggered after deserialisation completes, by the lookup() call inside getReferent() in ForeignOpaqueReference.

The demonstration shows the CVE-2023-21839 exploit in Goby, again with command execution and shell access.

Root cause

Both bugs sit in WLNamingManager.getObjectInstance(), which takes an object that has just been deserialised and dispatches on its type. Two of those branches hand control to attacker-influenced data:

  • The LinkRef branch calls getLinkName() on the deserialised object and passes the returned string straight to ic.lookup(linkName). Because LinkRef is a native Java class whose constructor stores an arbitrary string as the LinkAddress reference address, the attacker controls the JNDI address that is looked up.
  • The OpaqueReference branch calls getReferent(name, ctx) on the deserialised object. ForeignOpaqueReference implements that interface and its getReferent() performs context.lookup(this.remoteJNDIName), with remoteJNDIName set through the constructor.

In both cases the deserialisation step itself is benign, which is why a review focused only on readObject() and similar methods misses them. The dangerous operation is the naming lookup that follows, reached through the lookup() path described above.

Impact

An attacker who can supply the serialised object to the naming service can cause WebLogic to perform a remote JNDI load from an address of their choosing. In the researchers' own tooling this was turned into command execution and shell access. The article does not state which versions are affected beyond the images listed, nor does it give a CVSS score or bounty.

Fix

Oracle fixed both issues: CVE-2023-21931 was officially fixed on 18 April 2023 and CVE-2023-21839 on 16 January 2023. The article does not describe the code change itself.

Variants to test

  • Other naming operations. Where bind() or rebind() does not trigger anything, try lookup() and lookupLink() against the same service. A positive result is a request that completes deserialisation and then causes an outbound JNDI connection to a host you control.
  • Other getObjectInstance() branches. The article notes both CVEs come from two branches of WLNamingManager.getObjectInstance(). Enumerate the remaining branches and check whether any of them call a method on the deserialised object that uses attacker-controlled fields. A positive result is a branch that reaches a lookup or similar remote fetch with a value taken from the object.
  • Other classes implementing OpaqueReference. ForeignOpaqueReference is one implementation; look for others whose getReferent() performs a remote operation using instance fields. A positive result is a class whose getReferent() reaches lookup() with a field set through its constructor.
  • Other classes extending Reference like LinkRef. Look for reference types whose stored address is returned by a getter and then passed to a lookup. A positive result is a getter whose return value flows into InitialContext.lookup() without validation.
  • Post-deserialisation timing. Instrument the deserialisation path to confirm that no malicious action occurs during readObject() and that the action happens only after the naming operation. A positive result is an outbound connection observed strictly after deserialisation returns.

Timeline

CVE-2023-21931:

  • 12 August 2022: vulnerability reported to official channels
  • 19 August 2022: vulnerability officially confirmed
  • 18 April 2023: vulnerability officially fixed

CVE-2023-21839:

  • 31 July 2022: vulnerability reported to official channels
  • 5 August 2022: vulnerability officially confirmed
  • 16 January 2023: vulnerability officially fixed

Glossary

  • API: a defined way for one program to ask another program to do something, like a menu of allowed requests.
  • Application server: software that runs web applications and answers requests on their behalf; WebLogic is one.
  • bind(): a naming operation that registers a name in the naming service.
  • Call stack: the chain of method calls currently in progress, showing how the program reached a given line.
  • Class: a blueprint in code from which objects are created at runtime.
  • Constructor: the special method that runs when an object is created, used to set its starting values.
  • CVE: a public catalogue number for a known security vulnerability.
  • CVSS: a standard scoring system for the severity of a vulnerability.
  • Deserialisation: rebuilding a live object in memory from a stream of bytes.
  • Docker: a tool that downloads and runs prebuilt software images, such as the Vulfocus machines used here.
  • ForeignOpaqueReference: a WebLogic class implementing OpaqueReference whose getReferent() looks up a remote JNDI name stored in one of its fields.
  • Goby: a security scanning tool used here to detect the bugs and demonstrate command execution and shell access.
  • getObjectInstance(): the method in WLNamingManager that receives a deserialised object and dispatches on its type; both bugs live in its branches.
  • getReferent(): the method required by the OpaqueReference interface; in ForeignOpaqueReference it performs the remote lookup.
  • instanceof: a Java check asking whether an object is an instance of a given class or interface.
  • Interface: a contract listing methods that any implementing class must provide.
  • Java: the programming language WebLogic and these classes are written in.
  • JNDI: Java Naming and Directory Interface, a standard way for Java programs to look things up by name, potentially on a remote server.
  • LinkRef: a native Java class that stores an address string under the label LinkAddress and returns it via getLinkName().
  • lookup(): a naming operation that fetches whatever is registered under a name; here it can cause an outbound connection.
  • lookupLink(): a naming operation that follows a link stored under a name.
  • Method: a named action a class can perform.
  • Object: one thing built from a class while the program runs.
  • OpaqueReference: a WebLogic interface requiring getReferent() and toString().
  • Post-deserialisation vulnerability: a flaw that does not fire while an object is being rebuilt, but in a later operation that uses the rebuilt object.
  • rebind(): a naming operation that replaces an existing name registration.
  • readObject(), readResolve(), readExternal(): Java methods that run while an object is being deserialised, the usual focus of deserialisation research.
  • Serialisation: turning a live object in memory into a stream of bytes.
  • Shell: an interactive command interface on a machine; obtaining one means running commands on the target.
  • Vulfocus: a collection of ready-made, deliberately vulnerable machines used for security testing.
  • WebLogic: Oracle's Java application server, the product affected by both bugs.
  • WLNamingManager: the WebLogic class whose getObjectInstance() method contains the branches exploited by both CVEs.

More from Oracle (WebLogic)

View all

The newest disclosed reports for this program.

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.