Seems like more and more, I see people having a terrible time with their WordPress installs being hacked. While I’m no expert on the internets, or security, or anything like that….I did suffer through 2 rounds of attacks here on The Voodoo Empire, and recovered fully….and learned a lot. So here is the process I went through. The first time I wasn’t thorough enough, and that is how it happened again. I’ve been clean for months now, after doing things properly the second time. Before I describe my process, here are some great reads that pretty much set me straight and got me going on the cleanup process.
These got me going through the cleanup process, and one other good link, after you get everything cleaned up:
So that’s the required reading out of the way….now onto my process.
I first noticed some gibberesh (the base64 stuff) showing up in my theme’s files when I went in to do some editing. It had been months since I had worked on my theme, so who knows how long the spam had been in there. I deleted all the rogue code from all my theme’s files and thought I was golden. Until it showed up again, I layed the find and delete game for some time…..but it kept coming back. Then I started to dig around some more…..The Voodoo Empire has 5 WordPress installs, and at the time we had Drupal, Joomla, ZenCart, MediaWiki, and many other software packages. This totals up to a few thousand php files on the server. Each and every php file had the base64 stuff in it. So next up, every php file was either cleaned, or replaced. I thought I’d had it beat. A month later it was back. I’d developed the habit of viewing my source code from within my browser each time I visited my websites now to look for bad stuff. But this time, even though there was spam in my source code, there wasn’t any files altered. So I dug and dug, and finally found a php file that didn’t belong buried about 4 level deep. It was inserting spam links. I deleted it and thought I was good. But alas, it was too good to be true…..soon, all my php files on my server got altered again. This time though, I did some research and finally cleaned up properly.
First thing I did was change all my passwords. FTP, WP (and all other programs), all DB passwords, etc. After I changed all my passwords, I took a look at one of the files that had been altered, and checked out it’s timestamp. My host (GoDaddy) offers server access logs to peruse at my leisure (if you’ve never seen an access log, they are scary). I had no idea what was in a log, I’d never seen one, but I decided to dive in. I checked my access logs agains the times that the altered files had last been changed and found that a rogue php file buried way deep in the 2008 uploads folder of a different WP install was affecting my main WP install. Upon further investigation, I found another rogue php file that was altering my other files. So I deleted the rogue php files. I then reinstalled every single software package on my server. Then I went in and manually cleaned the rest of the php files that didn’t get replaced (WP theme files, wp-config file, etc). After that it was on to plugins. I deleted all plugins and installed from clean downloads. So now every php file on my server was accounted for, and clean. No rogue php files existed anywhere. No rogue code was added on to any of my existing php files.
It was time to finish thing up….on to the database. I manually scanned through exports of my database looking for any suspicious code that I found, and ran some basic sql queries on my existing database looking for suspicious code, and got my database all squeeky clean. And now, with everything nice and clean, I changed up all my passwords once again.
There you have it! My long and painful travel to a clean WP. Keep everything up to date, WP installs, themes, plugins, etc. Check your source code often. Maybe install some of the various security plugins that are out there (none of them stopped my attacks, but they do have a use). And if you do get hacked…..be thorough. If you are not, you are just wasting your time! Remember, server access logs can be your friend! Hopefully you can avoid being hacked, if you are reading this because it happened to you, I hope I helped you just a little, be patient, be thorough, and good luck!
Check out my post here if you are looking for more information on rogue files, and using your access logs to find them.