Start a FREE 7 day trial! Get training videos and books, plus expert support:  

WordPress Tutorials and Blog Posts

Wordfence Protects Your WordPress Site From Hacks

tutuploadsmedia_1347216304512.png

WordPress is a very secure and well-coded platform. However, simply because it is so enormously popular, a lot of people try to create hacks and viruses for WordPress sites.

The Wordfence plugin is a great way to keep your WordPress site safe. Wordfence is a free plugin that scans your site for viruses, malware, trojans, malicious links and more.

In this tutorial, we're going to show you how to configure Wordfence, how to identify hacked files and what your options are for repairing them.

Step 1: Installation

You can get the Wordfence plugin from https://wordpress.org/extend/plugins/wordfence/ or search for Wordfence from the plugin page and click install.

There is a free version that does most everything you could want, and there is premium paid upgrade that gives you more functions and entitles you to priority support.

tutuploadsmedia_1347211245291.png
 

Step 2: Take the tour

Immediately after activation, you'll see the popup for a tour. It's worth the time for anyone new to web security to take this tour so you understand this plugin. After you're familiar, then you'll want to do a scan.

tutuploadsmedia_1347212459931.png

Step 3: Run a scan

  • Click Scan on the Wordfence menu.
  • Click Start a Wordfence Scan.
  • Wait for it to complete.
tutuploadsmedia_1347212693358.png
  • You will see problem areas marked in red. Don't panic this is normal on the first scan.
  • And there are two features that are disabled. Click the links to enable those.
  • Enable the two features to check your plugins and themes. This won't check your child themes. It will only check your original themes against the WordPress Theme repository.
tutuploadsmedia_1347212926063.png
  • Clicking the links will take you to the configuration settings.
  • It's a good idea to read all of your options and make sure you have things set the way you want.
  • Setting Alerts is a useful feature. Wordfence will email you whenever there's a possible problem.
  • Save your changes.
tutuploadsmedia_1347213164875.png
  • Return to Scans on the Wordfence menu.
  • Run the scan again.
  • If you see Problems found scroll to the bottom of the page to view the actual problem.
tutuploadsmedia_1347213806044.png

Step 4: Review and fix errors or warnings

  • You will most likely see these two warnings. This is nothing to worry about. These are log files. They are not dangerous, and if you view them you will see PHP warnings and actual errors.
  • Check he links at the bottom of each one to see how you can deal with them.
tutuploadsmedia_1347213922610.png
  • You have several options.
  • You can actually view the log from here if you suspect there is an error that needs fixing. I wouldn't recommend deleting the file since you may need it.
  • You can choose to have Wordfence ignore the file if you don't want to see this warning every time you do a scan. I decided to just leave things as they are. It just makes it easy to check the logs after a scan and I like the convenience of the handy link.
tutuploadsmedia_1347214154807.png

Step 5: Dealing with a hacked site

  • If a core file has been hacked, and code inserted, Wordfence compares your code to the core files in the WordPress repository and issues an alert.
  • This is a cause for concern, but not necessarily time to panic.
  • Click the link See how the file has changed.
tutuploadsmedia_1347214578384.png
  • You'll see the original file right next to the modified version.
  • In this case, I made a correction to a file that was missing an end tag. Not serious and not something I really need to fix, since this reflects a change I made myself.
  • If you see a lot of encoded characters, or any code you don't recognize, this is a very bad sign. We'll give you a todo list for dealing with it below.
tutuploadsmedia_1347208750827.png
  • This isn't a problem so choose Ignore until the file changes.
  • Since this is an index file and one that could possibly be attacked, I want to be alerted if someone else alters the file. I don't want to ignore changes forever.
tutuploadsmedia_1347215000612.png
 
What should you do if your site has been hacked? Here are the steps to take to clean your site:

Steps to clean your site after a hack

  1. Upgrade your site to the newest version of WordPress.
  2. Upgrade all your themes and plugins to their newest versions.
  3. Change all passwords on the site.
  4. Backup all your files and the database.
  5. Go to the Wordfence options page and make sure the options to scan core, theme and plugin files are selected. Then run a Wordfence scan. This compares your core, theme and plugin files against the original versions in the WordPress repository and lets you know how a hacker has changed them.
  6. When the results come up you may see a very long list of infected files. Take your time and slowly work through the list.
  7. Examine any suspicious files and delete them if they are dangerous. Remember that you can’t undo deletions.
  8. Look at any changed core, theme and plugin files. Use the option Wordfence provides to see what has changed between the original file and your file. If the changes look malicious, use the Wordfence option to repair the file.
  9. Look at any unknown files that are in core directories and delete them if necessary.
  10. Slowly work your way through the list until it is empty.
  11. Run another scan and confirm your site is clean.
  12. If you are still getting an alert from another product or from Google that says your site has a problem, get support from Wordfence and your web host.

Finally, if you do use a WordPress-only hosting company such as WPEngine or Pagely, don't be afraid to check with your hosting company and see if they have an process for cleaning your site. Many WordPress-only hosting companies help you clean up after a hack.

 

Start a FREE 7 day trial! Get training videos and books, plus expert support:  

License

All of our tutorials are published under the Creative Commons Attribution-NonCommercial license. This means:
  • You can re-use these tutorials.
  • You can modify these tutorials.
  • You must link back to our original tutorial.
  • You can't use these tutorials commercially.
Click here to read the full license.