Example Vulnerable Code

Let us consider a simple JNDI Java API javax.naming.InitialContext.lookup(String name)

@GetMapping("/lookup")
public Object lookup(@RequestParam("name") String name) throws Exception {
	return new javax.naming.InitialContext().lookup(name);
}

Exploiting JNDI Injections before JDK 1.8.0_191

Exploiting JNDI injections in JDK 1.8.0_191+

Solution

The actual problem here is not within the JDK or Apache Tomcat library, but rather in custom applications that pass user-controllable data to the “InitialContext.lookup()” function, as it still represents a security risk even in fully patched JDK installations. Keep in mind that other vulnerabilities (such as ‘Deserialisation of untrusted data’ for example) may also lead to JNDI resolution in many cases. Preventing these vulnerabilities by using a source code review is always a good idea.

Resources