Gobuster 目录与子域名枚举
Gobuster 是用 Go 编写的高速暴力枚举工具,主要用于发现 Web 服务器上的隐藏目录、文件、子域名和 VHost。在靶场打靶中,Nmap 识别出 HTTP 服务后,Gobuster 通常是下一步的标准操作。
安装
Kali Linux
Kali 默认已预装:
gobuster version
Debian / Ubuntu
sudo apt update && sudo apt install -y gobuster
Go Install
go install github.com/OJ/gobuster/v3@latest
macOS
brew install gobuster
核心模式
Gobuster 支持多种枚举模式,通过子命令指定:
| 子命令 | 用途 | 说明 |
|---|---|---|
dir | 目录/文件枚举 | 最常用,暴力枚举 Web 路径 |
dns | 子域名枚举 | 爆破子域名(xxx.target.com) |
vhost | VHost 枚举 | 基于 Host 头的虚拟主机发现 |
fuzz | 模糊测试 | 用 FUZZ 关键词替换任意位置 |
s3 | S3 存储桶枚举 | 发现公开的 AWS S3 存储桶 |
tftp | TFTP 枚举 | 枚举 TFTP 服务器上的文件 |
通用参数
| 参数 | 说明 | 示例 |
|---|---|---|
-u <url> | 目标 URL | -u http://192.168.1.108/ |
-w <wordlist> | 字典文件路径 | -w /usr/share/wordlists/dirb/common.txt |
-t <n> | 并发线程数(默认 10) | -t 50 |
-o <file> | 输出到文件 | -o gobuster.txt |
-q | 安静模式,只输出结果 | -q |
-v | 详细模式 | -v |
--no-error | 不显示错误信息 | --no-error |
--delay <duration> | 请求间延迟 | --delay 100ms |
dir 模式(目录/文件枚举)
专用参数
| 参数 | 说明 | 示例 |
|---|---|---|
-x <exts> | 追加扩展名 | -x php,txt,html,bak |
-s <codes> | 仅显示指定状态码(默认显示 2xx/3xx) | -s 200,301,302 |
-b <codes> | 排除指定状态码 | -b 404,403 |
-r | 跟随重定向 | -r |
-k | 跳过 TLS 证书验证 | -k |
-a <ua> | 自定义 User-Agent | -a "Mozilla/5.0" |
-c <cookie> | 携带 Cookie | -c "session=abc123" |
-H <header> | 自定义 Header | -H "Authorization: Bearer xxx" |
-n | 不打印状态码 | -n |
-e | 输出完整 URL | -e |
--exclude-length <n> | 排除指定长度的响应 | --exclude-length 0 |
常用命令
1. 靶场标准扫描(最常用)
gobuster dir -u http://192.168.1.108/ -w /usr/share/seclists/Discovery/Web-Content/common.txt -q -t 20 -x php,txt,html
2. 大字典深度扫描
gobuster dir -u http://192.168.1.108/ -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 50 -x php,txt,html,bak,zip -o gobuster_medium.txt
3. 指定端口扫描
gobuster dir -u http://192.168.1.108:8080/ -w /usr/share/seclists/Discovery/Web-Content/common.txt -q -t 20
4. HTTPS 目标(跳过证书验证)
gobuster dir -u https://target.com/ -w /usr/share/wordlists/dirb/common.txt -k -t 20
5. 带认证扫描
# Cookie 认证
gobuster dir -u http://target/admin/ -w /usr/share/seclists/Discovery/Web-Content/common.txt -c "PHPSESSID=abc123" -t 20
# Header 认证
gobuster dir -u http://target/api/ -w /usr/share/seclists/Discovery/Web-Content/common.txt -H "Authorization: Bearer eyJhbG..." -t 20
6. 排除误报
# 排除 403 和特定响应长度
gobuster dir -u http://target/ -w /usr/share/seclists/Discovery/Web-Content/common.txt -b 403,404 --exclude-length 0 -t 20
dns 模式(子域名枚举)
专用参数
| 参数 | 说明 | 示例 |
|---|---|---|
-d <domain> | 目标域名 | -d target.com |
-r <resolver> | 指定 DNS 解析器 | -r 8.8.8.8 |
-i | 显示 IP 地址 | -i |
--wildcard | 强制继续即使检测到通配符 | --wildcard |
常用命令
gobuster dns -d target.com -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -t 30 -i
vhost 模式(VHost 枚举)
VHost 枚举不依赖 DNS 解析,通过修改 Host 头来发现同一 IP 上的虚拟主机。
专用参数
| 参数 | 说明 | 示例 |
|---|---|---|
-u <url> | 目标 URL | -u http://target.com |
--domain <domain> | 追加到字典词条后的域名 | --domain target.com |
--append-domain | 自动追加域名到字典词条 | --append-domain |
--exclude-length <n> | 排除指定长度的响应 | --exclude-length 0 |
常用命令
gobuster vhost -u http://target.com -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt --append-domain -t 30
如果大量结果返回相同长度的响应,用
--exclude-length过滤误报。
字典选择指南
字典的选择直接决定枚举效果。推荐使用 SecLists。
目录枚举字典
| 字典 | 大小 | 适用场景 |
|---|---|---|
Discovery/Web-Content/common.txt | ~4.6K 行 | 快速扫描,靶场首选 |
Discovery/Web-Content/directory-list-2.3-small.txt | ~87K 行 | 中等深度 |
Discovery/Web-Content/directory-list-2.3-medium.txt | ~220K 行 | 深度扫描 |
Discovery/Web-Content/directory-list-2.3-big.txt | ~1.3M 行 | 全面扫描(耗时长) |
Discovery/Web-Content/raft-large-directories.txt | ~62K 行 | Raft 项目整合,质量高 |
Discovery/Web-Content/raft-large-files.txt | ~37K 行 | 文件名专用 |
子域名枚举字典
| 字典 | 大小 |
|---|---|
Discovery/DNS/subdomains-top1million-5000.txt | 5K 行 |
Discovery/DNS/subdomains-top1million-20000.txt | 20K 行 |
Discovery/DNS/subdomains-top1million-110000.txt | 110K 行 |
Kali 内置字典
如果没有安装 SecLists,Kali 自带以下字典:
# dirb
/usr/share/wordlists/dirb/common.txt # ~4.6K 行
/usr/share/wordlists/dirb/big.txt # ~20K 行
# dirbuster
/usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
靶场策略:先用
common.txt快扫(几秒完成),有线索再用medium或加-x扩展名深扫。
扩展名选择策略
-x 参数的选择取决于目标技术栈:
| 目标技术栈 | 推荐扩展名 |
|---|---|
| PHP (Apache/Nginx) | -x php,txt,html,bak,zip |
| ASP.NET (IIS) | -x asp,aspx,txt,html,config |
| Java (Tomcat) | -x jsp,txt,xml,war |
| Python (Flask/Django) | -x py,txt,html,json |
| Node.js | -x js,json,txt,html |
| 通用(不确定) | -x php,txt,html,bak,zip,old,conf |
可以通过 Nmap 的
-sV或 HTTP 响应头判断技术栈。
性能调优
线程数
| 场景 | 线程数 | 说明 |
|---|---|---|
| 本地靶场 | 50-100 | 延迟低,可以激进 |
| 远程目标 / HackTheBox | 20-30 | 避免被限速或 ban |
| 有 WAF 的目标 | 5-10 + --delay | 降低速度规避检测 |
常见问题
大量 403 干扰输出
gobuster dir -u http://target/ -w wordlist.txt -b 403 -t 20
通配符响应(所有路径都返回 200)
# 先确认通配符行为
curl -s -o /dev/null -w "%{http_code} %{size_download}" http://target/definitely-not-exist-12345/
# 用 --exclude-length 排除固定长度的通配符响应
gobuster dir -u http://target/ -w wordlist.txt --exclude-length 1234 -t 20
目标限速 / 连接被拒
gobuster dir -u http://target/ -w wordlist.txt -t 5 --delay 200ms
与其他工具对比
| 对比项 | Gobuster | Feroxbuster | Dirsearch |
|---|---|---|---|
| 语言 | Go | Rust | Python |
| 速度 | 快 | 最快 | 中等 |
| 递归扫描 | ❌ 不支持 | ✅ 原生支持 | ✅ 支持 |
| 子域名枚举 | ✅ 支持 | ❌ 不支持 | ❌ 不支持 |
| VHost 枚举 | ✅ 支持 | ❌ 不支持 | ❌ 不支持 |
| 配置文件 | ❌ | ✅ 支持 | ✅ 支持 |
| 适用场景 | 通用首选 | 深度递归目录扫描 | Python 环境下的替代 |
靶场推荐:Gobuster 足够应对绝大多数场景。如果需要递归扫描(自动进入发现的子目录),考虑 Feroxbuster。
靶场实战速查
RustScan 发现 HTTP 端口后,根据场景选择 Gobuster 命令:
| 场景 | 命令 |
|---|---|
| 快速扫描 80 端口 | gobuster dir -u http://target/ -w /usr/share/seclists/Discovery/Web-Content/common.txt -q -t 20 -x php,txt,html |
| 扫描非标准端口 | gobuster dir -u http://target:8080/ -w /usr/share/seclists/Discovery/Web-Content/common.txt -q -t 20 |
| 深度扫描 | gobuster dir -u http://target/ -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 50 -x php,txt,html,bak -o results.txt |
| 扫描 HTTPS | gobuster dir -u https://target/ -w /usr/share/seclists/Discovery/Web-Content/common.txt -k -t 20 |
| 子域名枚举 | gobuster dns -d target.com -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -t 30 -i |
| VHost 发现 | gobuster vhost -u http://target.com -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt --append-domain -t 30 |
标准侦察工作流中的位置
1. RustScan 全端口快扫 → 发现 HTTP 端口(80/443/8080 等)
2. Nmap 服务识别 → 确认 Web 服务器类型和版本
3. Gobuster 目录/文件枚举 → 发现隐藏路径和敏感文件
4. 针对发现的入口点深入利用 → LFI、文件上传、后台登录等
相关知识
- RustScan 端口扫描 — 快速发现开放端口,定位 HTTP 服务
- Nmap 服务识别与脚本扫描 — 确认 Web 服务器类型,为字典和扩展名选择提供依据