2026年5月20日

2026年5月20日

WordPressセキュリティプラグインの選び方と設定方法

はじめに

WordPressのセキュリティプラグインはWAF(Webアプリケーションファイアウォール)・マルウェアスキャン・ログイン保護・ファイル変更監視などの多機能を提供します。主要3プラグインの特徴と推奨設定を解説します。

症状・原因

  • サイトが攻撃されているがどこから来ているか分からない
  • マルウェア感染の早期検出の仕組みがない
  • ログイン試行が多くサーバー負荷が高い
  • ファイルが改ざんされても気づかない

解決手順

ステップ1:プラグインを比較・選択する

主要セキュリティプラグイン比較:

┌─────────────────┬──────────┬──────────┬──────────────────┐
│ 機能            │Wordfence │ Sucuri   │ iThemes Security │
├─────────────────┼──────────┼──────────┼──────────────────┤
│ WAF(無料)     │ ○(学習型)│ △(有料)│ △               │
│ マルウェアスキャン│ ○        │ ○        │ ○               │
│ ログイン保護    │ ○        │ ○        │ ○               │
│ リアルタイム IP │ ○(有料) │ ○(有料)│ ×               │
│ ファイル監視    │ ○        │ ○        │ ○               │
│ 価格/年         │ 無料〜$99 │ 無料〜$229│ 無料〜$99       │
└─────────────────┴──────────┴──────────┴──────────────────┘

推奨:
  - 予算なし: Wordfence 無料版
  - 高トラフィック: Sucuri(CDN付きWAF)
  - 設定の簡単さ: iThemes Security

ステップ2:Wordfence の推奨設定

Wordfence 設定手順:

1. ファイアウォール設定(Wordfence → ファイアウォール):
   - WAFステータス: 有効(拡張保護)
   - 自動ブロック: 有効
   - ブルートフォース保護: 有効
   - レート制限: 人間以外のトラフィックを制限

2. スキャン設定(Wordfence → スキャン):
   - スキャンスケジュール: 毎日
   - スキャンの種類: 高感度
   - メール通知: 管理者メールに送信

3. ログイン保護(Wordfence → ログインセキュリティ):
   - 二段階認証: 有効化(管理者に必須)
   - ログイン試行回数制限: 5回
   - パスワード監査: 弱いパスワードを使用しているユーザーを通知
// functions.php: Wordfenceのアラートをカスタマイズ

// Wordfenceのメール通知に管理者メールを追加
add_filter('wordfence_alert_email_to', function (array $emails): array {
    $emails[] = 'security@example.com'; // セキュリティ担当者のメール
    return $emails;
});

// WordfenceがブロックしたIPをログに記録
add_action('wordfence_block_ip', function (string $ip, string $reason): void {
    error_log("Wordfence blocked IP: {$ip} Reason: {$reason}");
}, 10, 2);

ステップ3:Sucuri Security の設定

Sucuri Security 設定手順:

1. 設定 → Sucuri Security:
   ✓ コアファイルの整合性チェック
   ✓ プラグイン・テーマの整合性チェック
   ✓ ポストハック機能を有効化

2. 監査ログ(Sucuri → 監査ログ):
   ユーザーの行動・ファイル変更・ログインをすべて記録

3. アラート設定:
   - 管理者ユーザーのログイン: 通知
   - プラグインの有効化/無効化: 通知
   - ファイルの変更: 通知

4. Sucuri WAF(有料 $9.99/月〜):
   CloudflareのようなCDN型WAFで、サーバーに到達する前にブロック

ステップ4:ファイル変更を自動検知する

// functions.php: 重要ファイルの変更を検知してメール通知

function mytheme_check_file_integrity(): void {
    $files_to_monitor = [
        ABSPATH . 'wp-config.php',
        ABSPATH . '.htaccess',
        get_template_directory() . '/functions.php',
    ];

    foreach ($files_to_monitor as $file) {
        if (!file_exists($file)) {
            continue;
        }
        $current_hash = md5_file($file);
        $option_key   = 'file_hash_' . md5($file);
        $stored_hash  = get_option($option_key);

        if ($stored_hash === false) {
            // 初回: ハッシュを記録
            update_option($option_key, $current_hash, false);
        } elseif ($stored_hash !== $current_hash) {
            // ハッシュが変わった: メール通知
            wp_mail(
                get_option('admin_email'),
                'WordPressファイル変更検知: ' . basename($file),
                "以下のファイルが変更されました:\n{$file}\n\n変更日時: " . date('Y-m-d H:i:s')
            );
            update_option($option_key, $current_hash, false);
        }
    }
}
// 日次スケジュールで実行
add_action('mytheme_daily_security_check', 'mytheme_check_file_integrity');

if (!wp_next_scheduled('mytheme_daily_security_check')) {
    wp_schedule_event(time(), 'daily', 'mytheme_daily_security_check');
}

ステップ5:セキュリティヘッダーを設定する

// functions.php: セキュリティ関連HTTPヘッダーを追加

add_action('send_headers', function (): void {
    if (headers_sent()) {
        return;
    }
    // クリックジャッキング防止
    header('X-Frame-Options: SAMEORIGIN');
    // MIMEタイプスニッフィング防止
    header('X-Content-Type-Options: nosniff');
    // XSS対策(古いブラウザ向け)
    header('X-XSS-Protection: 1; mode=block');
    // リファラー情報を制限
    header('Referrer-Policy: strict-origin-when-cross-origin');
    // HTTPS強制(HSTSは別途設定推奨)
    if (is_ssl()) {
        header('Strict-Transport-Security: max-age=31536000; includeSubDomains');
    }
});

注意事項

  • セキュリティプラグインを複数インストールすると競合して誤検知・サイト停止が発生します。1つだけ使用してください
  • Wordfenceの無料WAFは「学習モード」から始まります。初回は1週間ほど学習期間を設けてから「有効(拡張保護)」に切り替えてください
  • セキュリティプラグインはパフォーマンスに影響します。有効にした後はPageSpeed Insightsでスコアを確認してください

まとめ

予算なしならWordfence無料版でWAF・ログイン保護・日次スキャンを有効にします。wp_mailmd5_file を組み合わせた独自ファイル変更監視を実装し、send_headers フックでX-Frame-Options等のセキュリティヘッダーを追加します。セキュリティプラグインは1つに絞り、学習期間後に保護を最大化します。

お気軽にご相談ください

お見積りへ お問い合わせへ