跳到主要内容

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
vhostVHost 枚举基于 Host 头的虚拟主机发现
fuzz模糊测试FUZZ 关键词替换任意位置
s3S3 存储桶枚举发现公开的 AWS S3 存储桶
tftpTFTP 枚举枚举 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.txt5K 行
Discovery/DNS/subdomains-top1million-20000.txt20K 行
Discovery/DNS/subdomains-top1million-110000.txt110K 行

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延迟低,可以激进
远程目标 / HackTheBox20-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

与其他工具对比

对比项GobusterFeroxbusterDirsearch
语言GoRustPython
速度最快中等
递归扫描❌ 不支持✅ 原生支持✅ 支持
子域名枚举✅ 支持❌ 不支持❌ 不支持
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
扫描 HTTPSgobuster 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、文件上传、后台登录等

相关知识