Objective: Gain Unauthorized Access (Data, Functionality, or Server)
Goal: Gain Unauthorized Access (Data, Functionality, or Server)
├── 1. Exploit Spring Expression Language (SpEL) Injection [HIGH-RISK]
│ ├── 1.1. Unvalidated User Input in SpEL Expressions (MVC/Thymeleaf)
│ │ └── 1.1.3. Execute arbitrary code (RCE) or access sensitive data via SpEL. [CRITICAL]
│ └── 1.3. SpEL Injection in Spring Data Repositories (e.g., `@Query` annotation)
│ └── 1.3.3. Exfiltrate data or modify database content beyond intended scope. [CRITICAL]
├── 2. Leverage Spring Security Misconfigurations [HIGH-RISK]
│ ├── 2.1. Weak or Default Authentication/Authorization
│ │ └── 2.1.4. Bypass authentication using known default accounts or weak passwords. [CRITICAL]
│ ├── 2.3. CSRF Protection Disabled or Misconfigured
│ │ └── 2.3.3. Perform state-changing actions on behalf of the victim user. [CRITICAL]
│ ├── 2.4. Insufficient Authorization Checks
│ │ └── 2.4.3. Access resources or execute actions without proper authorization. [CRITICAL]
│ └── 2.5. Exposure of Sensitive Information via Actuator Endpoints [HIGH-RISK]
│ └── 2.5.2. Access sensitive information like environment variables, database credentials, or heap dumps. [CRITICAL]
├── 3. Exploit Spring Data Vulnerabilities
│ ├── 3.1. Unsafe Deserialization in Spring Data REST
│ │ └── 3.1.3. Achieve Remote Code Execution (RCE). [CRITICAL]
│ ├── 3.2. SQL Injection through Custom Repository Implementations (if not using parameterized queries)
│ │ └── 3.2.3. Exfiltrate data, modify database content, or gain database access. [CRITICAL]
│ └── 3.3 Query Injection in Spring Data JPA/MongoDB (if using native queries without proper sanitization)
│ └── 3.3.3 Bypass intended data access restrictions or retrieve unauthorized data. [CRITICAL]
├── 4. Exploit Spring Boot Auto-Configuration Weaknesses
│ └── 4.2. Dependency Management Issues (Vulnerable Dependencies) [HIGH-RISK]
│ └── 4.2.3. Achieve RCE, data breaches, or other attacks depending on the vulnerability. [CRITICAL]
└── 5. Exploit Spring Cloud Vulnerabilities (if used)
├── 5.1. Spring Cloud Config Server Path Traversal
│ └── 5.1.3. Retrieve sensitive configuration files or other system files. [CRITICAL]
├── 5.2. Spring Cloud Gateway SpEL Injection
│ └── 5.2.3. Achieve RCE or bypass security restrictions. [CRITICAL]
└── 5.3. Vulnerabilities in other Spring Cloud components (e.g., Eureka, Zuul)
└── 5.3.3. Disrupt service discovery, routing, or other microservices functionalities. [CRITICAL]
Attack Tree Path: 1. Exploit Spring Expression Language (SpEL) Injection [HIGH-RISK]
-
1.1.3. Execute arbitrary code (RCE) or access sensitive data via SpEL. [CRITICAL]
- Description: An attacker successfully injects a malicious SpEL payload into an application that uses SpEL to evaluate user-provided input without proper validation or sanitization. This typically occurs in web forms or URL parameters within Spring MVC or Thymeleaf templates.
- How it works:
- The attacker crafts a SpEL expression designed to execute system commands or access internal objects/data. Examples:
T(java.lang.Runtime).getRuntime().exec('command')
,${systemProperties}
. - The attacker submits this payload through a vulnerable input field.
- The application, lacking proper input validation, passes the malicious SpEL expression to the SpEL evaluator.
- The SpEL evaluator executes the attacker's code, leading to RCE or unauthorized data access.
- The attacker crafts a SpEL expression designed to execute system commands or access internal objects/data. Examples:
- Mitigation:
- Strict Input Validation: Validate all user input using a whitelist approach (allow only known-good characters and patterns). Reject any input that doesn't conform to the expected format.
- Input Sanitization: Escape or encode any special characters that have meaning within SpEL.
- Avoid Dynamic SpEL: Minimize the use of dynamically generated SpEL expressions based on user input. If unavoidable, use a tightly controlled context with limited access to objects and methods.
- Whitelisting SpEL Functions: If you must use SpEL, restrict the available functions and objects to the absolute minimum required.
- Use a Safer Templating Engine: Consider alternatives to Thymeleaf that don't rely on SpEL for dynamic content generation if SpEL's full power isn't needed.
-
1.3.3. Exfiltrate data or modify database content beyond intended scope. [CRITICAL]
- Description: An attacker injects a malicious SpEL payload into a Spring Data repository query (often through the
@Query
annotation) that uses dynamic SpEL expressions. - How it works:
- The application uses a Spring Data repository with a method annotated with
@Query
that incorporates user input into a SpEL expression without proper sanitization. - The attacker provides crafted input that manipulates the SpEL expression to alter the query's logic.
- The modified query executes against the database, potentially returning data the attacker shouldn't have access to or modifying data in unintended ways.
- The application uses a Spring Data repository with a method annotated with
- Mitigation:
- Avoid Dynamic SpEL in
@Query
: Prefer using JPQL or Criteria API for dynamic queries, and always use parameterized queries or named parameters. Never directly concatenate user input into the query string. - Input Validation and Sanitization: If dynamic SpEL is absolutely necessary, rigorously validate and sanitize all user input before incorporating it into the SpEL expression.
- Least Privilege: Ensure the database user account used by the application has only the minimum necessary permissions.
- Avoid Dynamic SpEL in
- Description: An attacker injects a malicious SpEL payload into a Spring Data repository query (often through the
Attack Tree Path: 2. Leverage Spring Security Misconfigurations [HIGH-RISK]
-
2.1.4. Bypass authentication using known default accounts or weak passwords. [CRITICAL]
- Description: An attacker gains unauthorized access by exploiting default credentials (e.g., "admin/admin", "user/password") that were not changed during deployment or by guessing weak passwords due to a lax password policy.
- How it works:
- The attacker attempts to log in using common default credentials.
- Or, the attacker uses password guessing or brute-force techniques against accounts with weak passwords.
- Mitigation:
- Change Default Credentials: Always change default credentials immediately after installation or deployment.
- Strong Password Policy: Enforce a strong password policy that requires a minimum length, complexity (uppercase, lowercase, numbers, symbols), and regular password changes.
- Account Lockout: Implement account lockout after a certain number of failed login attempts to prevent brute-force attacks.
- Multi-Factor Authentication (MFA): Implement MFA to add an extra layer of security.
-
2.3.3. Perform state-changing actions on behalf of the victim user. [CRITICAL]
- Description: An attacker exploits a Cross-Site Request Forgery (CSRF) vulnerability to trick a logged-in user into performing actions they did not intend. This happens when CSRF protection is disabled or misconfigured.
- How it works:
- The attacker crafts a malicious website or email containing a hidden request to the vulnerable application.
- The victim user, who is already authenticated to the vulnerable application, visits the attacker's website or clicks the malicious link.
- The user's browser, unknowingly, sends the forged request to the vulnerable application.
- The application, lacking CSRF protection, processes the request as if it came from the legitimate user, performing the attacker-specified action (e.g., changing email, transferring funds).
- Mitigation:
- Enable CSRF Protection: Enable Spring Security's built-in CSRF protection. It's usually enabled by default, but ensure it hasn't been accidentally disabled.
- Synchronizer Token Pattern: Ensure that the application uses the synchronizer token pattern correctly. This involves generating a unique, unpredictable token for each session and including it in all state-changing requests.
- Double Submit Cookie: Consider using the double-submit cookie pattern as an additional defense, especially for applications that cannot easily use the synchronizer token pattern.
-
2.4.3. Access resources or execute actions without proper authorization. [CRITICAL]
- Description: An attacker gains access to resources or functionality they should not be authorized to use, due to missing or incorrectly configured authorization checks.
- How it works:
- The application fails to properly check user roles or permissions before granting access to a resource or allowing an action to be performed. This can be due to missing
@PreAuthorize
,@PostAuthorize
, or@Secured
annotations, or incorrect configuration of role-based access control (RBAC).
- The application fails to properly check user roles or permissions before granting access to a resource or allowing an action to be performed. This can be due to missing
- Mitigation:
- Consistent Authorization Checks: Apply authorization checks consistently across all sensitive endpoints and methods. Use
@PreAuthorize
,@PostAuthorize
, or@Secured
annotations to enforce role-based or permission-based access control. - Principle of Least Privilege: Grant users only the minimum necessary permissions to perform their tasks.
- Regular Security Audits: Conduct regular security audits and code reviews to ensure that authorization checks are correctly implemented and enforced.
- Consistent Authorization Checks: Apply authorization checks consistently across all sensitive endpoints and methods. Use
-
2.5.2. Access sensitive information like environment variables, database credentials, or heap dumps. [CRITICAL]
- Description: An attacker accesses sensitive information exposed through unprotected Spring Boot Actuator endpoints.
- How it works:
- The application exposes Actuator endpoints (e.g.,
/actuator/env
,/actuator/heapdump
,/actuator/configprops
) without proper authentication or authorization. - The attacker sends HTTP requests to these endpoints and retrieves sensitive information.
- The application exposes Actuator endpoints (e.g.,
- Mitigation:
- Secure Actuator Endpoints: Secure Actuator endpoints using Spring Security. Require authentication and authorization for access.
- Disable Unnecessary Endpoints: Disable any Actuator endpoints that are not strictly required for production monitoring.
- Restrict Access by IP Address: If possible, restrict access to Actuator endpoints to specific IP addresses (e.g., monitoring servers).
- Customize Endpoint Exposure: Use
management.endpoints.web.exposure.include
andmanagement.endpoints.web.exposure.exclude
properties to control which endpoints are exposed.
Attack Tree Path: 3. Exploit Spring Data Vulnerabilities
-
3.1.3. Achieve Remote Code Execution (RCE). [CRITICAL] * Description: An attacker sends a crafted request containing a malicious serialized object to a Spring Data REST endpoint, triggering unsafe deserialization and leading to remote code execution. * How it works:
- The application uses a vulnerable version of a library that performs unsafe deserialization of user-provided data (e.g., an older version of Jackson or a library with a known deserialization vulnerability).
- The attacker crafts a malicious serialized object that, when deserialized, executes arbitrary code.
- The attacker sends this object as part of a request to a Spring Data REST endpoint.
- The application deserializes the object, triggering the execution of the attacker's code. * Mitigation:
- Avoid Unsafe Deserialization: Avoid deserializing untrusted data whenever possible.
- Use Safe Deserialization Libraries: Use secure deserialization libraries and configure them to prevent unsafe deserialization. For example, use a whitelist of allowed classes for deserialization.
- Keep Libraries Up-to-Date: Regularly update all dependencies, including Spring Data REST and any libraries used for serialization/deserialization, to patch known vulnerabilities.
- Input Validation: Validate and sanitize all incoming data, even if it's expected to be serialized.
-
3.2.3. Exfiltrate data, modify database content, or gain database access. [CRITICAL]
- Description: An attacker exploits a SQL injection vulnerability in a custom Spring Data repository implementation that uses string concatenation to build SQL queries.
- How it works:
- The application uses a custom repository implementation with a method that constructs SQL queries by concatenating user input without using parameterized queries or prepared statements.
- The attacker provides crafted input that includes malicious SQL code.
- The application executes the concatenated query, including the attacker's SQL code, leading to unauthorized data access, modification, or even database server compromise.
- Mitigation:
- Parameterized Queries: Always use parameterized queries or prepared statements when constructing SQL queries. This prevents attackers from injecting malicious SQL code.
- ORM Framework: Utilize the features of your ORM framework (e.g., JPA, Hibernate) to build queries safely.
- Input Validation: Validate and sanitize all user input, even if you're using parameterized queries, as an additional layer of defense.
-
3.3.3 Bypass intended data access restrictions or retrieve unauthorized data. [CRITICAL]
- Description: Similar to SQL injection, but targets NoSQL databases (like MongoDB) when using native queries in Spring Data without proper sanitization.
- How it works:
- The application uses native queries (e.g., with
@Query
in Spring Data MongoDB) and constructs these queries using unsanitized user input. - The attacker crafts input that manipulates the query logic, allowing them to bypass intended filters or access data they shouldn't.
- The application uses native queries (e.g., with
- Mitigation:
- Use QueryDSL or Criteria API: Prefer using type-safe query builders like QueryDSL or the Criteria API provided by Spring Data, which are less susceptible to injection.
- Parameterized Queries (where applicable): If using native queries, use parameterized queries or the equivalent mechanism provided by your NoSQL database driver to prevent injection.
- Input Validation and Sanitization: Rigorously validate and sanitize all user input before incorporating it into any query, even if using parameterized queries.
Attack Tree Path: 4. Exploit Spring Boot Auto-Configuration Weaknesses [HIGH-RISK]
- 4.2.3. Achieve RCE, data breaches, or other attacks depending on the vulnerability. [CRITICAL]
- Description: An attacker exploits a known vulnerability in a dependency managed by Spring Boot.
- How it works:
- The application uses a Spring Boot version that includes a vulnerable dependency (e.g., a library with a known RCE vulnerability).
- The attacker identifies the vulnerability (e.g., through public vulnerability databases) and crafts an exploit.
- The attacker sends the exploit to the application, triggering the vulnerability and achieving RCE, data exfiltration, or other malicious actions.
- Mitigation:
- Dependency Scanning: Use a software composition analysis (SCA) tool or dependency vulnerability scanner (e.g., OWASP Dependency-Check, Snyk, Dependabot) to identify vulnerable dependencies.
- Regular Updates: Regularly update Spring Boot and all its managed dependencies to the latest stable versions. Subscribe to security advisories for Spring and related projects.
- Vulnerability Management Process: Establish a process for promptly addressing identified vulnerabilities, including patching, upgrading, or mitigating the risk.
Attack Tree Path: 5. Exploit Spring Cloud Vulnerabilities (if used)
-
5.1.3. Retrieve sensitive configuration files or other system files. [CRITICAL]
- Description: An attacker exploits a path traversal vulnerability in Spring Cloud Config Server to access files outside the intended configuration directory.
- How it works:
- The application uses a vulnerable version of Spring Cloud Config Server.
- The attacker crafts a request with ".." sequences in the URL to navigate to directories outside the configured configuration repository.
- The server, lacking proper input validation, serves the requested file, potentially exposing sensitive configuration data or other system files.
- Mitigation:
- Update Spring Cloud Config Server: Update to a patched version of Spring Cloud Config Server that addresses the path traversal vulnerability.
- Input Validation: Implement input validation to prevent path traversal attacks. Reject any requests containing ".." or other suspicious path segments.
- Least Privilege: Ensure that the user account running the Config Server has only the minimum necessary file system permissions.
-
5.2.3. Achieve RCE or bypass security restrictions. [CRITICAL]
- Description: An attacker injects a malicious SpEL payload into a Spring Cloud Gateway route that uses dynamic SpEL expressions.
- How it works:
- The application uses Spring Cloud Gateway with routes that dynamically generate SpEL expressions based on user input (e.g., in filters or predicates).
- The attacker crafts a request with a malicious SpEL payload in a header or parameter.
- The gateway, lacking proper input validation, evaluates the malicious SpEL expression, leading to RCE or bypassing security restrictions.
- Mitigation:
- Avoid Dynamic SpEL: Avoid using dynamically generated SpEL expressions in Spring Cloud Gateway routes. If unavoidable, use a tightly controlled context with limited access.
- Input Validation and Sanitization: Rigorously validate and sanitize all user input before incorporating it into any SpEL expression.
- Whitelisting SpEL Functions: Restrict the available SpEL functions and objects to the absolute minimum required.
- Update Spring Cloud Gateway: Keep Spring Cloud Gateway up-to-date to address any known SpEL injection vulnerabilities.
-
5.3.3. Disrupt service discovery, routing, or other microservices functionalities. [CRITICAL]
- Description: An attacker exploits a vulnerability in other Spring Cloud components (like Eureka for service discovery or Zuul for routing) to disrupt the microservices architecture.
- How it works: The specifics depend on the particular vulnerability in the component. It could involve sending malformed requests, exploiting known bugs, or leveraging misconfigurations.
- Mitigation:
- Keep Components Updated: Regularly update all Spring Cloud components to the latest stable versions to patch known vulnerabilities.
- Security Hardening: Follow security best practices for configuring each component. This includes proper authentication, authorization, and input validation.
- Monitoring: Monitor the health and behavior of your Spring Cloud components to detect any anomalies or suspicious activity.
- Vulnerability Scanning: Use vulnerability scanners to identify potential weaknesses in your Spring Cloud infrastructure.