Skip to main content

path_traversal

Function path_traversal 

Source
pub fn path_traversal(input: &str) -> String
Expand description

Generates path traversal patterns for directory traversal testing.

Randomly replaces forward slashes with path traversal sequences like ../, ..\, ....//, or URL-encoded variants (%2e%2e/). This creates payloads to test directory traversal vulnerabilities where attackers try to access files outside the intended directory.

§Use Cases

  • Red Team: Test for directory traversal vulnerabilities
  • LFI/RFI Testing: Local/Remote File Inclusion attack payloads
  • Path Validation: Test if systems properly sanitize paths
  • Blue Team: Validate path traversal prevention mechanisms

§Examples

use redstr::path_traversal;

let result = path_traversal("/etc/passwd");
// Example: "../etc/../passwd" or "..%2fetc/passwd" (varies each run)
assert!(result.contains("etc") && result.contains("passwd"));

// Web application file access
let file = path_traversal("uploads/file.txt");
// Example: "uploads/../file.txt" or "..\\uploads/file.txt"

// Nested traversal
let deep = path_traversal("/var/www/html/index.php");
// Example: "../var/../www/....//html/index.php"