Skip to content
RCE Write-up Advanced

JNDI Injection Remote Code Execution via Path Manipulation in MemoryUserDatabaseFactory

The MemoryUserDatabaseFactory class in Apache Tomcat allows an attacker to control the pathname and readonly properties via JNDI, leading to an arbitrary file write. By bypassing the isWriteable check with a directory creation primitive, an attacker can write a JSP file and achieve remote code execution.

Steven Seeley Follow

Published on srcincite.io

In this blog post, I’m going to describe a relative new vector to achieve remote code execution via a JNDI Injection that I found independently to other researchers. The concept of exploiting an object lookup process for a JNDI injection is nothing new.

Steven Seeley (@steventseeley), on srcincite.io

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.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the MemoryUserDatabaseFactory does not properly validate the pathname and readonly properties from the JNDI reference, allowing an attacker to set them and trigger a file write.

What the attacker needed

JNDI injection vulnerability; Tomcat catalina and velocity libraries; Writeable current working directory; Ability to trigger JNDI lookup twice

How it was found

  1. Create an RMI registry and bind two objects: one to create a directory using FileUtil.mkdir, and one to trigger the file write via MemoryUserDatabaseFactory.
  2. Trigger a JNDI lookup to the first object to create the required directory structure.
  3. Trigger a second JNDI lookup to the second object, which sets readonly to false and pathname to a path that escapes to a web-accessible directory.
  4. The MemoryUserDatabaseFactory downloads an XML file from the attacker's server and parses it, then writes a JSP file containing the attacker's payload to the target location.
  5. Access the written JSP file to execute arbitrary code.

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 write-up has not been written yet. The Original tab links to the source.

What is RCE?

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

More by Steven Seeley

View all

6 more disclosed reports, best first.

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.