How to Detect and Prevent a WordPress Spam Injection Attack

Dec 17
10:40

2009

Chris London

Chris London

  • Share this article on Facebook
  • Share this article on Twitter
  • Share this article on Linkedin

Recovering from a WordPress Spam Injection attack is not fun, but you can regain your Google Search Results after being hacked by a spam injection attack.

mediaimage
Last month my WordPress blog was the victim of a spam injection attack. I am the art director for a highly rated graphic design and website design company. I have years of experience in website design,How to Detect and Prevent a WordPress Spam Injection Attack Articles WordPress Blog Design and I am security minded in my approach to web development - I was still a victim of clever hacking. It can happen to anyone and it is happening at an increasingly alarming rate. The worst part about this experience was that not only my WordPress blog was attacked - my entire corporate website was removed from Google SERPS. We were ranked in the Google Top 10 for several coveted spots such as; graphic design company, packaging design companies, brand identity company, and many more. Our site was completely out of Google search results for two weeks in which time we lost countless leads. This experience absolutely sickened me! It also created way too many hours of work dedicated to repairing the hackers damage and recovering our website's Google Rankings. During my research into fixing the spam injection hackers damage I discovered that this is a widespread problem with WordPress blogs. It's happening to thousands of people and it is not limited to people using older versions of WordPress.

Recovering from a WordPress Spam Injection attack is not fun, but you can regain your Google Website Rankings after being hacked by a spam injection attack. If you've been compromised, hopefully you have your website and WordPress blog backed up. It can be a pretty tedious process to go through every file and folder on your server locating and deleting spam files. I recommend backing up your WordPress posts and completely removing all files and databases from your server. Then do a complete fresh upload of your website and a complete reinstall of WordPress.

If you have already been removed from Google Search Results then you will want to notify Google immediately of what has happened. The best policy with Google is to be specific in your explanations. You will need to make sure that you have removed all bad files from your server and then contact Google again explaining what actions you have taken to resolve the situation and submit your "request for reconsideration". In most cases where a valid site has been hacked Google will restore their sites rankings within two weeks. However, don't expect any notifications from Google on their progress of reevaluating your website or WordPress blog. I am writing this article in hopes that it will help anyone from having to go through that processs.

What should you look for if you suspect a WordPress Spam Injection Attack?

The first thing you should look for is a list of spammy keywords showing up in your list of keywords located in your Google Webmasters Tools. If you aren't using Google Webmaster Tools then you should definitely look into this. When your site starts showing up in weird looking search results, which can also be seen in Google Webmaster Tools under search results for your site, you need to act fast because at this point Google will act fast to remove your site from SERPS in order to protect others who may be at risk from visiting your website.

The key to detection is awareness. Be vigilant in monitoring your website and your website's stats. Spam injections are a clever, effective form of hacking and show no outward signs of infection. However, If you do a Google Site Search for spammy key words like; {site:yoursite.com viagra} you will be able to see if your site is referencing spam keywords. You will not be able to see spam showing up on your site. In order to physically see spam tags in your site you must go to the "cached" version of your web pages and view them in "text mode". If you've been infected you will now be able to see spam keywords, usually appearing as a footer.

What does a Spam Injection Do?

Spam Injection software hides spam keyword links in code that is usually encoded with a PHP function that effectively scrambles html to be decoded once safely embedded on your server, database, etc. You won't see these files decoded, but the Google Bot and other bots will when crawling your site! Once the Bots access the code the spam injection software has done it's work, effectively stealing your search index to improve their own pagerank.

These spam injection hacks are very hard to detect software injections inserted into your site, usually on a database level, via templates or plugins. This is part of the reason WordPress is such a target for these attacks. Plugins are what make WordPress so dynamic and cool, but they are an open doorway for spam injection software. For obvious reasons we should all focus our attention on prevention so that you don't have to deal with detection.

What can I do to prevent a WordPress Spam Injection Attack?

I'll start with the simplest things you can do to protect your WordPress blog or site from spam attacks first. . .

First: Update WordPress Updating WordPress is the easiest thing to do, so why not do it? I usually wait a short period of time after a new release to make sure the bug fixes have been worked out. Please be aware that simply updating WordPress is NOT enough!

Second: Pick a good password Pick a good password. Don't use the same password on every site. If you're really diligent you can also change your password regularly.

Third: Change the admin user name The default WordPress user name is "admin". This is just a guess, but I suspect that the majority of people never change this. Don't give any information away. Hackers are clever, but like burglars they would rather move on to the easy score. You can change your admin by creating a new user and then deleting the admin user. You'll be given the option to migrate posts to another user.

Fourth: Hide your WordPress Version Number

David Kierznowski of blogsecurity.net lately released a simple plugin to hide your wordpress installation version number. The no version plugin is a simple plugin that will replace the version number with blanks, so anyone doing a view "page source" from the browser on your site will not be able to see your wordpress version.

Fifth: Protect your plugins Plugins are the easy gateway way for hackers to access your blog. All WordPress files begin with (wp-) by default so, hackers can quickly discover which plugins you're using by going to /wp-content/plugins/, if you haven't renamed your database files. A quick remedy to block a blank index.html file in the wp-content/plugins/ folder.

More Complex Procedures:

First: Protecting your WP-Config file. This file contains your database name, database username and database password. Obviously, you don't want anyone to have access to something this valuable. If you don't feel comfortable making changes to your config you may want to contact your hosting company for help otherwise you can add the following code to your .htaccess file:

PHP: 1. # protect wpconfig.php 2. 3. order allow,deny 4. deny from all 5.

Second: Change your database names

Note: do not attempt this unless you are comfortable with PHPMyAdmin and making changes to MySQL. If you are not comfortable with this you should hire a professional to assist you.

Begin by backing up your database!

Many people have problems with the database table name prefix changing functionality of WP Security Scan. You can manually change your database names following the instructions below.

1. BACKUP your WordPress database to a sql file - you can do this in "phpmyadmin". 2. You should Deactivate your plugins as a precaution before proceeding. You can reactivate them after you have finished. 3. Make a copy of the .sql file you created, then you can open the .sql file and use a text editor to find and replace all "wp_" prefix to "rename_". 4. Now, drop all tables of your WordPress databases, but DO NOT drop the database. 5. import the (.sql) file that you have just edited into your wordpress databases. 6. Finish by editing your wp-config.php file and change the $table_prefix = 'wp_'; to $table_prefix = 'something_';

I hope that this article will help someone avoid the fallout associated with a spam injection hack. I love the functionality of WordPress, but unfortunately, this experience has left me so cautious that my company no longer uses a WordPress Blog along with our corporate website. Maybe someday.