hackingyseguridad/directoriotraversal
GitHub: hackingyseguridad/directoriotraversal
一组用Bash、Python和NSE编写的路径遍历漏洞检测与利用脚本集合,覆盖多个已知CVE并提供通用模糊测试能力。
Stars: 12 | Forks: 5
### 目录遍历 / 路径遍历工具包



这是一组用 **Bash**、**Python** 和 **NSE (Nmap)** 编写的脚本集合,用于检测和验证 Web 服务器上的 **路径遍历 / 目录遍历** 漏洞,包括针对各种已知 CVE 的特定测试。
### 📑 目录
- [什么是路径遍历?](#-qué-es-path-traversal)
- [本仓库包含什么?](#-qué-incluye-este-repositorio)
- [系统要求](#-requisitos)
- [安装](#-instalación)
- [快速使用](#-uso-rápido)
- [按 CVE 分类利用脚本](#-scripts-de-explotación-por-cve)
- [通用工具](#-herramientas-generales)
- [Payload 字典](#-diccionario-de-payloads)
- [执行示例](#-ejemplo-de-ejecución)
- [相关 HTTP 响应代码](#-códigos-de-respuesta-http-relevantes)
- [免责声明 / 负责任地使用](#️-aviso-legal--uso-responsable)
- [许可证](#-licencia)
- [贡献](#-contribuciones)
### 路径遍历
**路径遍历**(也称为*目录遍历*)是一种 Web 漏洞,允许攻击者**跳出**应用程序的根目录,并访问本不应公开的系统文件和文件夹。
它通过操纵包含文件路径的 URL 参数或用户输入来利用此漏洞,通过插入诸如 `../`(或其编码变体:`%2e%2e%2f`、`..%c0%af` 等)之类的序列来浏览服务器的文件系统。
当输入验证不充分时,攻击者可能会读取到敏感文件,例如:
| 系统 | 典型目标文件 | 泄露的信息 |
|---|---|---|
| Linux/Unix | `/etc/passwd` | 系统用户列表 |
| Linux/Unix | `/etc/shadow` | 密码哈希值(需要特权) |
| Windows | `windows/system32/cmd.exe` 或 `win.ini` | 系统执行/配置 |
| Web 应用程序 | `web.config`、`.env`、`config.php` | 凭据、API 密钥 |
| 服务器 | 日志、证书、源代码 | 后端内部信息 |
**基本 Payload 示例:**
```
curl --path-as-is -k -v http://:80/../../../../../etc/passwd
```

**Windows 示例:**
```
curl --path-as-is -k -v http://:80/../../../../../../windows/system32/cmd.exe
```
### 本仓库包含什么?
| 类别 | 数量 | 描述 |
|---|---|---|
| 按 CVE 分类的 Exploit | 7 个 `.sh` 脚本 | 针对特定已知漏洞的 PoC |
| 通用扫描工具 | 6 个脚本 | 针对遍历 Payload 的模糊测试和批量测试 |
| Python 脚本 | 1 个(`dir.py`) | 使用 Python 自动化测试 |
| Nmap 脚本 (NSE) | 1 个(`traversal.nse`) | 通过 Nmap Scripting Engine 进行遍历检测 |
| PHP 脚本 | 1 个(`traversal.php`) | PHP 中的 PoC / 实用工具 |
| 辅助实用工具 | 3 个脚本 | 证书生成、URL/SSL 管理、字典更新 |
| Payload 字典 | 1 个(`pathtraversal.txt`,外部) | 包含遍历路径和 Payload 的字典 |
### ⚙️ 系统要求
- Linux/Unix 系统(已在 Debian/Ubuntu、Kali 等发行版上测试)
- `bash`
- `curl`
- `python3`(用于 `dir.py`)
- `nmap`(用于 `traversal.nse`)
- `git`(用于克隆此仓库及相关字典)
- 测试目标的权限和**明确授权**(请参阅[免责声明](#️-aviso-legal--uso-responsable))
### 安装
```
git clone https://github.com/hackingyseguridad/directoriotraversal.git
cd directoriotraversal
chmod +x *.sh
```
获取/更新 Payload 字典:
```
./actualizar.sh
```
### 快速使用
```
# 针对目标的通用 Directory Traversal 测试
./directoriotraversal.sh
# Scanner 的替代变体
./directoriotraversal2.sh
# 针对 Apache 服务器的特定测试
./apache_path_traversal.sh
# 针对特定 CVE 的测试(示例:Apache Path Traversal 2021)
./CVE-2021-41773.sh
```
### 按 CVE 分类利用脚本
| 脚本 | CVE | 受影响的产品 / 组件 | 简要描述 |
|---|---|---|---|
| `CVE-2001-0333.sh` | [CVE-2001-0333](https://nvd.nist.gov/vuln/detail/CVE-2001-0333) | IIS / 旧版 Web 服务器 | 通过 URL 字符编码的经典遍历 |
| `CVE-2009-1535.sh` | [CVE-2009-1535](https://nvd.nist.gov/vuln/detail/CVE-2009-1535) | FTP / Web 服务器 | 访问根目录之外的文件 |
| `CVE-2018-0296.sh` | [CVE-2018-0296](https://nvd.nist.gov/vuln/detail/CVE-2018-0296) | Cisco ASA / FTD (WebVPN) | 导致拒绝服务和信息泄露的遍历 |
| `CVE-2018-13379.sh` | [CVE-2018-13379](https://nvd.nist.gov/vuln/detail/CVE-2018-13379) | Fortinet FortiOS SSL VPN | 读取会话文件(明文形式的 VPN 凭据) |
| `CVE-2019-11510.sh` | [CVE-2019-11510](https://nvd.nist.gov/vuln/detail/CVE-2019-11510) | Pulse Secure VPN | 未经身份验证的任意文件读取 |
| `CVE-2021-41773.sh` | [CVE-2021-41773](https://nvd.nist.gov/vuln/detail/CVE-2021-41773) | Apache HTTP Server 2.4.49 | 路径规范化导致的遍历,如果启用了 `mod_cgi`,可能导致 RCE |
| `CVE-2021-42013.sh` | [CVE-2021-42013](https://nvd.nist.gov/vuln/detail/CVE-2021-42013) | Apache HTTP Server 2.4.50 | 对 CVE-2021-41773 补丁的绕过 |
### 通用工具
| 脚本 | 语言 | 功能 |
|---|---|---|
| `directoriotraversal.sh` | Bash | 针对目标进行通用的路径遍历扫描器 |
| `directoriotraversal2.sh` | Bash | 通用扫描器的替代/改进版本 |
| `dirhttp.sh` | Bash | 专门针对 HTTP 的遍历测试 |
| `apache_path_traversal.sh` | Bash | 针对 Apache 服务器的测试 |
| `dir.py` | Python | 使用 Python 自动化遍历测试 |
| `traversal.nse` | Lua (NSE) | 用于 Nmap Scripting Engine 的脚本,在端口扫描期间进行检测 |
| `traversal.php` | PHP | 用于在 PHP 环境中进行测试的 PoC / 实用工具 |
| `probar.sh` | Bash | 执行特定测试 |
| `probarauto.sh` | Bash | 针对目标的自动化测试 |
| `probarauto2.sh` | Bash | 上述自动化脚本的变体 |
| `urlssl.sh` | Bash | 基于 SSL 的 URL 管理/验证 |
| `generacert.sh` | Bash | 为 HTTPS 测试生成证书 |
| `actualizar.sh` | Bash | 下载/更新 Payload 字典 |
### 📖 Payload 字典
本仓库使用了一个位于此处维护的外部路径和遍历 Payload 字典:
🔗 [`diccionarios/pathtraversal.txt`](https://github.com/hackingyseguridad/diccionarios/blob/master/pathtraversal.txt)
使用以下命令自动下载/更新:
```
./actualizar.sh
```
## 🧪 执行示例
```
$ ./directoriotraversal.sh example.com
[+] Probando payloads de Directory Traversal contra example.com ...
[+] Cargando diccionario: pathtraversal.txt
[+] Payload: ../../../../etc/passwd -> 403 Forbidden
[+] Payload: ..%2f..%2f..%2fetc%2fpasswd -> 200 OK [POSIBLE VULNERABLE]
[+] Reporte guardado en resultados.txt
```
### 相关 HTTP 响应代码
| 代码 | 含义 | 在路径遍历中的相关性 |
|---|---|---|
| `200 OK` | 请求成功 | Payload 可能已成功;检查返回的内容 |
| `301 / 302` | 重定向 | 服务器可能在处理之前对路径进行了规范化 |
| `400 Bad Request` | 无效请求 | 服务器拒绝了路径格式 |
| `403 Forbidden` | 拒绝访问 | 过滤器或 WAF 阻止了该尝试 |
| `404 Not Found` | 未找到资源 | 路径不存在或遍历未到达预期资源 |
| `500 Internal Server Error` | 服务器内部错误 | 可能表明存在可利用的意外行为 |
完整参考:[RFC 2616 - HTTP 状态码](https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)
# [www.hackingyseguridad.com](http://www.hackingyseguridad.com/)
[diccionarios/pathtraversal.txt](https://github.com/hackingyseguridad/diccionarios/blob/master/pathtraversal.txt)
#
标签:Bash, CISA项目, CTI, Python, 应用安全, 无后门, 逆向工具