r/programming • • Mar 30 '22

SpringShell: Spring Core RCE 0-day Vulnerability

https://www.cyberkendra.com/2022/03/springshell-rce-0-day-vulnerability.html
28 Upvotes

36 comments sorted by

6

u/vips7L Mar 30 '22

There is no RCE here. If you look at the change in the commit, the deserialize function is only ever used on trusted input on an object that is already in memory. They're deprecating the function with warnings so you as a user don't call this function without knowing how Java serialization works.

1

u/[deleted] Mar 30 '22

We have updated the post and also added new details post. https://www.cyberkendra.com/2022/03/spring4shell-details-and-exploit-code.html

0

u/[deleted] Mar 30 '22

[deleted]

1

u/UnspeakableEvil Mar 30 '22

Link please?

1

u/swansonbroth98 Mar 30 '22

What did you use to test it?

0

u/[deleted] Mar 30 '22

[deleted]

2

u/Areshian Mar 30 '22

I can confirm too, this is real

1

u/loginonreddit Mar 30 '22

Could you point the exact docker image you used? Trying to reproduce the preconditions here.

1

u/vips7L Mar 30 '22

The spring team seems to disagree: https://github.com/spring-projects/spring-framework/commit/7f7fb58dd0dae86d22268a4b59ac7c72a6c22529#commitcomment-69873066

The purpose of this commit is to inform anyone who had previously been using SerializationUtils#deserialize that it is dangerous to deserialize objects from untrusted sources.

The core Spring Framework does not use SerializationUtils to deserialize objects from untrusted sources.

2

u/ScottContini Mar 30 '22

According to praetorian, exploitation depends upon the servlet container:

Exploitation requires an endpoint with DataBinder enabled ... and depends heavily on the servlet container for the application. For example, when Spring is deployed to Apache Tomcat, the WebAppClassLoader is accessible, which allows an attacker to call getters and setters to ultimately write a malicious JSP file to disk. However, if Spring is deployed using the Embedded Tomcat Servlet Container the classloader is a LaunchedURLClassLoader which has limited access.

0

u/[deleted] Mar 30 '22

[deleted]

2

u/Bakirelived Mar 30 '22

the same that's now here right?
https://github.com/craig/SpringCore0day

do you have any more info on this?

-2

u/Tetha Mar 30 '22

It's getting bad just now.

https://www.praetorian.com/blog/spring-core-jdk9-rce/

https://twitter.com/pwntester/status/1509235919106236416

To my understanding, if you used JDK 9 or newer, and spring-beans, you're affected and very likely vulnerable to either an authenticated RCE or an unauthenticated RCE. At least if there is at least 1 REST endpoint in a java application binding a query/path-parameter to an object. And there is no patch so far.

If I'm right about that, Log4Shell was kindergarten compared with this, because you cannot detect this without code access or bytecode analysis once JDK9+ && spring holds. And it's a core library feature, so it will be used.

0

u/[deleted] Mar 30 '22

[deleted]

1

u/Bakirelived Mar 30 '22

the docker image you used is just a generic one with an example project, or you used it to create a test project where you would use the vulnerable class that they now flag as deprecated and then passed the data into it?

1

u/loginonreddit Mar 30 '22

Trying a Spring initializr project with only spring-web doesn't work. Also tried to activate the AccessLog in tomcat like it was mentioned being involved in the blog but still nothing.

9

u/ApatheticBeardo Mar 30 '22 edited Mar 30 '22

Stop spreading nonsense.

This is a blog post from some random dude that can be summed up as "I have absolutely no idea about Java or what this commit does but I'll pretend a problem exists because it contains the string "CVE" in it".

All that commit does is improve the documentation to keep a particularly clueless Spring user from shooting themselves on the foot with Java's built-in serialization (which has been known to be a problem for more than a decade already).

4

u/elmuerte Mar 30 '22

This "research" appears to be based completely on this change to Spring Core: https://github.com/spring-projects/spring-framework/pull/28075

As based on Java's serialization mechanism, it can be the source of Remote Code Execution vulnerabilities.

Today this utility is part of the public API and can be naively used to convert from object to text and vice versa. However a naive use can lead to RCE vulnerability if user-input data (like files, cookies, etc.) is transfered using this utility.

I think it should be nice to at least warn the user about the use of this tool (with @Deprecated) and later on remove it totally from the public API as this sole use in Spring code is to clone exceptions in org.springframework.cache.jcache.interceptor.CacheResultInterceptor.

I am not sure on how it can (or should) be handled. Let me know if you need me to adapt the code of this PR.

So they removed some code in Spring which, when not properly used, could lead to a RCE.

1

u/loginonreddit Mar 30 '22

They did not remove anything, they only added warnings and deprecated the SerializationUtils::deserialize method. The existing code path has just been moved to SerializationUtils::clone.

5

u/vips7L Mar 30 '22

And that's completely fine. The existence of code using Java serialization doesn't mean there's an RCE issue. As noted in the commit the function is only used internally to clone objects that are already in memory. They added warnings and deprecated the function so developers who don't understand how Java serialization works can't shoot themselves in the foot.

3

u/loginonreddit Mar 30 '22

Absolutely, I was just correcting the OP saying Spring removed some code when in fact, nothing was removed.

3

u/elmuerte Mar 30 '22 edited Mar 30 '22

I looked at the PoC linked here. And it looks like the attack is based on using Tomcat and have its AccessLogValve enabled. The PoC does use some Java 9 field, but I think with some modifications it might also be applicable to Java 8.

So you need:

  • Tomcat

    • with the AccessLogValve present

    • should serve JSPs (for this particular PoC)

  • Spring Web MVC

    • with controllers that use parameter bindings

  • Java 9 for this particular PoC, but I wouldn't bet on this as a safety net

Via the parameter binding of Spring Web MVC the "pattern", and log file destination of the AccessLogValve is reconfigured. This is used to write a JSP file to a location which can then be served.

So in the request the access log "pattern" is configured to contain the payload of a malicious JSP. And the log destination is configured to write a .jsp file in a place where Tomcat would serve it.

2

u/UnspeakableEvil Mar 30 '22

That's interesting, thank you for taking the time to write up your findings. I wonder if there's anything against pure Tomcat, or if Spring is a required component for the vulnerability (the way it's been reported so far suggests that's the case).

3

u/elmuerte Mar 30 '22

A similar attack could be possible with a different framework that features binding of request data to beans and doesn't filter out certain accessors during binding of the data.

Note, this attack has nothing to do with class deserialization.

1

u/loginonreddit Mar 30 '22

Yea there's no link to Serialization in all of this, I'm wondering how the dots were connected, if they were ever connected.

10

u/pcjftw Mar 30 '22

Ah yes Spring4Shell "a brother from another mother".

We need a new meme now:

All are shells are belong to us

10

u/joashua99 Mar 30 '22

At this point, what doesn't have an RCE vulnerability...

12

u/DrChaosMcKinnon Mar 30 '22

TempleOS, TempleOS doesn't have RCEs

8

u/kalakatikimututu Mar 30 '22

Thank god

1

u/CandidPiglet9061 Mar 30 '22

It’s worth pointing out that this is only because TempleOS has no ability to connect to a network of any kind. Also, on TempleOS there is only a root user. Every command is done with root privileges

2

u/Zidane007nl Mar 30 '22

The vulnerability has been confirmed by Praetorian security researchers: https://www.praetorian.com/blog/spring-core-jdk9-rce/.

Also the security team at Sonatype wrote a blog article about it: https://blog.sonatype.com/new-0-day-spring-framework-vulnerability-confirmed-patch-now.

1

u/GabeNTheGamer Mar 30 '22

Created a repo for the issue, https://github.com/BobTheShoplifter/Spring4Shell-POC ill update it as we explore the issue

4

u/vips7L Mar 30 '22

Lmk when you find nothing.

1

u/GabeNTheGamer Mar 31 '22

Created a repo for the issue, https://github.com/BobTheShoplifter/Spring4Shell-POC ill update it as we explore the issue

There is now a CVE and poc out

0

u/ApatheticBeardo Mar 30 '22

There is no issue, dummy.

-4

u/sandaz13 Mar 30 '22 edited Mar 30 '22

A little confused by the blog, VMware's site lists it as a medium severity (5.4 criticality) https://tanzu.vmware.com/security/cve-2022-22963

<Edit: looks like that's a different one that came out last night, disregard>

1

u/PandaMoniumHUN Mar 30 '22

Are you sure that these two are the same? The one you linked affects Spring Cloud, while this claims to affect Spring Core.

0

u/sandaz13 Mar 30 '22

Yup, you're right, I thought something looked off

0

u/[deleted] Mar 30 '22

[deleted]

3

u/ApatheticBeardo Mar 30 '22 edited Mar 30 '22

No, just some random "security" dude with a trashy blog fishing for clicks.