Skip to content

My WordPress header.php Got Hacked –

by arlo on May 12th, 2012 

Today I went to see some analytics and noticed that traffic was unusually down. I went to a popular wiki page that usually drives a lot of traffic to check if my link was there. It sure was, but when I clicked on it chrome gave me a malware warning!

XSS Hack (cross site scripting)

If you do a search for the offending website you will not find anything. So I looked at the live DOM via chrome tools (or you can use firebug) to search for the site, and sure enough I found it.

At this point I knew there was some Javascript being loaded that was dynamically creating this iframe. I searched the DOM in fear that it might be a 3rd party wordpress plugin gone rogue, but found nothing. Then I took a look at my header.php for my theme, BINGO! I see this confuscated block of characters that screams machine generated. Turns out it’s some sort of hash that is being decoded and creates a script tag which in turn injects an iframe into the DOM. So I quickly removed it and saw the warning go away. Hopefully this post helps others locate a similar problem with their site. Here is the code that I had to remove from my header.php:


Investigating the Hack

I am still in the middle of figuring out where the vulnerability is on my site. I recently (2 days ago) updated my WordPress install to 3.3.2 (newest) and this is the first time I have been hacked. Not sure if WordPress is to blame or not, either way I would like to find out how this happened.

Update: 1

I found this blog post that seems to explain what happened to my WordPress install. I also changed my password on my server and ftp accounts. Then I did a search to see how far this little hack has gone.

grep -R 'echo(gzinflate(base64_decode(' *

This revealed that ALL my WordPress themes were hacked.

So far it doesn’t look like a WordPress flaw, but more like my SSH/FTP account had been compromised. Then the intruder, noticed I had a WordPress site and decided to inject all my themes. :P

From → Javascript, WordPress

  • Thomas

    You haven’t solved the problem.

    Some vulnerability allowed someone (probably using an automated tool) to compromise your server or WordPress installation, and that’s what allowed them to modify your header.php. You’ve removed the damage caused, but the vulnerability is still there. That means that sometime soon, the same thing will happen again.

  • Arlo Carreon

    Right you are! I just found the hack about 30 minutes ago and removed it (then wrote a blog post ;p ).  As soon as I find out where the vulnerability is, I will add on to this post.

  • PaintBall

    Id make sure you have the latest version of wp installed

  • Arlo Carreon

    I absolutely do (3.2.2). It just so happens I updated about 2 days ago. I updated the post stating that I am not sure whether it is WordPress or not, but I would love to find out.

  • Thomas

    Just keep in mind that even if you find and fix the vulnerability, you’ll still need to do a full, clean reinstall. 

    Most malicious hackers will try to drop a stealth web shell somewhere on servers that they compromise, which will give them access whenever they want. Those can be hidden in .htaccess files, random php files on your server – pretty much anywhere.

  • Arlo Carreon

    wow, didn’t know that. I’ll see what I can do.

  • apmeyer

    Make to change all your passwords. Very possible someone simply accesses your install via FTP or logged into wordpreas directly and edited the header there. If you’re not usin something like 1password, I’d start. Best of luck. Let us know what else you uncover.

  • Arlo Carreon

    Thanks! I just changed my password to a more secure one. Reddit users seems to all agree that infected computers look for filezilla files, which store passwords in plain text.  

  • Pingback: Wordpress header.php Got Hacked – | Arlo Carreon |

  • Ben Sarmiento
  • Kenfeldman

    Check for the Timthumb Vulnerability — this has all the markings of that.

  • Tollens Griffbek

    Do you even know what you are doing?   You say “see this confuscated block of characters that screams machine generated” – aren’t you aware of base64 encoding?

    The problem is that your site probably has terrible security and you don’t fully understand enough to get on top of the problem.

  • Paul

    I had something similar to this happen. It turned out to be an old plugin (IIRC it was a photo editing plugin) for the WordPress 2x series that needed updating. Anyway, the plugin effectively compromised the whole installation. I re-installed with the latest WordPress and re-configured each plugin individually.

  • Matthew Forzan

    Can confirm this is NOT limited to WordPress installs. Just finished cleaning up a custom built website where the index.php file was infected (in the header section). File was modified on the 10th and still not sure how they got in.

    As always, make sure you have the usual backups and do the password changes frequently. Look at ways to increase your security – there are many options out there including making your files only writeable from your home/work IP address.

    Unfortunately these hacks will be around for some time and as the hackers get smarter, we need to as well.

  • Nick Alpin

    Great job in catching the rogue code and thanks for sharing. It may be useful to notify your host, they may have tools that could quickly run through file permissions, access history, etc. If they’re helpful, they may be able to spot files accessed by/modified from locations other than yours. Same for finding any hidden scripts, etc. 

  • Rick H

    Here’s the attack vector:

    If you use FileZilla as your FTP client, the FTP credentials for your connections are stored in a plain text file (look in your %APPDATA%/Roaming/Filezilla folder). There are malware that will get that connection credentials and use it to modify your file (in your case, the header.php in your WordPress theme directory). That’s how they put that code inside the file.

    And FileZilla does not see that plain text file as a security risk. (WTF ???)

    My response: immediately delete FileZilla, manually remove the folder in %APPDATA% (because the uninstall doesn’t), change your site’s FTP credentials (user name and password), then use WinSCP ( )as your FTP client. WinSCP lets you assign a master password so that site connection credentials are encrypted.

    And do a full antivirus scan.

  • Bodhi McGee

    My site would auto update and then i’d find that something wasn’t working with a plugin or a part of the theme occasionally. It felt out of control and it was frustrating because i dont know how to roll back the site when something would go haywire. Anyways, long story short, I started using a wordpress maintenance company and since then i’ve had no worries with any of this. Theres a lot of them to choose from but after speaking with several i went with one called Total WP Support so i have to give them a little plug and say thanks guys. If anyone is in the same boat and needs wordpress support they are at