Skip to content

Instantly share code, notes, and snippets.

@jaydansand
Last active August 18, 2020 21:06
Show Gist options
  • Select an option

  • Save jaydansand/dcb66a0e36365c178a91 to your computer and use it in GitHub Desktop.

Select an option

Save jaydansand/dcb66a0e36365c178a91 to your computer and use it in GitHub Desktop.

Revisions

  1. jaydansand revised this gist Nov 13, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions xmlrpc-slowdown.php
    Original file line number Diff line number Diff line change
    @@ -4,8 +4,8 @@
    Plugin URI:
    Description: Deliberately introduce some delay into XMLRPC calls to rate limit brute-force and DoS attacks.
    Version: 1.0
    Author: Jay Dansand
    Author URI:
    Author: Jay Dansand, Technology Services, Lawrence University
    Author URI: https://gist.github.com/jaydansand
    */

    /* Copyright 2014 Lawrence University
  2. jaydansand revised this gist Jul 29, 2014. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions xmlrpc-slowdown.php
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,21 @@
    Author URI:
    */

    /* Copyright 2014 Lawrence University
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License, version 2, as
    published by the Free Software Foundation.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
    */

    /**
    * Implement filters xmlrpc_enabled and xmlrpc_login_error.
    *
  3. jaydansand created this gist Jul 29, 2014.
    27 changes: 27 additions & 0 deletions xmlrpc-slowdown.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    <?php
    /*
    Plugin Name: XMLRPC Slowdown
    Plugin URI:
    Description: Deliberately introduce some delay into XMLRPC calls to rate limit brute-force and DoS attacks.
    Version: 1.0
    Author: Jay Dansand
    Author URI:
    */

    /**
    * Implement filters xmlrpc_enabled and xmlrpc_login_error.
    *
    * @see class-wp-xmlrpc-server.php
    */
    function xmlrpc_slowdown_filter_sleep($arg) {
    // Keep track of calls (should be 1 or 2) to increase delay
    // when called after a login failure.
    static $calls = 0;
    ++$calls;
    $rand = function_exists('mt_rand') ? 'mt_rand' : 'rand';
    usleep(call_user_func($rand, 500000 * $calls, 2000000 * $calls));
    return $arg;
    }

    add_filter('xmlrpc_enabled', 'xmlrpc_slowdown_filter_sleep');
    add_filter('xmlrpc_login_error', 'xmlrpc_slowdown_filter_sleep');