Spring Framework
Last updated
Last updated
Spring is an application framework and inversion of control container for the Java platform.
We can attempt to trigger an error on the website as a method of fingerprinting. If the error results in a "Whitelabel Error Page," this indicates that the website is running Spring Boot.
spring4shell-scan is a fully automated, reliable, and accurate scanner for finding Spring4Shell and Spring Cloud RCE vulnerabilities
Routing misconfigurations in the Spring Framework can pose significant security risks, potentially leading to protected URL bypass, path traversal, or information leaks.
Spring Routing AbuseThe Spring Boot Framework includes a number of features called actuators to help you monitor and manage your web application when you push it to production. Intended to be used for auditing, health, and metrics gathering, they can also open a hidden door to your server when misconfigured.
Spring Boot ActuatorsSpring application that uses Thymeleaf as its templating engine, if template name or fragment is concatenated with untrusted data, it can lead to expression language injection and hence RCE.
Spring View ManipulationSpring4Shell is a vulnerabilitiy to remote code execution in the Spring Framework. It affects a component in Spring Core which is the heart of the framework.
Current conditions for vulnerability (as stated in Spring's announcement of the vulnerability) can be summarised as follows:
JDK 9+
A vulnerable version of the Spring Framework (<5.2 | 5.2.0-19 | 5.3.0-17)
Apache Tomcat as a server for the Spring application, packaged as a WAR
A dependency on the spring-webmvc
and/or spring-webflux
components of the Spring Framework
We may use BobTheShoplifter's exploit
Alternatively, we may use me2nuk's exploit
Alternatively, we may use Leovalcante's exploit
In Spring Cloud Function versions 3.1.6, 3.2.2 and older unsupported versions, when using routing functionality it is possible for a user to provide a specially crafted SpEL as a routing-expression that may result in remote code execution and access to local resources.
We can easily exploit it by hand
If there is an input form, such as a search form, or URL parameter which the parameter is reflected in the website, you may be able to find the vulnerability to the server-side template injection.
Try them:
Then you can also check more about that.
Software frameworks sometime allow developers to automatically bind HTTP request parameters into program code variables or objects to make using that framework easier on developers. This can sometimes cause harm.
This functionality becomes exploitable when:
Attacker can guess common sensitive fields.
Attacker has access to source code and can review the models for sensitive fields.
AND the object with sensitive fields has an empty constructor.
Suppose there is a form for editing a user's account information:
Here is the object that the form is binding to:
Here is the controller handling the request:
Using the mass assignment vulnerability, we can set the value of the attribute isAdmin of the instance of the class User:
The Spring Expression Language (SpEL for short) is a powerful expression language that supports querying and manipulating an object graph at runtime. SpEL injection occurs when user controlled data is passed directly to the SpEL expression parser.
For instance, the following method uses the standard context to evaluate SpEL expression:
As a result, you can gain code execution by sending the following POST
request:
If you have access to a source code, try to search for vulnerable code using the following keywords:
SpelExpressionParser
, EvaluationContext
, parseExpression
, @Value("#{ <expression string> }")
#{ <expression string> }
, ${<property>}
, T(<javaclass>)
If a source code is not available, it is worth checking the metrics
and beans
endpoints provided by the Spring Boot actuators. These endpoints can expand the list of available beans and the parameters they accept.
This vulnerability requires the following conditions:
Spring Boot version 1.1.0 - 1.1.12
, 1.2.0 - 1.2.7
, 1.3.0
There is at least one interface that triggers the default whitelabel error page in Spring Boot
Check the next Spring Boot application: LandGrey/springboot-spel-rce. If you send a request to /article?id=hop
, the application will return a whitelabel error with code 500
. However, if you send a request to /article?id=${7*7}
, the application returns an error page with the calculated value 49
.
As a result, it leads to RCE and you can execute arbitrary commands first by preparing the payload with the next python scrypt (this sample prepares a payload that executes open -a Calculator
command):
Send the payload within the id
parameter, open -a Calculator
will be executed:
The SimpleEvaluationContext
context prevents arbitrary code executing and writes a error message. However, you still can exploit the ReDoS attack.
Spring Data Redis, part of the larger Spring Data family, provides easy configuration and access to Redis from Spring applications. Spring Data Redis first serializes data before writing data to Redis. By default, Java native serialization is used for serialization.
When Spring Data Redis retrieves data from Redis, the stored bytecode is deserialized. Since the target class is not checked or filtered during deserialization it can lead to remote code execution.
Read this article for more details