Skip to content

Latest commit

 

History

History
117 lines (97 loc) · 6.77 KB

File metadata and controls

117 lines (97 loc) · 6.77 KB

Attack Tree Analysis for burntsushi/ripgrep

Objective: Exfiltrate Data or Achieve Arbitrary Code Execution via Application's Use of Ripgrep (rg)

Attack Tree Visualization

                                     +-----------------------------------------------------+
                                     | Exfiltrate Data or Achieve Arbitrary Code Execution |
                                     |      via Application's Use of Ripgrep (rg)         |
                                     +-----------------------------------------------------+
                                                  /                 |
                                                 /                  |
          +--------------------------------+  +---------------------+
          |  1. Input Validation Bypass   |  | 2. Command Injection |
          +--------------------------------+  +---------------------+
              /           |                          |
             /            |                          |
+----------+-----+ +------+-----+          +---+---+-----+
| 1.a.  Craft | | 1.b. Use |          |2.a. Inject|
|  Regex to   | |  Special |          |  rg Flags |
|  Match      | |Characters|          |  to Run   |
|  Unintended | |  in Path |          |  Arbitrary|
|  Files      | |[HIGH-RISK]|          |  Commands |
| [HIGH-RISK] | |          |          | [CRITICAL]|
+----------+-----+ +------+-----+          +---+---+-----+
                                                      |
                                                      |
                                            +-----------+-----+
                                            | 2.b.  Bypass |
                                            |  Filtering   |
                                            |  of Flags    |
                                            | [CRITICAL]   |
                                            +-----------+-----+
  • Overall Description: The attacker exploits insufficient validation of user-supplied regular expressions to make ripgrep match files outside the intended scope, leading to data exfiltration.

  • Steps:

    1. The application accepts a regular expression as input from the user.
    2. The application fails to adequately sanitize or restrict the user-provided regex.
    3. The attacker crafts a malicious regex that matches files outside the intended search directory or files containing sensitive information. Examples:
      • ../../etc/passwd (if path traversal is not handled elsewhere)
      • .*\.conf (to match all configuration files)
      • .*\.key (to match private key files)
    4. The application uses the attacker's regex with ripgrep.
    5. Ripgrep matches the unintended files.
    6. The application displays or processes the contents of the matched files, exposing sensitive data to the attacker.
  • Likelihood: Medium

  • Impact: High

  • Effort: Low

  • Skill Level: Intermediate

  • Detection Difficulty: Medium

  • Overall Description: The attacker exploits insufficient validation of user-supplied file paths to access files outside the intended directory, leading to data exfiltration (classic path traversal).

  • Steps:

    1. The application accepts a file path or part of a file path as input from the user.
    2. The application fails to adequately sanitize or restrict the user-provided path.
    3. The attacker injects special characters like .. (parent directory), * (wildcard), or shell metacharacters into the path. Examples:
      • ../../etc/passwd
      • /var/www/../../../etc/shadow
      • *.php (if wildcards are not properly handled)
    4. The application constructs the file path to be used with ripgrep, incorporating the attacker's malicious input.
    5. Ripgrep accesses files outside the intended directory.
    6. The application displays or processes the contents of the accessed files, exposing sensitive data to the attacker.
  • Likelihood: Medium

  • Impact: High

  • Effort: Very Low

  • Skill Level: Intermediate

  • Detection Difficulty: Easy

  • Overall Description: The attacker injects arbitrary ripgrep flags, particularly --pre, to execute arbitrary commands on the server, leading to complete system compromise.

  • Steps:

    1. The application constructs the ripgrep command string using user-provided input.
    2. The application fails to properly escape or sanitize the user input, allowing the attacker to inject arbitrary flags.
    3. The attacker injects a malicious flag, such as --pre 'bash -c "malicious_command"'. Other dangerous flags could also be used.
    4. The application executes the ripgrep command with the injected flag.
    5. The injected command is executed with the privileges of the user running ripgrep (often the web server user).
    6. The attacker gains arbitrary code execution on the server.
  • Likelihood: Low

  • Impact: Very High

  • Effort: Low

  • Skill Level: Advanced

  • Detection Difficulty: Hard

  • Overall Description: The attacker bypasses the application's attempts to filter out dangerous ripgrep flags, enabling them to proceed with command injection (Critical Node 1).

  • Steps:

    1. The application attempts to filter out dangerous ripgrep flags from user input.
    2. The attacker identifies a weakness in the filtering logic. This could involve:
      • Using alternative flag names (e.g., short vs. long flags: -e vs. --regexp).
      • Using encoding techniques (e.g., URL encoding).
      • Exploiting flaws in the regular expression used for filtering.
      • Finding edge cases or boundary conditions that the filter doesn't handle.
    3. The attacker crafts their input to bypass the filter.
    4. The application fails to block the malicious flag.
    5. The attacker can now inject arbitrary flags (proceeding to Critical Node 1).
  • Likelihood: Low

  • Impact: Very High

  • Effort: Medium

  • Skill Level: Advanced

  • Detection Difficulty: Hard