Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
My server's been hacked EMERGENCY

I have an Expression Engine website I try to clean up. The database has been given many new users so it seems the database has been hacked / links added. One major issue is that the site when clicked in Google is being bypassed. All visitors are being redirected to another website. Here is the search : . First site is the one in question.. The site they are redirected to is I have been trying to find this redirect in all files and the database, but I have had no luck. It is not a .htaccess redirect, that I have checked and confirmed. But I have not been able to locate a JScript or PHP redirect in the files nor database as of yet.. Probably well hidden because of a base64 or packed encryption. Ideas?

NB no clean database version available

share|improve this question

marked as duplicate by Iain, RobM, Sven, mailq, Scott Pack Nov 20 '11 at 14:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

General advice here is to disable your site and recover it from known good backups as no matter what you do now, you cannot guarantee that there isn't another back door. You might also consider contacting the site designer, they may have a backup of the site from when they handed it over. – Iain Nov 20 '11 at 10:34
Thanks Iain. No good backups available so I want to try to clean up before I just start from scratch with a clean EE and build up the database from scratch. I also want to learn what happened here. – rhand Nov 20 '11 at 10:36
"cleaning up" is a really bad idea unless you are 100% sure of the full extent of the hack, know precisely what was changed, and are 100% sure you can role back those changes and guarantee data integrity. – RobM Nov 20 '11 at 12:19
On the other hand, trying to learn exactly what happened and how he got in is a very good idea. Otherwise the same thing will just happen again. – Ladadadada Nov 20 '11 at 12:40
up vote 1 down vote accepted

It only redirects people with a referrer from Google (possibly also other search engines.) If I take off the referrer part of curl I just get a normal page back.

curl -e "" --include
HTTP/1.1 302 Found
Date: Sun, 20 Nov 2011 11:44:17 GMT
Server: Apache
Vary: Accept-Encoding
Content-Length: 239
Content-Type: text/html; charset=iso-8859-1

<title>302 Found</title>
<p>The document has moved <a href="">here</a>.</p>

The content of the response (after the headers) suggests that this is an Apache generated redirect and not a PHP generated one. Most people don't think to send a body when using the PHP header() function for redirects and that text matches exactly what an Apache generated body would look like.

To me, this means it's not a PHP file and it's not a javascript or meta redirect stored in your database.

Based on this I would suggest looking in Apache config files. Everything in /etc/apache (or /etc/httpd deoending on your distro) needs to be checked. It doesn't have to be a RewriteRule or even a Redirect. It could be an extra Include directive that loads the redirect from another file somewhere else. It could even be a directive that changes what .htaccess files are called.

A command that might help you find it is grep -r "sweepstakesandcontestsinfo" /etc/apache.

You didn't mention how you checked that it's not a .htaccess redirect. .htaccess is the most likely option because it usually doesn't require any special privileges to write one of those inside the document root.

If you haven't already done so, run this: find /var/www -name .htaccess but change "/var/www" to your document root.

If that doesn't find anything, try the same command but with / as the first argument. Obviously, you will have to check over each and every line in every .htaccess file you find.

If you find that some of your Apache config files are changed, then this attacker has root access on your box. The best response at that time is to take it offline and begin a proper cleanup. There are many questions on both here and security.SE about how to recover from a compromise once you have cleared up the immediate problem (which is the redirect).

share|improve this answer
Found one .htaccess so far that had a rewrite rule. It was on the same server but for another site than the site I was trying to fix. It states: <IfModule mod_rewrite.c> RewriteEngine On RewriteOptions inherit RewriteCond %{HTTP_REFERER} .*(msn|live|altavista|excite|ask|aol|google|mail|bing|yahoo).*$ [NC] RewriteRule .* [R,L] Oddly enough I have not found one for this site in question yet. Did rename that .htaccess now, but am still trying to fix the redirect on the site in question – rhand Nov 21 '11 at 4:30
Emptied EE's cache, but still have the same redirect using Google or Yahoo. So the Apache redirect must still be somewhere. Grepped a lot of .htaccess files, even some in the logs folder, but found none in the site's folder that have a redirect. Also checked MSN and there I get the same redirect. NB As this is a Dreamhost virtual server and not a dedicated server or a VPS I do not have root access. Would also assume DH did not get hacked, but will ask them later today just in case – rhand Nov 21 '11 at 5:06
I have been going through the site to find the redirect leading to for quite some time. Grepping through files and using find I have been checking all files and .htaccess files on the server. I founds one .htaccess added at with a redirect going to that same site, but I have not been able to find a PHP, meta or .htaccess redirect doing the redirecting in the domain in question. Even after looking extensively for suspicious and or compressed or obfuscated code the best way that I could. I am stunned. – rhand Nov 21 '11 at 8:51
Added Google Webmster verification file to the site and GWT cannot locate it on the server somehow while it is there. Caused by the redirect issue I guess. – rhand Nov 23 '11 at 4:56
Found another shell script in another site on the same home holder, but the redirect is still elusive. Also searched for PHP auto_append_file to see if a redirect was attached like that. No joy. We will wipe the site this week and start anew. – rhand Nov 29 '11 at 23:21

Trying the link a couple of times shows that the Google result goes to the "wrong" site, but going direct to the URL ( doesn't result in a redirection.

Perhaps you have a google search poisoning rather than a site problem?

share|improve this answer
How would people poison Google ranking? By having the redirect for a long time perhaps? That would explain why Google is still redirected. But the same is still happening for MSN and Yahoo as well.. – rhand Nov 23 '11 at 2:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.