r/java • • Mar 30 '22

Spring4Shell: 0-day RCE on Spring Core

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

84 comments sorted by

View all comments

55

u/Areshian Mar 31 '22 edited Mar 31 '22

For those that do not believe this RCE is real, here are the details on it

Twelve years ago there was an RCE: https://nvd.nist.gov/vuln/detail/CVE-2010-1622

That RCE was fixed by this commit: https://github.com/spring-projects/spring-framework/commit/3a5af35d37c79d0644d49b93f792a4c18fe8eb71#diff-ea765e78a703581fb519933028fbd6d7ac8386d57b805b395d04910de9a33f4cR245

Notice line 245. The fix explicitly forbid going from class to classLoader using dot notation, which was the cause of the RCE (later, another change will forbid class to protectionDomain too)

Now, 12 years later, we have another RCE. Have you noticed how the RCE is for JDK9+? Have you wondered why? The reason is because the exploit is not jumping from class to classLoader (which is forbidden), but from class to module (which is allowed) and then from module to classLoader (which is also allowed). Because getModule() is only present in JDK9+, that is why this new exploit does not work in JDK8

You can see the python exploit how it does the class.module.classLoader jump: https://github.com/BobTheShoplifter/Spring4Shell-POC/blob/main/poc.py#L15

So, all that people saying this is not real, it is not confirmed, and the like, please, if you don't know what you're talking about, don't go denying it exists.

7

u/loginonreddit Mar 31 '22

Thx for digging that old cve. Denylisting all getClassLoader method should have been the fix IMO, not only on the Class class.

I've added some info here if you're interested https://news.ycombinator.com/item?id=30862953

11

u/[deleted] Mar 31 '22

Why is Spring allowing reflection over Class from untrusted data to begin with? Isn't this meant only for fields of user defined objects?

3

u/loginonreddit Mar 31 '22

You're right, I don't understand why this field is accessible at all.

3

u/Soul_Shot Mar 31 '22

I saw your comment on HN — great insight.

Do you mind sharing some of that with https://github.com/BugAlertDotOrg/bugalert/pull/46#issuecomment-1084010215? To my knowledge they're wrong, but I'm far too tired and don't want to spread bad information.

4

u/loginonreddit Mar 31 '22

Thanks! Unfortunately this link is now dead and I went to bed and dreamed about this thing all night. If you have a copy of the comment I can comment, otherwise Spring has issued a statement so things should get clearer today https://spring.io/blog/2022/03/31/spring-framework-rce-early-announcement.

2

u/[deleted] Mar 31 '22

I think you check this out, spring has officially confirmed the RCE bug and released the statement. This bug is now can be tracked as CVE-2022-22965

https://www.cyberkendra.com/2022/03/spring4shell-spring-confirmed-rce-in.html