# Analyzing Email Headers For Phishing Investigation

> 解析和分析电子邮件头部以追踪钓鱼邮件的来源，通过 SPF、DKIM 和 DMARC 验证来核实发件人真实性并识别伪造行为。

- **Type:** Skill
- **Install:** `agentstack add skill-killvxk-cybersecurity-skills-zh-analyzing-email-headers-for-phishing-investigation`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [killvxk](https://agentstack.voostack.com/s/killvxk)
- **Installs:** 0
- **Category:** [Communication](https://agentstack.voostack.com/c/communication)
- **Latest version:** 0.1.0
- **License:** Apache-2.0
- **Upstream author:** [killvxk](https://github.com/killvxk)
- **Source:** https://github.com/killvxk/cybersecurity-skills-zh/tree/master/skills/analyzing-email-headers-for-phishing-investigation

## Install

```sh
agentstack add skill-killvxk-cybersecurity-skills-zh-analyzing-email-headers-for-phishing-investigation
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# 分析电子邮件头部用于钓鱼调查

## 适用场景
- 调查疑似钓鱼（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  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 "\']+', content)
    print("=== 邮件正文中发现的 URL ===")
    for url in set(urls):
        print(f"  {url}")

    # 检查 URL 混淆（显示文本 != href）
    href_pattern = re.findall(r']*href=["\']([^"\']+)["\'][^>]*>(.*?)', content, re.DOTALL)
    print("\n=== 超链接分析 ===")
    for href, text in href_pattern:
        display_url = re.findall(r'https?://[^\s 实际='{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: 
  日期:     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 上的已知恶意软件

  风险级别: 高危
```

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [killvxk](https://github.com/killvxk)
- **Source:** [killvxk/cybersecurity-skills-zh](https://github.com/killvxk/cybersecurity-skills-zh)
- **License:** Apache-2.0

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** yes
- **Filesystem access:** yes
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-killvxk-cybersecurity-skills-zh-analyzing-email-headers-for-phishing-investigation
- Seller: https://agentstack.voostack.com/s/killvxk
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
