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
Comments
14 Responses to “Protect WordPress Against Malicious URL Requests”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.










Great Tip, thanks
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!
Thanks for the timely fix.
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.
Great article, thank you!
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!!!
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/protect-wordpress-against-malicious-url-requests/
Thanks for letting us know. We updated the codes as well on this site.
Awesome! That fixed it. Thanks!
How easy is that?
Start to finish… 10mins.
Thanks for posting.
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.
Thnaks for such a great plugin and of course for sharing to world… God bless you..