Communitygithub.com

フィッシング調査のためのメールヘッダー解析

メールヘッダー(Receivedチェーン、Return-Path、Message-IDなど)を解析し、フィッシングメールの真の発信元を特定します。

フィッシング調査のためのメールヘッダー解析 とは?

このスキルは、フィッシングメールの調査において、メールヘッダーを徹底的に解析するための実践的なワークフローを提供します。Receivedヘッダーのチェーンを追跡してメールの配送経路を特定し、SPF、DKIM、DMARCの認証結果を検証することで、なりすましや偽装を検出します。Pythonスクリプトを使用してヘッダーを自動解析し、digやnslookupでDNSレコードを確認、さらにVirusTotalやAbuseIPDBなどの脅威インテリジェンスプラットフォームと連携してIPアドレスやドメインの評判を調査します。CEO詐欺(BEC)、認証情報収集型フィッシング、マルウェア添付、正規サービス悪用など、代表的なシナリオごとの分析手法もカバーしており、セキュリティインシデント対応やフォレンジック調査にすぐに活用できます。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/mukul975/Anthropic-Cybersecurity-Skills/tree/main/skills/analyzing-email-headers-for-phishing-investigation

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

フィッシング調査のためのメールヘッダー解析 は何をしますか?

使用タイミング

  • フィッシングメールの疑いがある場合、真の発信元を特定するため
  • 送信者の真正性を確認し、メールなりすましを検出するため
  • インシデント対応時にユーザーがフィッシングリンクをクリックした場合
  • 不審なメールの配送経路とリレーサーバーを追跡するため
  • SPF、DKIM、DMARCのアライメントを検証し、偽造を特定するため

前提条件

  • 不審なメッセージの生メールヘッダー(EML形式またはMSG形式)
  • SMTPプロトコルとメールヘッダーフィールドの理解
  • SPF/DKIM/DMARC検証のためのDNSルックアップツール(dig, nslookup)へのアクセス
  • メールヘッダー分析ツール(MHA、emailheaders.netの概念)
  • Pythonとメール解析ライブラリ(自動分析用)
  • IP/ドメインのレピュテーション確認のための脅威インテリジェンスプラットフォームへのアクセス

ワークフロー

ステップ1: 生メールヘッダーの抽出

# Outlookからエクスポート:メールを開く > ファイル > プロパティ > インターネットヘッダー
# 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: メールヘッダーチェーンの解析

# Pythonメールライブラリを使用してヘッダーを解析
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レコードの検証

# エンベロープ送信者ドメインを抽出
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:[email protected]; pct=100"

# 送信元IPをSPFに対して検証
# 最初の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='[email protected]',
    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: 送信者ドメインと基盤インフラの分析

# 送信者ドメインの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: メール本文と添付ファイルの調査

# メール本文から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(Sender Policy Framework)ドメインの許可されたメールサーバーを指定するDNSレコード
DKIM(DomainKeys Identified Mail)メールコンテンツの完全性を検証する暗号署名
DMARCSPFとDKIMを統合するポリシーフレームワーク。送信者認証に使用
Receivedヘッダー配送チェーンの各ホップを示すサーバー追加ヘッダー(下から上に読む)
Return-Pathバウンスメッセージ用のエンベロープ送信者アドレス。Fromと異なる場合あり
Message-ID送信メールサーバーが割り当てる一意の識別子
X-Originating-IP元の送信者IPアドレス(一部のメールサービスで追加)
ヘッダー偽装攻撃者はFrom、Reply-Toなどのヘッダーを偽装できるが、Receivedチェーンは偽装できない

ツールとシステム

ツール目的
MXToolboxオンラインメールヘッダー解析およびDNSルックアップ
dig/nslookupSPF、DKIM、DMARC検証のためのDNSレコードクエリ
pyspfPython SPFレコード検証ライブラリ
dkimpyPython DKIM署名検証ライブラリ
PhishTool専門的なフィッシングメール分析プラットフォーム
VirusTotalURLおよびファイルのレピュテーションチェックサービス
AbuseIPDBIPアドレスレピュテーションデータベース
whoisドメイン登録情報の検索

一般的なシナリオ

シナリオ1:CEO詐欺 / ビジネスメール詐欺(BEC) CEOからのメールを装っているが、Reply-ToがGmailアドレスを指している。SPFは送信元IPが偽装されたドメインに許可されていないため失敗し、DKIMは欠落、Fromドメインは類似ドメイン(ceo-company.com vs company.com)である。

シナリオ2:認証情報収集型フィッシング メールに「login.microsoft.com」と表示されるリンクが含まれているが、hrefは類似ドメインを指している。添付ファイルは偽のログインページを含むHTMLファイルで、認証情報を外部に送信するJavaScriptがある。送信ドメインは3日前に登録されたものである。

シナリオ3:マクロ付き添付ファイルによるマルウェア配信 Office文書が添付されたメール。送信者ドメインのSPFはパスするが、アカウントは侵害されている。DKIM署名は有効(正規のインフラから送信)。添付ファイルのSHA-256ハッシュはVirusTotalで既知のマルウェアと一致する。

シナリオ4:正規サービスを悪用した標的型フィッシング 攻撃者が正規のメールマーケティングサービスを利用してフィッシングを送信。SPFとDKIMはサービスが許可されているためパスする。フィッシングはインフラではなくコンテンツに存在するため、ヘッダー認証チェックではなくURLとコンテンツの分析が必要となる。

出力形式

メールヘッダー分析レポート:
  件名:     "緊急:請求書支払いのお願い"
  From:        [email protected] (偽装)
  Reply-To:    [email protected] (不一致)
  Return-Path: <[email protected]>
  日時:        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 -> mailbox

  認証:
    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...) - VTで既知のマルウェア

  リスクレベル: 高

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

abusing-dpapi-for-credential-access

Extract and decrypt Windows DPAPI-protected secrets (Credential Manager, browser logins/cookies, Wi-Fi credentials, KeePass keys) online or offline using SharpDPAPI, SharpChrome, Mimikatz, or Impacket

abusing-shadow-credentials-for-privesc

Take over Active Directory accounts by writing attacker-controlled public keys to msDS-KeyCredentialLink (Shadow Credentials) with pyWhisker, Whisker, or Certipy, then authenticate via PKINIT to recover the target

achieving-cmmc-level-2-compliance

>-

acquiring-disk-image-with-dd-and-dcfldd

Create forensically sound bit-for-bit disk images with dd or dcfldd on a Linux forensic workstation, preserving evidence integrity through hash verification (MD5/SHA) during acquisition. Use when imaging a suspect drive, USB device, or memory card for investigation, preserving volatile disk evidence during incident response, or producing a verified copy for legal or law-enforcement proceedings before any destructive analysis.

analyzing-active-directory-acl-abuse

Detect dangerous ACL misconfigurations in Active Directory using ldap3

analyzing-android-malware-with-apktool

Perform static analysis of Android APK malware using apktool for resource decompilation, jadx for Java source recovery, and androguard for manifest inspection, dangerous permission-combination detection, and identification of obfuscated code, dynamic code loading, and reflection-based API calls. Use to statically triage a suspicious APK without executing it or to build mobile malware detection rules.

analyzing-api-gateway-access-logs

Parses API Gateway access logs (AWS API Gateway, Kong, Nginx) to detect

analyzing-apt-group-with-mitre-navigator

Query ATT&CK data with attackcti, mitreattack-python, and stix2, then build MITRE ATT&CK Navigator layers and multi-layer heatmap overlays mapping one or more APT groups

analyzing-azure-activity-logs-for-threats

Queries Azure Monitor activity logs and sign-in logs via azure-monitor-query

analyzing-bootkit-and-rootkit-samples

Analyzes bootkit and advanced rootkit malware infecting the Master

analyzing-browser-forensics-with-hindsight

Parse Chromium-based browser databases with Hindsight to extract and correlate browsing history, downloads, cookies, cached content, autofill data, saved passwords, and extensions from Chrome, Edge, Brave, Opera, and Vivaldi into a unified timeline (XLSX, JSON, or SQLite output). Use during incident response, insider-threat investigations, or criminal cases when you need to reconstruct a user

analyzing-campaign-attribution-evidence

Systematically evaluate cyber-campaign evidence to attribute an operation to a threat actor, using the Diamond Model and Analysis of Competing Hypotheses (ACH) to weigh infrastructure overlaps, TTP consistency, malware code similarity, and timing/language artifacts into confidence-weighted attribution assessments. Use when an incident investigation needs a defensible attribution confidence level.

analyzing-certificate-transparency-for-phishing

Monitor Certificate Transparency logs using crt.sh and Certstream to

analyzing-cloud-storage-access-patterns

Detect abnormal access in AWS S3, GCS, and Azure Blob Storage by analyzing CloudTrail Data Events, GCS audit logs, and Azure Storage Analytics for after-hours bulk downloads, new-IP access, and API-call spikes (e.g. GetObject) via statistical baselines and time-series anomaly detection. Use when investigating suspected cloud data exfiltration or building related detection rules.

analyzing-cobalt-strike-beacon-configuration

Extract and analyze Cobalt Strike beacon configuration from PE files

analyzing-cobaltstrike-malleable-c2-profiles

Parse and analyze Cobalt Strike Malleable C2 profiles with dissect.cobaltstrike (profiles and beacon-payload configs) and pyMalleableC2 (AST parsing) to extract HTTP/DNS transforms, URIs, headers, sleep/jitter, and injection behavior, then generate network detection signatures. Use when reverse-engineering a captured malleable profile or building detections against Cobalt Strike Beacon traffic.

analyzing-command-and-control-communication

Analyzes malware C2 communication over HTTP, HTTPS, DNS, and custom

analyzing-cyber-kill-chain

Analyzes intrusion activity against the Lockheed Martin Cyber Kill Chain

analyzing-disk-image-with-autopsy

Perform comprehensive forensic analysis of raw (dd), E01, or AFF disk images with Autopsy and The Sleuth Kit, recovering deleted files, examining metadata and embedded artifacts, keyword searching, and building investigation timelines with visual reports. Use for structured analysis of a forensic disk image or when stakeholders need visual reports from evidence.

analyzing-dns-logs-for-exfiltration

Analyzes DNS query logs to detect data exfiltration via DNS tunneling,

関連スキル