Get a domain name


Guarding WordPress Against Hacker URL Requests

Mon, Dec 28, 2009

Adding To WordPress

Update: This plugin can now be found in the WordPress plugin repository for easy installs.

I was skimming through my Google FeedReader the other day and read an excellent article by Jeff Starr of Perishable Press which showed us how to create a very simple plugin to help protect our WordPress sites from malicious WordPress crackers.

He found this code in the pastebin repository, a site where people who write computer code can come together and help one another.

A dead giveaway that someone is trying to hack into your blog is when you see terms like the following being used:

  • base64()
  • eval()

The plugin shown below will attempt to block such requests. So with that, let’s get on to the tutorial.

The How-To Video

Remember you can click the “full view” button to see it a little better.

Step-by-Step

Step1: Head over to Perishable Press and copy the code Jeff shows us by clicking here (link opens in a new window).

Step 2: Open a text editor and paste the code in. Be sure to save the file as a .php file (for example, block-bad-requests.php).

Step 3: Zip up the file you just created using a zip program like WinZip or the zip utility that comes with Windows.

zip the file

Step4: Upload, install, and activate the plugin.

Quick, simple, and effective.

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Related posts:

  1. How To Upgrade WordPress Manually
  2. How To Install Google Analytics On A WordPress Blog Without Using A Plugin
  3. How To Move Your WordPress Core Files Out Of Root
  4. How To Backup Your WordPress Blog’s Database With A Plugin

,
John's Wishlist

17 Responses to “Guarding WordPress Against Hacker URL Requests”

  1. Keith Davis Says:

    Hi John
    Best of both worlds… video and screenshots.
    You’re spoiling us John!
    If I create this plugin, can I advertise myself as a Wordpress plugin developer? LOL
    I’m with you on security so this will be my first plugin of the new year.

  2. Keith Davis Says:

    Sorry John,I forgot to ask…
    Presumably you can simply upload the .php file to your plugins directory and then activate it via the dashboard?

  3. John Hoff Says:

    Hey Keith. Yeah it’s a pretty neat little piece of code.

    Yes, you should be able to upload the php file to your plugins directory and activate it. Should be no problem there.

    I assume you’re using FTP for that…?

    If you can, try to use SFTP or FTPS. Check with your web host to see if you have that option, that way your FTP login info will be encrypted and not easily obtained.

  4. Keith Davis Says:

    Thanks John

    I use FTP over explicit TLS/SSL, which my hosting service tells me is secure.

  5. John Hoff Says:

    That’s good, Keith. That’s what we offer as well.

  6. Keith Davis Says:

    John if my hosting company weren’t so good… I would have signed up with you long ago.

    After my early attempts at FTP, my hosting company used to send me emails saying that they had moved my files to the correct directory LOL

  7. Keith Davis Says:

    All done John
    Uploaded and activated in less than 10mins.
    Thanks for spending time to make it easy for the rest of us.

  8. John Hoff Says:

    Very cool, Keith. It’s my pleasure. Thanks for reading! :)

  9. Keith Davis Says:

    Hi John
    I’ve just noticed your comments over at Perishable Press about adding to the code there.
    I copied the code from the top of the page but your comment suggests that we should be using the code from comment number 20.
    Is that correct?

  10. John Hoff Says:

    Jeff updated the post with the best code to use. Make sure you use the updated code in his post. That’s the best one to use.

  11. Anysia (Booklorn on Twitter) Says:

    This is now available as a plugin at Wordpress.org, FYI. Came here from your ebook, went through all this, only to have WordPress immediately tell me that the plugin was out of date and to download the new version from WP.org.

  12. John Hoff Says:

    Hi Anysia. Thanks for purchasing the ebook, I hope you like it.

    Thanks for the update on the plugin. I added Jeff’s plugin to the ebook at the last minute. He wrote the plugin and I emailed him asking if it was ok to put it in the book. Good to know it’s now available for everyone in the plugin repository. It’s a great (and simple) plugin.

  13. Keith Davis Says:

    Hi
    Just looked at Wordpress plugins repository – presumably the plugin is the “Block Bad Queries (BBQ)” by Jeff Starr.

  14. John Hoff Says:

    Hi Keith… yep it is and I definitely gave him full credit for the plugin in the post above and also in WordPress Defender.

    I made sure to ask him if first if I could include it in WordPress Defender.

    Yeah Anysia (above) mentioned it, too. After this comment I’ll log in and update the post.

    Thanks for spotting it.

  15. Keith Davis Says:

    John
    When I created the plugin as shown above, I didn’t call it “Block Bad Queries”

    I’m guessing that this plugin does not create any database tables so I can simply delete the one I created and upload Jeff’s.

  16. John Hoff Says:

    @Keith – yep, you’re good to go to deactivate and delete the version you have and then upload and activate the latest version plugin.

    Hint: To find it easily, go to Plugins -> Add New in your blog’s sidebar and search for BBQ.

    That should bring it up quick.

  17. Keith Davis Says:

    Thanks John
    Much appreciated.


Leave a Reply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