Giter Club home page Giter Club logo

waf4wordpress's Introduction

WAF for WordPress

Stop real-life attacks on your WordPress website and trigger Fail2ban.

This WAF does not give proper HTTP responses to unusual requets. It blocks the attacking IP address instantly, the purpose of this are the following.

  1. Prevent website compromise in further requests
  2. Prevent D/DoS attacks

Shared hosting has no server-wide banning (because of trust issues) but you can still install this software without Fail2ban to stop attacks by using one of the Miniban methods.

Theory

Your WordPress - really general HTTP - security consists of:

  1. Use HTTPS
  2. Have daily backups
  3. Block known hostile networks
  4. Have Fail2ban installed (controls the firewall)
  5. Maintain your website and use strict Fail2ban filters which ban on the first suspicious request instantly
  6. Deny direct access to core WordPress files, themes and plugins
  7. Install WAF for WordPress (this project)
  8. Use Leanmail for filtering Fail2ban notification emails

See the Block WordPress attack vectors note in my other repository for an overview of the topic.

Installation of Http_Analyzer class

Examines headers in the HTTP requests and triggers Fail2ban accordingly.

To install it copy http-analyzer/waf4wordpress-http-analyzer.php beside your wp-config.php and copy these lines in top of wp-config.php:

/** Security */
require_once __DIR__ . '/waf4wordpress-http-analyzer.php';
new \Waf4WordPress\Http_Analyzer();

A better solution is to load it from the auto_prepend_file PHP directive. This time you have to copy the above code in the class file.

Installation of Core_Events class

It is an MU plugin that triggers Fail2ban on various WordPress specific attack types. Login is only logged, use Http_Analyzer class for handling that.

To install copy core-events/waf4wordpress-core-events.php into your wp-content/mu-plugins/ directory. You may have to create the mu-plugins directory. It activates automatically.

About the non-wp-projects directory

Triggers Fail2ban on WordPress login probes in any project.

To install copy the fake non-wp-projects/wp-login.phpand non-wp-projects/xmlrpc.php to your non-WordPress project's document root.

Not available in WordPress.org's plugin directory

After is it published on WordPress.org you can install the plugin and skip file copying.
That way it'll be installed automatically.

How to support PayPal IPN, Braintree and custom entry points in poorly written plugins

Copy this into your in wp-config.php.

// Enable PayPal IPN in WooCommerce
if ( isset( $_SERVER['REQUEST_URI'] ) ) {
    if ( '/wc-api/WC_Gateway_Paypal/' === parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) ) {
        // PayPal IPN does not send Accept: and User-Agent: headers
        $_SERVER['HTTP_ACCEPT'] = '*/*';
        $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 PayPal/IPN';
    }
}

// Enable Braintree Webhooks
new \Waf4WordPress\Braintree_Fix( '/braintree/webhook' );

// Enable email opens in Newsletter plugin
if ( isset( $_SERVER['REQUEST_URI'] ) ) {
    $newsletter_path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
    if ( '/wp-content/plugins/newsletter/statistics/open.php' === $newsletter_path
        || '/wp-content/plugins/newsletter/statistics/link.php' === $newsletter_path
    ) {
        // UA hack for old email clients
        $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 ' . $_SERVER['HTTP_USER_AGENT'];
    }
    unset( $newsletter_path );
}

// Enable email open tracking in ALO EasyMail Newsletter plugin
if ( isset( $_SERVER['REQUEST_URI'] ) ) {
    $alo_path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
    if ( '/wp-content/plugins/alo-easymail/tr.php' === $alo_path ) {
        // UA hack for old email clients
        $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 ' . $_SERVER['HTTP_USER_AGENT'];
    }
    unset( $alo_path );
}

Support and feature requests

Open a new issue

waf4wordpress's People

Contributors

szepeviktor avatar leonstafford avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.