analyzing-email-headers-for-phishing-investigation
解析和分析电子邮件头部以追踪钓鱼邮件的来源,通过 SPF、DKIM 和 DMARC 验证来核实发件人真实性并识别伪造行为。
Best use case
analyzing-email-headers-for-phishing-investigation is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
解析和分析电子邮件头部以追踪钓鱼邮件的来源,通过 SPF、DKIM 和 DMARC 验证来核实发件人真实性并识别伪造行为。
Teams using analyzing-email-headers-for-phishing-investigation should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/analyzing-email-headers-for-phishing-investigation/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How analyzing-email-headers-for-phishing-investigation Compares
| Feature / Agent | analyzing-email-headers-for-phishing-investigation | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
解析和分析电子邮件头部以追踪钓鱼邮件的来源,通过 SPF、DKIM 和 DMARC 验证来核实发件人真实性并识别伪造行为。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 分析电子邮件头部用于钓鱼调查
## 适用场景
- 调查疑似钓鱼(Phishing)邮件以确定其真实来源时
- 验证发件人真实性并检测电子邮件伪造时
- 用户点击钓鱼链接后的事件响应期间
- 追踪可疑邮件的投递路径和中继服务器时
- 验证 SPF、DKIM 和 DMARC 对齐以识别伪造时
## 前置条件
- 来自可疑邮件的原始邮件头部(EML 或 MSG 格式)
- 了解 SMTP 协议和电子邮件头部字段
- 访问 DNS 查询工具(dig、nslookup)用于 SPF/DKIM/DMARC 验证
- 电子邮件头部分析工具(MHA、emailheaders.net 相关概念)
- 带邮件解析库的 Python 用于自动化分析
- 访问威胁情报(Threat Intelligence)平台进行 IP/域名声誉查询
## 工作流程
### 步骤 1:提取原始电子邮件头部
```bash
# 从 Outlook 导出: 打开邮件 > 文件 > 属性 > Internet 头部
# 从 Gmail 导出: 打开邮件 > 三个点 > 显示原始邮件
# 从 Thunderbird 导出: 查看 > 消息源码
# 如果从取证镜像处理 EML 文件
cp /mnt/evidence/Users/suspect/AppData/Local/Microsoft/Outlook/phishing_email.eml \
/cases/case-2024-001/email/
# 如果处理 PST 文件,提取单个消息
pip install pypff
python3 << 'PYEOF'
import pypff
pst = pypff.file()
pst.open("/cases/case-2024-001/email/outlook.pst")
root = pst.get_root_folder()
def extract_messages(folder, path=""):
for i in range(folder.get_number_of_sub_messages()):
msg = folder.get_sub_message(i)
headers = msg.get_transport_headers()
subject = msg.get_subject()
if headers:
filename = f"/cases/case-2024-001/email/msg_{i}_{subject[:30]}.txt"
with open(filename, 'w') as f:
f.write(headers)
for i in range(folder.get_number_of_sub_folders()):
extract_messages(folder.get_sub_folder(i))
extract_messages(root)
PYEOF
```
### 步骤 2:解析电子邮件头部链
```bash
# 使用 Python email 库解析头部
python3 << 'PYEOF'
import email
from email import policy
with open('/cases/case-2024-001/email/phishing_email.eml', 'r') as f:
msg = email.message_from_file(f, policy=policy.default)
print("=== 关键头部字段 ===")
print(f"From: {msg['From']}")
print(f"To: {msg['To']}")
print(f"Subject: {msg['Subject']}")
print(f"Date: {msg['Date']}")
print(f"Message-ID: {msg['Message-ID']}")
print(f"Reply-To: {msg['Reply-To']}")
print(f"Return-Path: {msg['Return-Path']}")
print(f"X-Mailer: {msg['X-Mailer']}")
print(f"X-Originating-IP: {msg['X-Originating-IP']}")
print("\n=== Received 头部(从底部到顶部 = 时间顺序)===")
received_headers = msg.get_all('Received')
if received_headers:
for i, header in enumerate(reversed(received_headers)):
print(f"\n跳 {i+1}: {header.strip()}")
print("\n=== 认证结果 ===")
auth_results = msg.get_all('Authentication-Results')
if auth_results:
for result in auth_results:
print(result)
print(f"\nARC-Authentication-Results: {msg.get('ARC-Authentication-Results', '不存在')}")
print(f"Received-SPF: {msg.get('Received-SPF', '不存在')}")
print(f"DKIM-Signature: {msg.get('DKIM-Signature', '不存在')}")
PYEOF
```
### 步骤 3:验证 SPF、DKIM 和 DMARC 记录
```bash
# 提取信封发件人域名
SENDER_DOMAIN="example-corp.com"
# 检查 SPF 记录
dig TXT $SENDER_DOMAIN +short | grep "v=spf1"
# 示例: "v=spf1 include:_spf.google.com include:sendgrid.net ~all"
# 检查 DKIM 记录(选择器来自 DKIM-Signature 头部,例如 "s=selector1")
DKIM_SELECTOR="selector1"
dig TXT ${DKIM_SELECTOR}._domainkey.${SENDER_DOMAIN} +short
# 检查 DMARC 记录
dig TXT _dmarc.${SENDER_DOMAIN} +short
# 示例: "v=DMARC1; p=reject; rua=mailto:dmarc@example-corp.com; pct=100"
# 对照 SPF 验证发送 IP
# 从第一个 Received 头部提取 IP
SENDING_IP="203.0.113.45"
# 使用 Python 手动进行 SPF 检查
python3 << 'PYEOF'
import spf # pip install pyspf
result, explanation = spf.check2(
i='203.0.113.45',
s='sender@example-corp.com',
h='mail.example-corp.com'
)
print(f"SPF 结果: {result}")
print(f"说明: {explanation}")
# 结果: pass(通过), fail(失败), softfail(软失败), neutral(中性), none(无), temperror(临时错误), permerror(永久错误)
PYEOF
# 检查发送 IP 是否在已知恶意 IP 列表中
# 查询 AbuseIPDB 或 VirusTotal
curl -s "https://api.abuseipdb.com/api/v2/check?ipAddress=${SENDING_IP}" \
-H "Key: YOUR_API_KEY" -H "Accept: application/json" | python3 -m json.tool
```
### 步骤 4:分析发件人域名和基础设施
```bash
# 对发件人域名进行 WHOIS 查询
whois $SENDER_DOMAIN | grep -iE '(registrar|creation|expiration|registrant|nameserver)'
# 检查域名年龄(最近注册的域名可疑)
# DNS 记录调查
dig A $SENDER_DOMAIN +short
dig MX $SENDER_DOMAIN +short
dig NS $SENDER_DOMAIN +short
# 对发送 IP 进行反向 DNS 查询
dig -x $SENDING_IP +short
# 检查仿冒/错字域名
# 使用视觉相似度与合法域名进行比较
python3 << 'PYEOF'
import Levenshtein # pip install python-Levenshtein
legitimate = "microsoft.com"
suspicious = "micr0soft.com"
distance = Levenshtein.distance(legitimate, suspicious)
ratio = Levenshtein.ratio(legitimate, suspicious)
print(f"编辑距离: {distance}")
print(f"相似度: {ratio:.2%}")
if ratio > 0.8:
print("警告: 可能是错字/仿冒域名!")
PYEOF
# 在 VirusTotal 上检查域名声誉
curl -s "https://www.virustotal.com/api/v3/domains/${SENDER_DOMAIN}" \
-H "x-apikey: YOUR_VT_API_KEY" | python3 -m json.tool
# 检查 Reply-To 是否与 From 不同(常见钓鱼指标)
python3 -c "
import email
with open('/cases/case-2024-001/email/phishing_email.eml') as f:
msg = email.message_from_file(f)
from_addr = email.utils.parseaddr(msg['From'])[1]
reply_to = email.utils.parseaddr(msg.get('Reply-To', msg['From']))[1]
if from_addr != reply_to:
print(f'警告: From ({from_addr}) != Reply-To ({reply_to})')
else:
print('From 和 Reply-To 匹配')
"
```
### 步骤 5:检查邮件正文和附件
```bash
# 从邮件正文提取 URL
python3 << 'PYEOF'
import email
import re
from email import policy
with open('/cases/case-2024-001/email/phishing_email.eml', 'r') as f:
msg = email.message_from_file(f, policy=policy.default)
body = msg.get_body(preferencelist=('html', 'plain'))
if body:
content = body.get_content()
urls = re.findall(r'https?://[^\s<>"\']+', content)
print("=== 邮件正文中发现的 URL ===")
for url in set(urls):
print(f" {url}")
# 检查 URL 混淆(显示文本 != href)
href_pattern = re.findall(r'<a[^>]*href=["\']([^"\']+)["\'][^>]*>(.*?)</a>', content, re.DOTALL)
print("\n=== 超链接分析 ===")
for href, text in href_pattern:
display_url = re.findall(r'https?://[^\s<]+', text)
if display_url and display_url[0] != href:
print(f" 不匹配: 显示='{display_url[0]}' -> 实际='{href}'")
# 提取附件并计算哈希值
print("\n=== 附件 ===")
for part in msg.walk():
if part.get_content_disposition() == 'attachment':
filename = part.get_filename()
content = part.get_payload(decode=True)
import hashlib
sha256 = hashlib.sha256(content).hexdigest()
print(f" 文件: {filename}, 大小: {len(content)}, SHA-256: {sha256}")
with open(f'/cases/case-2024-001/email/attachments/{filename}', 'wb') as af:
af.write(content)
PYEOF
# 将附件哈希提交给 VirusTotal
# 将 URL 提交给 URLhaus 或 PhishTank 进行声誉检查
```
## 核心概念
| 概念 | 定义 |
|------|------|
| SPF(发件人策略框架) | 指定域名授权邮件服务器的 DNS 记录 |
| DKIM(域名密钥识别邮件) | 验证电子邮件内容完整性的加密签名 |
| DMARC | 将 SPF 和 DKIM 结合用于发件人身份验证的策略框架 |
| Received 头部 | 服务器添加的头部,显示投递链中的每一跳(从底部到顶部读取) |
| Return-Path | 用于退信消息的信封发件人地址;可能与 From 不同 |
| Message-ID | 由原始邮件服务器分配的唯一标识符 |
| X-Originating-IP | 原始发件人 IP 地址(由某些邮件服务添加) |
| 头部伪造 | 攻击者可以伪造 From、Reply-To 和其他头部,但不能伪造 Received 链 |
## 工具与系统
| 工具 | 用途 |
|------|------|
| MXToolbox | 在线邮件头部分析器和 DNS 查询工具 |
| dig/nslookup | 用于 SPF、DKIM、DMARC 验证的 DNS 记录查询 |
| pyspf | Python SPF 记录验证库 |
| dkimpy | Python DKIM 签名验证库 |
| PhishTool | 专业钓鱼邮件分析平台 |
| VirusTotal | URL 和文件声誉检查服务 |
| AbuseIPDB | IP 地址声誉数据库 |
| whois | 域名注册信息查询 |
## 常见场景
**场景:CEO 欺诈/商业邮件攻击(BEC)**
邮件声称来自 CEO,但 Reply-To 指向 Gmail 地址,SPF 失败(因为发送 IP 未被伪造域名授权),DKIM 缺失,From 域名是仿冒域名(ceo-company.com vs company.com)。
**场景:凭据收割钓鱼**
邮件包含显示为"login.microsoft.com"但 href 指向仿冒域名的链接,附件是包含带凭据外泄 JavaScript 的假登录页面的 HTML 文件,发送域名三天前刚注册。
**场景:通过附件投递恶意软件**
带有包含宏的 Office 文档附件的邮件,发件人域名通过 SPF 但账户已被入侵,DKIM 签名有效(从合法基础设施发送),附件 SHA-256 与 VirusTotal 上的已知恶意软件匹配。
**场景:使用合法服务的鱼叉式钓鱼(Spearphishing)**
攻击者使用合法的邮件营销服务发送钓鱼邮件,SPF 和 DKIM 通过(因为该服务被授权),钓鱼内容在内容中而非基础设施中,需要 URL 和内容分析而非头部认证检查。
## 输出格式
```
电子邮件头部分析报告:
主题: "紧急: 需要支付发票"
发件人: accounting@examp1e-corp.com(已伪造)
Reply-To: payments.urgent@gmail.com(不匹配)
Return-Path: <bounce@mail-server.xyz>
日期: 2024-01-15 09:23:45 UTC
投递路径(4 跳):
跳 1: mail-server.xyz [203.0.113.45] -> relay1.isp.com
跳 2: relay1.isp.com -> mx.target-company.com
跳 3: mx.target-company.com -> internal-filter.target.com
跳 4: internal-filter.target.com -> 邮箱
认证结果:
SPF: 失败(203.0.113.45 未被 examp1e-corp.com 授权)
DKIM: 无(没有签名)
DMARC: 失败(p=none,未强制执行)
钓鱼指标:
- 仿冒域名(examp1e-corp.com vs example-corp.com,96% 相似)
- From/Reply-To 不匹配
- 域名在邮件发送前 2 天注册
- 正文中的 URL 指向凭据收割页面
- 附件: invoice.xlsm(SHA-256: a3f2...)- VirusTotal 上的已知恶意软件
风险级别: 高危
```Related Skills
testing-for-email-header-injection
测试 Web 应用程序邮件功能中的 SMTP 头部注入漏洞,这些漏洞允许攻击者注入额外的邮件头部、修改收件人,并通过联系表单实施垃圾邮件中继。
performing-red-team-phishing-with-gophish
使用 Python gophish 库自动化 GoPhish 钓鱼模拟活动。创建含追踪像素的邮件模板、 配置 SMTP 发送配置文件、从 CSV 构建目标组、发起活动,并分析结果, 包括打开率、点击率和凭据提交统计数据,用于安全意识评估。
performing-phishing-simulation-with-gophish
GoPhish 是一个开源钓鱼模拟框架,供安全团队开展授权的钓鱼意识培训活动,提供活动管理、邮件模板创建、着陆页克隆和综合报告功能。
performing-malware-persistence-investigation
系统性地调查 Windows 和 Linux 系统上的所有持久化机制,以识别恶意软件如何在重启后存活并维持访问。
performing-log-analysis-for-forensic-investigation
收集、解析和关联系统、应用程序及安全日志,以在取证调查期间重建事件并建立时间线。
performing-linux-log-forensics-investigation
对 Linux 系统日志(包括 syslog、auth.log、systemd journal、kern.log 和应用程序日志)进行取证调查,以重建用户活动、检测未授权访问并在被入侵的 Linux 系统上建立事件时间线。
performing-insider-threat-investigation
调查内部威胁事件,涉及滥用授权访问权限窃取数据、破坏系统或违反安全策略的员工、承包商或受信任合作伙伴。 结合数字取证、用户行为分析以及 HR/法务协调,构建基于证据的案例。适用于内部威胁调查、 员工数据盗窃、权限滥用、用户行为异常或内部威胁检测等请求场景。
performing-endpoint-forensics-investigation
对受损端点执行数字取证调查,包括内存获取、磁盘镜像、工件分析和时间线重建。 适用于调查安全事件、为法律诉讼收集证据或分析端点受损范围的场景。 适用于涉及端点取证、内存分析、磁盘取证或事件调查的请求。
performing-disk-forensics-investigation
使用取证镜像、文件系统分析、产物恢复和时间线重建进行磁盘取证调查,以支持事件响应案例。 使用 FTK Imager、Autopsy 和 The Sleuth Kit 等工具进行证据采集、已删除文件恢复和产物检查。 适用于磁盘取证、硬盘分析、取证镜像、文件恢复、证据采集或数字取证调查等请求场景。
performing-cloud-forensics-investigation
通过收集和分析来自 AWS、Azure 和 GCP 服务的日志、快照和元数据,在云环境中开展取证调查。
performing-adversary-in-the-middle-phishing-detection
检测和响应中间人(AiTM)钓鱼攻击,这类攻击使用 EvilProxy、Evilginx 和 Tycoon 2FA 等反向代理工具包绕过 MFA 并窃取会话令牌。
performing-active-directory-compromise-investigation
通过分析认证日志、复制元数据、组策略变更和 Kerberos 票据异常,调查 Active Directory 攻陷事件,识别攻击者持久化机制和横向移动路径。