How to protect your wp-admin folder when you have a dynamic IP address

No Comments

Wordpress

Wordpress

If you have a self-hosted WordPress blog, I hope that you are thinking about security. The best thing you can do is to use the automatic updates so you always have the current version of WordPress.

One of the most pernicious hacks someone can do to your blog is to access to your wp-admin folder. This folder contains the back-end PHP pages of your site where you control everything and write your posts.

Via your web-host’s control panel you might be able to password protect this directory, although that could still be brute forced. An alternative method, which is well documented (see reference links below), is to create a “.htaccess” file in your wp-admin directory, with which you can limit access to a specific set of IP addresses. E.g. your home IP address and your work IP address. See the references below for links on how to write this.

This method is perfect for locking down and restricting who can access your admin pages without having to go through any sort of manual authentication. I held off doing this for a long time because my ISP assigns dynamic IP addresses, and my Netgear router needs frequent reboots. So my IP address changes a lot, so I’d keep getting locked out of my own blog!

To get around this, I thought of a script I could write to keep my wp-admin’s .htaccess file automatically updated! You could even use this if you took your laptop away from home and connected on another network, as your laptop will have your ssh keys installed. Try to stickto using a secure VPN though, just on principal :)

Sorry, it’s a bash script, so if you use Windows you’ll be stuck unless you install the cygwin environment and PuTTY. If you use a Mac, I’m sure you can switch on the bash shell.

Without further ado, here’s the script:
Note: make sure you have cURL installed first.

#! /bin/bash
# Auto-update .htaccess in http://your-blog/wp-admin/
# Run this from cron on a short interval.
# This will grab your IP address, and then rewrite the
# .htaccess file and use scp to upload to your server.
#
# David.R.Gilson 3rd October 2009
# http://www.davidgilson.co.uk
# I distrobute this under the Creative Commons Attribution
Share Alike license.
# http://creativecommons.org/licenses/by-sa/3.0/

cd ~


# Grab your external IP address.
ip="$(curl www.whatismyip.org)"
ip="$(curl -s checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//')"

# Write the file.
echo "AuthUserFile /dev/null" > htacc.txt
echo "AuthGroupFile /dev/null" >> htacc.txt
echo -e "AuthName \042Limit wp-admin access\042" >> htacc.txt
echo "AuthType Basic" >> htacc.txt
echo "<LIMIT GET>" >> htacc.txt
echo "order deny,allow" >> htacc.txt
echo "deny from all" >> htacc.txt
echo "# Whitelist home router" >> htacc.txt
echo "allow from "$ip >> htacc.txt
echo "</LIMIT>" >> htacc.txt


# Copy to server
scp htacc.txt [YOUR SSH LOGIN HERE]:"~/www/wp-admin/.htaccess"

# Clean up
rm htacc.txt

Once you’ve pasted all that into a file (I named mine htaccessupdate.sh), remember to make it executable by typing chmod +x htaccessupdate.sh.

References

ip=”$(curl -s checkip.dyndns.org|sed -e ‘s/.*Current IP Address: //’ -e ‘s/<.*$//’)”

Share this post

Tip of the week – 24th July 2009

2 Comments

Okay, so we all know we can check where a link is going to send you by hovering the mouse over it and looking at the status bar of your browser (you did know that didn’t you?).

So that’s one tool we have to defend against phishing, although what about web forms? Firefox doesn’t show you where you’ll get bumped after clicking on that submit button.

Well, with this add-on, now you can! FormFox will display the target URL of a form if you just hover your mouse over the corresponding button.
https://addons.mozilla.org/en-US/firefox/addon/1579

I’ve also found out that this functionality is built-in to Internet Explorer 7 too.

Share this post

Tip of the week – 12th June 2009

No Comments

[Security Tip]

If you want to test how good your hardware or software firewall is, then there is a SAFE website you can visit which will probe your defences !

It’s called “Sheilds Up” and you can see it at:
https://www.grc.com/x/ne.dll?bh0bkyd2

Share this post

Tip of the week – 5th June 2009

No Comments

[Security Tips]

If you were using one of the passwords from the website yesterday, you have a better memory than mine if you can memorize them! This probably means that you’re going to need to store those passwords in a file.

The people who make Truecrypt are aware of this, and when you are setting up an encrypted volume (see last Thursday’s tip), you can choose to use a keyfile if you wish.

So here’s an idea, go back a few tips about encrypting your documents folder. You could keep all your keyfiles on a USB flash drive, such that your documents folder would only be “unlocked” when you had that flash drive plugged in. Such that you kind of have a security key to unlock your flies.

Just make sure you take very good care of your key drive!

Share this post

Tip of the week – 29th May 2009

1 Comment

[Security Tip]

If you need to generate very strong random passwords for your security passwords, I’d like to recommend the GRC password generator:

https://www.grc.com/passwords.htm

This page will also explain how the passwords are generated and what makes them strong.

Share this post

Older Entries