Protect WordPress Against Malicious URL Requests

Posted on December 23rd, 2009 by in WordPress Plugins | 17 Comments  
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

About

Editorial Staff at WPBeginner mainly Syed and David.

Post comment as twitter logo facebook logo
Sort: Newest | Oldest
davidj 5 pts

How do I open a new Php file? I'm completely new to technical side of Word Press >.<.. is it via FTP?

wpbeginner 50 pts moderator

davidj You can open a PHP file using any text editor including notepad...

nurulimam 5 pts

Thanks for simple plugin but fowerfull

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

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.

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

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

any ideas?

If you scroll down in this link, there's an update to the code.

http://perishablepress.com/press/2009/12/22/protec...

Thanks for letting us know. We updated the codes as well on this site.

Awesome! That fixed it. Thanks!

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

Great article, thank you!

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.

You may name it whatever you like.

Thanks for the timely fix.

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!

Tweets about us: