Skip to content

Latest commit

 

History

History
107 lines (97 loc) · 7.74 KB

File metadata and controls

107 lines (97 loc) · 7.74 KB

Attack Tree Analysis for apache/commons-lang

Objective: Achieve RCE or DoS via Commons Lang 3

Attack Tree Visualization

                                      Attacker's Goal: Achieve RCE or DoS via Commons Lang 3
                                                      /                               \
                                                     /                                 \
                                  ------------------------------------      ------------------------------------
                                  |  Exploit Vulnerabilities in      |      |     Exploit Misuse of           |
                                  |     Commons Lang 3 Features     |      |     Commons Lang 3 Features     |
                                  ------------------------------------      ------------------------------------
                                       /                                                     |
                                      /                                                      |
  --------------------------                                         -------------
  |  Serialization Issues |                                         |  String    |
  | (if used unsafely)   |                                         |  Handling |
  --------------------------                                         -------------
      |  [HIGH RISK]                                                         |
      |                                                                       |
  ---------                                                         -------------
  |  OIS  |                                                         |  Format   |
  |Deser.|                                                         |  String   |
  ---------                                                         -------------
      |  [HIGH RISK]                                                         |
      |
  -------------                                                         -------------
  |  Gadget   |                                                         |  Injection|
  |  Chains  |                                                         |  (e.g.,   |
  ------------- {CRITICAL}                                                  |  StrSub.) |
                                                                        -------------  
                                                                            | [HIGH RISK]
            /|\                                                         -------------
           / | \                                                        |  Variable |
          /  |  \                                                       |  Interp. |
         /   |   \                                                      -------------
        /    |    \
       /     |     \
-----------------  -------------
|  Reflection   |
|  API Abuse   |
-----------------
       |
----------------
|  Unsafe Type |
|  Conversion  |
----------------
       | [HIGH RISK]
----------------
|  Class.forName|
|  w/ User Input|
---------------- {CRITICAL}
  • Overall Description: This attack vector exploits vulnerabilities in Java's object deserialization mechanism. While Commons Lang 3 doesn't directly handle serialization, its objects can be part of a larger serialized object graph. If an application uses ObjectInputStream unsafely (without proper whitelisting), an attacker can craft a malicious serialized object that, when deserialized, executes arbitrary code.
  • Attack Steps:
    • OIS Deserialization: The attacker sends a crafted serialized object to the application.
    • Gadget Chains: The serialized object contains a "gadget chain" – a sequence of carefully chosen class instances and method calls that, when deserialized, trigger unintended behavior, ultimately leading to RCE. Commons Lang 3 classes could be part of this chain, though it's not a requirement.
  • Likelihood: Low (Requires unsafe ObjectInputStream usage and a suitable gadget chain)
  • Impact: Very High (RCE)
  • Effort: High (Finding/crafting a gadget chain can be complex)
  • Skill Level: Advanced to Expert
  • Detection Difficulty: Medium to Hard (Requires monitoring deserialization activity and analyzing object graphs)
  • Mitigation:
    • Avoid ObjectInputStream if possible. Use safer alternatives like JSON or XML with strict schema validation.
    • If ObjectInputStream is unavoidable, implement strict whitelisting of allowed classes using ValidatingObjectInputStream or similar.
    • Regularly audit dependencies for vulnerable libraries.
    • Keep Commons Lang 3 updated.
  • Overall Description: This attack vector exploits the misuse of Java's reflection API, facilitated by Commons Lang 3's reflection utilities. If an application uses these utilities with unvalidated user input to dynamically access or modify classes and methods, an attacker can gain control.
  • Attack Steps:
    • Unsafe Type Conversion: The application uses reflection utilities (e.g., FieldUtils, MethodUtils) with user-provided input.
    • Class.forName with User Input: The attacker provides a malicious class name that is passed to Class.forName(). This allows the attacker to load an arbitrary class, potentially containing malicious code.
  • Likelihood: Low to Medium (Requires application to use reflection with unvalidated user input)
  • Impact: High (Potential for RCE or loading malicious classes)
  • Effort: Medium (Requires identifying the vulnerable reflection usage)
  • Skill Level: Intermediate to Advanced
  • Detection Difficulty: Medium (Can be detected through code analysis and input validation checks)
  • Mitigation:
    • Avoid using reflection with untrusted input.
    • If reflection is necessary, strictly validate user-provided class names, method names, and field names against a whitelist.
    • Use a Security Manager to restrict reflection capabilities.
    • Prefer direct method calls and object instantiation over reflection.

Attack Tree Path: String Handling (High Risk)

  • Overall Description: This attack vector exploits vulnerabilities in how an application handles strings, specifically using Commons Lang 3's StrSubstitutor for variable interpolation. If user input is directly used in the template string, an attacker can inject malicious expressions.
  • Attack Steps:
    • Format String Injection (e.g., StrSubstitutor): The application uses StrSubstitutor to perform variable substitution.
    • Variable Interpolation: The attacker provides input that includes malicious expressions or commands within the template string. These expressions are then evaluated by StrSubstitutor. While StrSubstitutor has some built-in protections, misconfigurations or older versions can be vulnerable.
  • Likelihood: Low to Medium (Requires user input to directly control the template string and a misconfiguration or older version)
  • Impact: Medium to High (Information disclosure, potential DoS, less likely RCE)
  • Effort: Low to Medium (Exploiting basic injection is easy, but achieving RCE is harder)
  • Skill Level: Intermediate
  • Detection Difficulty: Easy to Medium (Can be detected through input validation and code review)
  • Mitigation:
    • Sanitize and validate user input before using it with StrSubstitutor.
    • Use a predefined set of allowed variables and sanitize their values.
    • Consider a more restrictive templating engine.
    • Keep Commons Lang 3 updated.