SMTP用户枚举原理简介及相关工具
字数 3308 2025-08-18 11:37:33
SMTP用户枚举原理与工具使用详解
一、SMTP用户枚举原理
SMTP(简单邮件传输协议)是安全测试中常见的服务类型,其不安全的配置(未禁用某些命令)会导致用户枚举问题。主要通过以下SMTP命令实现:
1. 关键SMTP命令
| 命令 | 功能描述 |
|---|---|
| MAIL FROM | 指定发件人地址 |
| RCPT TO | 指定单个邮件接收人;可有多个RCPT TO;常在MAIL FROM命令之后 |
| VRFY | 用于验证指定用户/邮箱是否存在;由于安全原因,服务器常禁止此命令 |
| EXPN | 验证给定的邮箱列表是否存在,也常被禁用 |
2. 关键返回码
| 返回码 | 含义 |
|---|---|
| 250 | 要求的邮件操作完成 |
| 550 | 要求的邮件操作未完成,邮箱不可用(例如邮箱未找到,或不可访问) |
二、手动枚举方法
1. 使用VRFY命令
$ telnet 202.38.xxx.xxx 25
Trying 202.38.xxx.xxx...
Connected to 202.38.xxx.xxx.
Escape character is '^]'.
220 mxt.xxx.xxx.cn ESMTP Postfix
VRFY root
252 2.0.0 root
VRFY bin
252 2.0.0 bin
VRFY admin
550 5.1.1 <admin>: Recipient address rejected: User unknown in local recipient table
2. 使用MAIL FROM+RCPT TO命令
$ telnet 202.38.xxx.xxx 25
Trying 202.38.xxx.xxx...
Connected to 202.38.xxx.xxx.
Escape character is '^]'.
220 mxt.xxx.xxx.cn ESMTP Postfix
MAIL FROM:root
250 2.1.0 Ok
RCPT TO:root
250 2.1.5 Ok
RCPT TO:bin
250 2.1.5 Ok
RCPT TO:admin
550 5.1.1 <admin>: Recipient address rejected: User unknown in local recipient table
三、自动化工具使用
1. smtp-user-enum工具
kali自带的Perl编写工具,支持VRFY、RCPT和EXPN三种枚举方式。
基本参数
Usage: smtp-user-enum.pl [options] ( -u username | -U file-of-usernames ) ( -t host | -T file-of-targets )
options:
-m <number> 最大线程数(默认: 5)
-M <mode> 使用方法方式 EXPN, VRFY or RCPT (默认: VRFY)
-u <user> 指定用户
-f <addr> 邮箱地址,只能用在 "RCPT TO" mode (默认: user@example.com)
-D <domaim> 使用电子邮件地址添加到用户列表在域 (默认: none)
-U <file> 通过smtp服务指定文件里的用户名检查
-t <host> 指定主机来运行smtp服务器主机服务
-T <file> 指定文件来运行smtp服务器主机服务
-p <port> 设置TCP端口号 (默认: 25)
-d 调试
-t <time> 最大返回时间 (default: 5)
-v 版本
-h 帮助
使用示例
VRFY方式
$ smtp-user-enum -M VRFY -u root -t 202.38.xxx.xxx
RCPT方式
$ smtp-user-enum -M RCPT -u bin -t 202.38.xxx.xxx
EXPN方式
$ smtp-user-enum -M EXPN -u bin -t 202.38.xxx.xxx
2. Metasploit的smtp_enum模块
msf > use auxiliary/scanner/smtp/smtp_enum
msf auxiliary(scanner/smtp/smtp_enum) > show options
Module options (auxiliary/scanner/smtp/smtp_enum):
Name Current Setting Required Description
---- --------------- -------- -----------
RHOSTS yes The target address range or CIDR identifier
RPORT 25 yes The target port (TCP)
THREADS 1 yes The number of concurrent threads
UNIXONLY true yes Skip Microsoft bannered servers when testing unix users
USER_FILE /usr/share/metasploit-framework/data/wordlists/unix_users.txt yes The file that contains a list of probable users accounts.
msf auxiliary(scanner/smtp/smtp_enum) > set rhosts 202.38.xxx.xxx
rhosts => 202.38.xxx.xxx
msf auxiliary(scanner/smtp/smtp_enum) > run
3. Nmap的smtp-enum-users脚本
$ nmap -p 25 --script smtp-enum-users.nse 202.38.193.203
Nmap scan report for news.scut.edu.cn (202.38.193.203)
Host is up (0.054s latency).
PORT STATE SERVICE
25/tcp open smtp
| smtp-enum-users:
| root
| admin
| administrator
| webadmin
| sysadmin
| netadmin
| guest
| user
| web
|_ test
Nmap done: 1 IP address (1 host up) scanned in 1.27 seconds
自定义参数:
--script-args smtp-enum-users.methods={EXPN,RCPT,VRFY}设置扫描方式--script-args userdb=user_path,passdb=pass_path指定字典
四、防御措施
- 禁用不必要的SMTP命令(VRFY、EXPN)
- 配置SMTP服务对所有用户查询返回相同响应
- 实施速率限制防止暴力枚举
- 使用防火墙规则限制SMTP访问
五、完整SMTP返回码参考
| 返回码 | 含义 |
|---|---|
| 500 | 格式错误,命令不可识别(此错误也包括命令行过长) |
| 501 | 参数格式错误 |
| 502 | 命令不可实现 |
| 503 | 错误的命令序列 |
| 504 | 命令参数不可实现 |
| 211 | 系统状态或系统帮助响应 |
| 214 | 帮助信息 |
| 220 | 服务就绪 |
| 221 | 服务关闭传输信道 |
| 421 | 服务未就绪,关闭传输信道(当必须关闭时,此应答可以作为对任何命令的响应) |
| 250 | 要求的邮件操作完成 |
| 251 | 用户非本地,将转发向 |
| 450 | 要求的邮件操作未完成,邮箱不可用(例如,邮箱忙) |
| 550 | 要求的邮件操作未完成,邮箱不可用(例如,邮箱未找到,或不可访问) |
| 451 | 放弃要求的操作;处理过程中出错 |
| 551 | 用户非本地,请尝试 |
| 452 | 系统存储不足,要求的操作未执行 |
| 552 | 过量的存储分配,要求的操作未执行 |
| 553 | 邮箱名不可用,要求的操作未执行(例如邮箱格式错误) |
| 354 | 开始邮件输入,以.结束 |
| 554 | 操作失败 |
| 535 | 用户验证失败 |
| 235 | 用户验证成功 |
| 334 | 等待用户输入验证信息 |
通过以上方法和技术,安全测试人员可以有效地枚举SMTP服务上的有效用户账户,为后续的渗透测试提供有价值的信息。同时,系统管理员也应了解这些技术以更好地保护自己的SMTP服务。