Live data from Hacker News

Spring Core on JDK9 is vulnerable to remote code execution

praetorian.com

61–70 of 73 posts

Re: Spring Core on JDK9 is vulnerable to remote code execution

#61
post #45

There is a lot of bad information out there about this issue. What I have gathered so far, is that this is actually a real problem, but it may not affect most configurations. This[0] seems to be the original vulnerability analysis, and this is the example vulnerable app[1]. The main issue seems to be, that since java 9, WebDataBinder can be abused to access the classloader via the "class.module.classloader", you migh…

> output an arbitrary JSP file So i appreciate that this is only an example of a gadget, and there are others that could be invoked in the same way, but ... > to the webapp root directory This is only possible if the application is running from an exploded WAR. That can happen if the developer deploys an exploded WAR - normal in development, extremely strange in production - or if the application server explodes the…

The default config for tomcat is to explode the WAR, even in the most recent version.

Re: Spring Core on JDK9 is vulnerable to remote code execution

#62

Earlier quoted context omitted.

JDK9+ is important because Spring already prevents access to `class.classloader`, but it can be worked around thanks to modules (i.e. `class.module.classloader` works).

Yes but there may be some other Gadget vulnerabilities in all those fields too. Also, you might be able to make an app OOM by setting big string values somewhere in there. It boggles my mind why this field is accessible at all and wasn't blocked in CVE-2010-1622.

You can make an app OOM by setting big string values anywhere. You gotta handle that at a higher level and reject requests larger than a certain size, which there is already a default for.

Re: Spring Core on JDK9 is vulnerable to remote code execution

#63
post #15

Fortunately very few companies of any size use jdk9+

Unfortunately you're wrong. While some companies haven't yet made the leap from 8 to 11, most have. You'll find that Java 8 support is being deprecated if not outright removed across the JVM ecosystem.

Can you point me to surveys to back up this claim? I interview lots of people from lots of companies, no one is using anything above java 8. Sure this evidence is anecdotal, but i've probably got evidence from around 150 companies.

Re: Spring Core on JDK9 is vulnerable to remote code execution

#64
post #46
post #43

Earlier quoted context omitted.

I'll ask my engineers to post the one he wrote. He did put more details into the article, so go check that. Here is a repo with a POC though: https://github.com/TheGejr/SpringShell

That’s not really a POC though. That’s not a Spring Application I can run and reproduce on. That’s just a py script.

Check the post again. We made a repo with a full end to end vulnerable app and POC

Re: Spring Core on JDK9 is vulnerable to remote code execution

#65
post #9

Earlier quoted context omitted.

LunaSec founder here. I can understand the suspicion. It's the right mindset to have when looking at CVEs, in general, because 99% of them are overblown. The first title I wrote for the blog post was "There is no vuln" but I was wrong. Only after I spent a few hours digging did my gut change my mind. In this case I wrote the post to discuss 2 different vulns. One was a confirmed RCE with a CVE and the other was a WIP…

The exploit PoC that is doing the rounds works on full tomcat, not embedded tomcat, so if your example vulnerable application is using embedded tomcat that exploit won't work on it without being tweaked. I've looked at it today as well, for most of the day. Embedded tomcat doesn't have a webapps directory, whereas the full version of tomcat does, so the PoC writes the webshell to webapps/ /tomcatwar.jsp and that is s…

I just came to the same conclusion after some debugging. On embedded tomcat there is no access to resources and thus the popular PoC floating around doesn’t work. I left off for the night exploring getters/setters on the URL object returned on the URLs[0] call. On Java 11 there were some interesting getters/setters I want to explore. Let me know if you find a working PoC. Fun stuff!

Re: Spring Core on JDK9 is vulnerable to remote code execution

#66

Earlier quoted context omitted.

JDK9+ is important because Spring already prevents access to `class.classloader`, but it can be worked around thanks to modules (i.e. `class.module.classloader` works).

Yes but there may be some other Gadget vulnerabilities in all those fields too. Also, you might be able to make an app OOM by setting big string values somewhere in there. It boggles my mind why this field is accessible at all and wasn't blocked in CVE-2010-1622.

I spent a good amount of time trying to find some gadgets on jdk8 today no dice besides some DoS

Re: Spring Core on JDK9 is vulnerable to remote code execution

#67
post #53

Earlier quoted context omitted.

> The main benefit is updating the webapps w/o restarting the server, itself. I've never had this work properly in the long term, to be honest. Restarts with the Jenkins plugin would randomly freeze and fail or there would be memory leaks after too many restarts, or weird errors about it not being possible to properly clear up the resources from previously exploded/extracted .war archives. Though i might have just be…

There are many things that must go right. Threads being the primary one - don't start threads, pretty much anything that can start threads (outside the webapp) have to guard for the CCL and the thread group at the very least. The entire app must have a clear start/stop lifecycle correctly implemented. Static registrations in non-webapp services must be removed, and/or those services must use weak references. The list…

While this is possible, it takes ages for an application to gracefully shutdown so any time you save not having to start up a new server is lost. And then you still have classloader, memory and thread leaks since you can't really prove they are absent unless you have 100% test coverage + load testing on every possible code path.

Modern Java webservers (even 'enterprise' containers like JBoss etc) start up so quickly now there's not much to gain by not restarting them.

Re: Spring Core on JDK9 is vulnerable to remote code execution

#68
post #67
post #53

Earlier quoted context omitted.

There are many things that must go right. Threads being the primary one - don't start threads, pretty much anything that can start threads (outside the webapp) have to guard for the CCL and the thread group at the very least. The entire app must have a clear start/stop lifecycle correctly implemented. Static registrations in non-webapp services must be removed, and/or those services must use weak references. The list…

While this is possible, it takes ages for an application to gracefully shutdown so any time you save not having to start up a new server is lost. And then you still have classloader, memory and thread leaks since you can't really prove they are absent unless you have 100% test coverage + load testing on every possible code path. Modern Java webservers (even 'enterprise' containers like JBoss etc) start up so quickly…

>And then you still have classloader, memory and thread leaks since you can't really prove they are absent unless you have 100% test coverage + load testing on every possible code path.

Those are trivially proven and diagnosed with memory dumps or even "jmap -histo"(incl. where the leak started). Zero test coverage for that needed. Some bugs were even in JDK where it'd start a new thread in a threadpool and copy all the CCL/Threadgroup/ACL and any inheritable thread local.

Re: Spring Core on JDK9 is vulnerable to remote code execution

#69

Earlier quoted context omitted.

Any kind of writable reflection facility, and any kind of eval() should be added to the set of "unsafe" features.

At some point, mvc frameworks have to do some magic to dynamically load classes. This should be done at runtime, but can’t imagine it’s an easy problem to solve.

No they don’t, MVC has existed in C++ for decades. The problem is specific to reflection based MVC frameworks (objc has similar issues).

The solution is to explicitly specify every class that can be instantiated at compile time. Similar to how modern deserialization frameworks work. No code should be written that allows content from the network to explicitly specify arbitrary code to load and execute. E.g having a packet say and feeding the string “MyView” into some classloader, or dlsym, or whatever is asking for trouble. Feeding it into

    switch (view.class) {
       case “MyView”: return new MyView() … }
Results in a much less powerful primitive

Re: Spring Core on JDK9 is vulnerable to remote code execution

#70

Earlier quoted context omitted.

At some point, mvc frameworks have to do some magic to dynamically load classes. This should be done at runtime, but can’t imagine it’s an easy problem to solve.

Not my field, but how can this be so? We had MVC in 1990 written in C or C++.

In principle I think you could do something like this with COM, but I’m unaware of any such framework
Post reply on HN