Free Wordpress Blog Setup

Protect WordPress Against Malicious URL Requests

By Editorial Staff in Wordpress Plugins
Protect WordPress Against Malicious URL Requests

In early September, many WordPress sites were infected with Malicious codes. We wrote a quick fix for that issue which you can see in this post, but recently Jeff Starr from Perishable Press has come with a solution to protect WordPress from future attacks as well.

Simply open a new php file and paste the following codes:

<?php
/*
Plugin Name: Block Bad Queries
Plugin URI: http://perishablepress.com/press/2009/12/22/protect-wordpress-against-malicious-url-requests/
Description: Protect WordPress Against Malicious URL Requests
Author URI: http://perishablepress.com/
Author: Perishable Press
Version: 1.0
*/
global $user_ID; if($user_ID) {
if(!current_user_can('level_10')) {
if (strlen($_SERVER['REQUEST_URI']) > 255 ||
strpos($_SERVER['REQUEST_URI'], "eval(") ||
strpos($_SERVER['REQUEST_URI'], "CONCAT") ||
strpos($_SERVER['REQUEST_URI'], "UNION SELECT") ||
strpos($_SERVER['REQUEST_URI'], "base64")) {
@header("HTTP/1.1 414 Request-URI Too Long");
@header("Status: 414 Request-URI Too Long");
@header("Connection: Close");
@exit;
}
}
} ?>

Codes updated on Jan. 10, 2010.

Save this file and upload it in your plugin directory /wp-content/plugins/ and your work is done. This script will check for long strings as well as base64 code which was in the last attack and the eval( code which could be a threat in the future.

Once active, this plugin will silently and effectively close any connections for these sorts of injection-type attacks.

Source: Perishable Press

What Next?

Digg it
Save This Page
Subscribe to WPBeginner
Stumble it
Free Wordpress Blog Setup

Comments

14 Responses to “Protect WordPress Against Malicious URL Requests”
  1. DeKo says:

    Great Tip, thanks

  2. Man I’m glad I ran into this article, I am always afraid of having my blog compromised to some degree and this article really sets aside a lot of fears. Security is my #1 concern with all of my websites, so naturally WordPress security is high up there!

  3. Simon Petry says:

    Thanks for the timely fix.

  4. Herrin says:

    Always good to get easy to implement WordPress security tips, just wondering something:

    What should we call the php file? Does it matter?

    Ok thanks, look forward to more of your articles.

  5. Jenna Molby says:

    Great article, thank you!

  6. Trisha says:

    Wow, thanks for a great fix! I just installed and activated and no problems so far. Since I got an injector virus a while back, on every WP install, I immediately plug in secure wordpress and user locker. This is also going in my security bag! Thanks again!!!

  7. Trisha says:

    uh oh, getting a double header error.
    (already sent by pluggable.php)

    any ideas?

  8. Keith Davis says:

    How easy is that?
    Start to finish… 10mins.
    Thanks for posting.

  9. Hmm, you can get the same thing using the plugin named “wordpress firewall”. I get a nice email each time there’s a (hopefully blocked) tentative.

  10. bhagu says:

    Thnaks for such a great plugin and of course for sharing to world… God bless you..

Share Your Opinions

Tell us what you're thinking...
and if you want a pic to show with your comment, then get gravatar!

Please make sure that you have read our Comment Policy.

Due to high volume of request from our readers, we are adding this feature that allows you to stay updated with this post's comments without having to participate in the discussion even though we would love your input as always. Don't worry we hate SPAM just as much as you do, so you will never receive any SPAM messages from our site and that's our promise to you.

Subscribe without commenting

Close Bar