My site was hacked this morning – something I discovered by visiting my site, only to be greeted by Google’s genuinely frightening “WARNING: VISITING THIS SITE MAY HARM YOUR COMPUTER” screen.

The culprits altered every file ending in “.html”, as well as every file beginning with “index.”, to add a hidden IFRAME element to the page. That, in turn, would quietly load a web page from a third-party site that attempts to install malware onto visiting computers.

Nasty. And not uncommon for WordPress users.

Fortunately, I was able to track down and wipe out the infection in short order. Here’s how:

  • I looked at the timestamp on the hacked files. Each had been changed at 5:13 am today.
  • A quick trip to my server logs revealed that at 5:13 am, a file called “cache.php” was accessed using POST.
  • A peek at the file, a little Googling, and a look at a default WordPress installation, confirmed for me that cache.php a) didn’t belong, and b) was a very likely culprit. Backed up, and then deleted it.
  • This left me with the challenge of restoring all of the files that had been hacked (there were more than you might think). I didn’t relish the thought of doing it one by one. Fortunately, Dreamhost has a “Restore” command for domains that can let you roll a site back to a snapshot from a few days or weeks ago.
  • Unfortunately, it didn’t work. Fortunately, Dreamhost lets me use SSH to access the server.
  • I found a code snippet from this helpful guy on WordPress.org’s support forum that let me run a search-and-replace operation from the command line. I just replaced his search string with mine (the URL his iframe pointed to was different from the one my hackers used), being careful to put a backslash before every forward slash in the URL.
  • Then I went to Google’s Webmaster Tools home page, and requested a review of my site, letting them know I’d removed the nasty bits. That should soon mean you can visit this site without having to click past dire warnings of impending doom.

I’ll be checking even more regularly for rogue PHP files like cache.php – especially now that I know what to look for. And I’ve saved that search string for future use; with any luck, it will only be useful for helping others who’ve run into this.

Mastodon