The Joomla!® Community Magazine

Things to do before your site gets hacked

Written by Nicholas K. Dionysopoulos | Thursday, 01 July 2010 06:08 | Published in 2010 July
  • Print
  • Email
  •  
Level of Difficulty:Intermediate Joomla! is often bashed by unknowledgeable people as insecure. How little they know! The fact is that no system is airtight, unless you do your part to secure it. Most people coward away hearing as much as the word “security” itself. You don’t have to! Securing your site is rather easy, if you know what, where, and how it needs to be completed. This article may only scratch the surface, but will provide you with enough advice to perform a major upgrade in your site’s security in a few, easy steps.
Things to do before your site gets hacked

If you have ever been a regular of the Joomla! forums you have most certainly come across some frustrated post of a panicked user whose site has been hacked. The truth is all web applications suffer from the same phenomenon, not because they are insecure by nature, but because most people do not have the slightest clue on what they are supposed to do to protect their site. Security is not very hard, but is not very straightforward, either. It is a bit like contraception. It is necessary, but no method is bulletproof. As a result, this article is not meant to be a complete guide to Joomla! Security, but – very much like the Joomla! Security Checklist – it is just a set of guidelines you can easily follow, for that extra peace of mind.

Backup

Murphy’s Law dictates that a catastrophe will strike when you do not have the means to revert to the last known good condition. Do not get caught without a backup! Major companies have failed because they did not have a backup, or only a partial one. When talking about Joomla! sites, you need a complete backup of your files and database. The easiest way to produce a full site backup is Akeeba Backup, a popular free backup component in active development. Of course, I am a little biased – I’m its lead developer – but you can always trust the JED reviews and judge for yourself.

One important factor is how many backups you must keep and how you keep them. Keep at least a full month of daily backups, or 6 months of weekly backups. This way you can roll back to a safe known good position in time even if your site becomes compromised. Do not just keep your backups on the same server as your site! Download them to your hard drive and keep at least two copies on different removable media, e.g. CD-ROM, flash disk or external hard drive, optimally each copy being stored in a different physical location. Even better, use a cloud storage service – such as Amazon S3, DropBox, Wuala, or Ubuntu One – to securely store one copy of your backup archive. You can never be too paranoid about securing your backup files!

Upgrade, yesterday

The best time to upgrade your core Joomla! installation and extensions is yesterday, not tomorrow! Of course, you cannot move backwards in time and that is why it is of paramount importance to stay up-to-date with security releases. You must subscribe to the JSST news feed, if you have not done already, as well as keep a keen eye on the Vulnerable Extensions List. It goes without saying that you must also subscribe to the news feed of all extensions you have installed of your site. Upgrade immediately whenever a new release is out. Indolence is a deadly sin on the cruel world of the world wide web.

You may want to test the upgrades before applying them to your live site. Akeeba Backup is again your friend, as you can use your backup – you did take a backup, right? – to produce a “clone” of your site on a sub-domain, or a local server, apply the upgrades and make sure everything’s in working order.

Block user 62

You don't know what user 62 is? To cut a long story short, when you install Joomla! on your site it creates a Super Administrator account with a known user-name (admin) and a known user ID (62). This has been exploited in the past by crackers to gain access to unsuspecting sites. The best approach is to create a new Super Administrator user and block or demote the default admin user all the way down to Registered level.

Introduce multiple factor back-end authentication

All Joomla! sites have one thing in common: the back-end URL. It is always something in the like of http://example.com/administrator. You know what bothers me? This is susceptible to brute force attacks, i.e. someone trying arbitrary user names and password until they can successfully log-in as Super Administrator. The best way to mitigate this problem is to introduce more obstacles in their unholy path to cracking your site.

The genius jSecure Authentication plug-in lets you define a secret word you have to know in order to access the back-end login page. If your secret word is “foobar” you must type something like http://example.com/administrator?foobar in your browser in order to log-in to the site, otherwise you are redirected to the front-page.

The other very effective means of protection is securing the administrator directory with a password. Most, if not all, hosting control panels allow you to password protect a directory. Well, do it! Password protect your administrator directory, so that you need to enter a user name and password in order to see the back-end login page. When combined with jSecure Authentication you have a very strong back-end protection set-up.

Obscurity is sometimes a good thing

Even though I am not a proponent of security through obscurity, sometimes it’s a good way to deter script kiddies or make a semi-serious cracker’s life difficult, urging them to seek an easier target. To this end, it is a good idea to make everything not required for your site’s smooth operation inaccessible to the world. I’ve written an article about it in October, which you should read. Do note, if you choose to implement those rules, that they are purposely overprotective. You might have to add exceptions for PHP files which are called directly, for example VirtueMart’s payment gateway callback scripts, or eXtplorer’s fetchscript.php file.

ACL for the back-end

Trust me when I tell you that the default Joomla! back-end roles are not as secure as you might think. Especially the Administrator role, which is inherently very permissive, does not provide adequate isolation from potential breach from the inside. I can’t further comment on that without opening a can of worms, but I have positively managed to escalate Administrator’s permissions to the Super Administrator role. I suggest you to use a third party ACL solution to limit back-end users’ access to specific core and third part components only, depending on the user’s role in the site's management work flow. Thanks to the efforts of the core developers, Joomla! 1.6 will make it possible to define such ACLs using no third party extensions.

File and directory permissions

We’re touching a sore spot with this one, especially considering the widespread use of substandard hosts for hosting Joomla! powered websites. If your host doesn’t make use of suPHP – which effectively takes cares of permissions – it is worth employing a strong set of permissions for your files and folders. If you have no idea what permissions, ownership, users, etc are all about, you might want to read my concise Introduction to web server administration first.

First, make sure that each and every file on your site has been uploaded through FTP, effectively making your account’s user the owner of the file. Then, make sure that all directories have 0755 permissions and all regular files 0644 permissions. Finally, turn on the FTP layer in Joomla!'s Global Configuration. This ensures that most known cracking scripts, which require PHP being able to modify arbitrary files on your server, will fail.

Log grepping

This is an oft-debated technique, but I find it useful. It is also essential post-mortem, i.e. if your site ever gets cracked, in order to back-trace the problem. Anyway, the whole idea is to download your site’s access log and analyse it using an appropriate tool, searching for everything that should not be there. Examples of “what shouldn’t be there” are:

  • Base64 encoded data
  • SQL commands
  • Script tags
  • Unprintable Unicode characters

There are abundant resources on the web about log grepping. Don’t get your head spinning a lot with that because, as I said, it’s just another tool to monitor your site’s health. Most of the times you can't do anything about the attacks on your site, but you can at least run them against a local copy of it to understand their impact – and detect potential breaches.

Modified files can be game over for your site

This is the final step. It's not meant to protect you, but act as an early warning system instead. Putting restrictions and controls is essential, but only if they don’t fail. As Einstein bluntly put it “Only two things are infinite, the universe and human stupidity, and I’m not sure about the former”. An ingenious cracker, or a stupid script kiddie, might stumble upon a way to bypass your security controls and gain unauthorized access to your site. They can even hack you yesterday and exploit their back door today.

Even in this case, you need to know when you have been cracked so that you can act upon it. A very easy (conceptually!) way is to compare the state of your site to the last known good state. I have written a utility to help you with that, operating on two backup files, and an article on how to use it and interpret its results. The software is now stable; it is called Akeeba SiteDiff and is available for free from Akeeba Backup's download section.

Debriefing

Unfortunately, we have run out of space! Security is a vast topic, one that won’t even fit inside a well-sized book. All of the above are mere hints, a few good pointers to the right direction. Each one needs a bit of reading and some trial and error to implement. Remember that Rome wasn’t built overnight. Try implementing one security checkpoint at a time and work through perfecting your security policy. It takes time but it’s worth it, especially if you’re making money out of your site, either directly (e-commerce, ads) or indirectly (driving potential clients to your business). In the following issues of the Joomla! Community Magazine I will introduce even more security ideas and practical ways of enforcing them on your own site.

As a final thought, you might be wondering if you really need all of this security. The answer is, yes, you do! Do not think that only sites with a huge audience are susceptible to getting cracked. I’ve seen sites with a mere 30 visitors per month getting hacked. Why? I guess we'll never know, for the motives of the cracker can be diverse, obscure or beyond our reasoning. Your site can be a prospective cracker's shot at an adrenaline spike. Are you sure you want to be waiting for him as a sitting duck? I didn’t think so.

Tagged under Administrators

Social sharing is caring ;)

Nicholas K. Dionysopoulos

Nicholas K. Dionysopoulos

A Mechanical Engineer turned web developer I am mostly known as the lead developer of Akeeba Backup, the leading open source backup solution for Joomla!. When not working on my flagship software I enjoy squashing Joomla!bugs, writing articles about Joomla!, helping out with this magazine and playing the guitar.

Leave a comment

Make sure you enter the (*) required information where indicated.

[b] [i] [u] [s] [url] [quote] [code] [img]   

Comments (39)

  • avatar
    • 0
    • 1
    dauf

    great tips! thanks!

  • avatar
    • 0
    • 0
    Emily

    Excellent tips. Easy to read and implement. Thanks.

  • avatar
    • 0
    • 0
    Gemma Pelagio

    Thanks for the article. It was very helpful.

  • avatar
    • 0
    • 0
    digitup.se

    Thank you so much, very helpful

  • avatar
    • 0
    • 0
    shaifful

    really useful..
    informative too

  • avatar
    • 0
    • 0
    Lucian

    Thanks you!

  • avatar
    • 0
    • 0
    lennin

    hey! nice post it´s very useful!

  • avatar
    • 0
    • 0
    leao-sentado

    Thank you! please write more about this!

  • avatar
    • 0
    • 0
    Snap

    This great stuff! Your work is really helpful, thanks in advance for future updates.

  • avatar
    • 0
    • 0
    Mots

    I have been hacked twice and I have to say this is some valuable advice

  • avatar
    • 0
    • 0
    Josepe_sv

    Great, last year a small site mine was hacked after installing components download from warez.

  • avatar
    • 0
    • 0
    Nicholas K. Dionysopoulos

    Josepe, illegal downloads is actually the most common way for hackers to install backdoors on unsuspecting victims, not to mention that these illegal downloads harm the original developer in many ways.

    As a rule of thumb, don't use this method to add functionality to your site. You can almost always find a free or low-cost GPL alternative solution from the thriving Joomla! developer community. If not, just try to raise the funds. When you weight the cost of a quality extension and the cost of your lost time and reputation whenever your site gets hacked, I think you'll agree that the latter costs way much more than the former.

  • avatar
    • 0
    • 0
    JamesG

    Good overview! More, more.

  • avatar
    • 0
    • 0
    Rudy Espinosa

    Excellent Article on Joomla Security! Some of your suggestions confirmed that I am doing things correctly. The other suggestions, I soon be implementing as a result of well written article. Thank you!

  • avatar
    • 0
    • 0
    zweigelb

    Thank you very much for those tips, very, very helpful. I am going to check all of my Joomla powered sites now.

  • avatar
    • 0
    • 0
    Roma64

    When I was looking for a CMS, I heard the same stories/songs about Joomla and its poor security. But guess what. I read articles about Joomla and Security, written by people like Nicholas, and found out that the poor singers did not have their fact to write a good song, therefore, went with Joomla. Good Job

  • avatar
    • 0
    • 0
    BentRS

    Great Magazine - Great Article - Thanks a lot!

  • avatar
    • 0
    • 0
    Richard Kruk

    Good tips. Pretty basic Joomla, but those are always the ones that are forgotten or looked over.

  • avatar
    • 0
    • 0
    Matthew

    I use an .htaccess in all my sites administrator directory


    Order Deny,Allow
    Deny from all
    Allow from 75.146.139.38
    Allow from 75.146.139.37
    Allow from 75.146.139.36
    Allow from 75.146.139.35
    Allow from 75.146.139.34
    Allow from 75.146.139.33
    Allow from .ca.comcast.com

    I have 5 static IPs at my office, and I'm a comcast customer at home and 99.99% of my clients all have comcast. So now the hacker has to at least have the same (local, California) ISP and know everything else in order to access the administrator interface

  • avatar
    • 0
    • 0
    william

    great article I new some of your security tips but not all very useful, better safe than sorry. thanks

  • avatar
    • 0
    • 0
    Ashish

    Good ways to secure our joomla site. I appreciate the add-ons you have made available for us. Very informative article. Thanks!

  • avatar
    • 0
    • 0
    Drohobych

    Very good text !!!

  • avatar
    • 0
    • 0
    Steve

    As a Joomla! user with experience of being hacked I think these are excellent tips. The first thing website owners ask when hacked is always "why me"?

  • avatar
    • 0
    • 0
    VJ

    Hey thanks for the awesome guide. But I have one question. You said, "turn on the FTP layer in Joomla!'s Global Configuration. This ensures that most known cracking scripts, which require PHP being able to modify arbitrary files on your server, will fail."

    Could anyone explain this to me? Why would turning on the FTP layer make cracking scripts fail?

    thanks.

  • avatar
    • 0
    • 0
    Nicholas K. Dionysopoulos

    @VJ It's all about ownership and permissions of your files. If you read the external resource referenced in the paragraph previous to the one you quoted it should be evident. Since your files are owned by a different user than the one your web server runs under the only way to write a file is using the FTP layer. Cracking scripts have to be uploaded to your site in order to work. Since you make it extremely difficult for hackers to do so, you are effectively adding yet another layer of security on your site.

    That said, the FTP layer is not a panacea. A resourceful hacker could potentially discover another vulnerability he might use to compromise your site. That's why it's important to have multiple layers of security. It's just like with armour plates: the more you carry on you, the more protected you are against enemy fire.

  • avatar
    • 0
    • 0
    Darcy Peal

    Thank you very much!
    Every little bit helps and although I know there is no such thing as a "bullet proof" website I want mine to be as close as possible before I even go live with it.

    I had a site hacked in the past and it was being used to distribute Japanese porn.

    NEVER AGAIN!

  • avatar
    • 0
    • 0
    Nick Yeoman

    I like to put my site into subversion. That way if there is a breech you can easily restore (the files) to their original state.

    The only problem is the database.

  • avatar
    • 0
    • 0
    Nicholas K. Dionysopoulos

    Nick, you can always use an automated database backup tool (such as LazyBackup or Akeeba Backup with its Lazy Scheduling plugin) to grab a SQL dump of your database in a well-protected folder inside your site's root, so that it can be synchronised by SVN. Alternatively, you can write a shell script to run mysqldump and schedule it through CRON to achieve the same result. The biggest drawback with SVN is that you need to dig into shell scripts and CRON jobs to automate the backup procedure, whereas the restoration procedure requires SSH access and the knowledge of unintuitive revision numbers in order to restore the correct version of your site.

    However, I consider this approach very treacherous, as a hacker might eventually be able to figure out the path and exploit a directory traversal issue in a vulnerable extension to get hold of your database dump. My strategy is to use CRON jobs to let Akeeba Backup take daily full site backups which are automatically stored in Amazon S3. If something goes awry, I can restore in a snap with absolute confidence that my restored site will be exactly in the state it was when it was backed up.

  • avatar
    • 0
    • 0
    blans
    Quote:
    My strategy is to use CRON jobs to let Akeeba Backup take daily full site backups which are automatically stored in Amazon S3.

    Nicholas, First thanks for all your good work and your efforts to explain security in common (non-expert) language.

    Can I find an article about the above strategy?

    My way of making a backup is to upload the jpa and use kickstart. But having your automated procedure is much better.

  • avatar
    • 0
    • 0
    samson

    Thanks for the information, pls. i need links that can help protect my joomla sites, i have done so many things still yet it get hacked.

  • avatar
    • 0
    • 0
    natali

    muito bom o seu port!!! Good!!

  • avatar
    • 0
    • 0
    Wanda Klotz

    A customer was recently hacked and the site was getting slower and slower - getting bounced out of logging in to make appointments, found this file and another super-admin ... the provider would not give me the ability to control permissions and everything was writeable. This is the code to the 'ad' that was in the admin folder:






    JoomlaCode > Projects > Joomla! > Files > Browse Frs Release









    ddaccordion.init({
    headerclass: "expandable", //Shared CSS class name of headers group
    contentclass: "submenu", //Shared CSS class name of contents group
    collapseprev: true, //Collapse previous content (so only one open at any time)? true/false
    defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
    animatedefault: false, //Should contents open by default be animated into view?
    persiststate: false, //persist state of opened contents within browser session?
    toggleclass: ["", "openheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
    togglehtml: ["suffix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively ["position", "html1", "html2"] (see docs)
    animatespeed: "normal" //speed of animation: "fast", "normal", or "slow"
    })

    oldload = window.onload;
    function expandableExpandItem(){};
    function docmanExpandTree(){};
    window.onload=function(){oldload();convertTrees();window.setTimeout(' expandableExpandItem()',100);docmanExpandTree();}

    GS_googleAddAdSenseService("ca-pub-1189370408998555";);
    GS_googleEnableAllServices();


    GA_googleAddSlot("ca-pub-1189370408998555", "Joomla_Joomlacode";);
    GA_googleAddSlot("ca-pub-1189370408998555", "Joomla_JoomlacodeSide";);
    GA_googleAddSlot("ca-pub-1189370408998555", "Joomla_JoomlacodeFooter";);


    GA_googleFetchAds();



    Home
    About Joomla
    Community
    Forum
    Extensions
    Documentation
    Developer
    Shop








    function getPos(obj, direction) { /* direction == 0 ---> Top direction != 0 ---> Left */
    var cur = 0;
    if (obj.offsetParent) {
    do {
    if (direction == 0)
    cur += obj.offsetTop;
    else
    cur += obj.offsetLeft;
    } while (obj = obj.offsetParent);
    }
    return cur;
    }
    function expandFloatingMenu(id, icon) {
    var menu = document.getElementById(id);
    var icon = document.getElementById(icon);
    var t = getPos(icon, 0);
    var l = getPos(icon, 1);
    menu.style.top = ((t + parseInt(icon.height)) + "px";);
    menu.style.left = (l + "px";);
    if (menu.style.visibility == "visible";)
    menu.style.visibility = "hidden";
    else
    menu.style.visibility = "visible";
    }

    function SearchByIDMenu()
    {
    var menu = document.getElementById("SearchByIDMenu";);
    var icon = document.getElementById("SearchByIDIcon";);
    var othermenu = document.getElementById("quickJumpMenu";);
    if (othermenu)
    othermenu.style.visibility = "hidden";
    var t = getPos(icon, 0);
    var l = getPos(icon, 1);
    menu.style.top = ((t + parseInt(icon.height)) + "px";);
    menu.style.left = (l + "px";);
    if (menu.style.visibility == "visible";)
    menu.style.visibility = "hidden";
    else
    menu.style.visibility = "visible";
    }






    Forum MessageTracker ItemFRS Release


    Item Id: 






    MyGforge Home

    Main
    My Stuff
    Users
    Search
    Projects
    Snippets
    Log in | Register new account








    Joomla!
    Summary
    Reporting
    Search
    Tracker
    News
    Files
    Lists
    SVN
     












    GA_googleFillSlot("Joomla_JoomlacodeSide";);




    Main » Projects » Joomla! » Files » Joomla1.5.23 » Browse Frs Release



    Release ID:
    14506


    Release Name:
    Joomla1.5.23


    Release Date:
    2011-04-04 02:00:00


    Released By:
    Mark Dexter

    See joomla.org release announcement.


    See CHANGELOG.




    Files
    FileSize
    Downloads
    Md5 Hash
    Joomla_1.5.23-Stable- Full_Package.zip6956762105467ed2214548d8a26eb66eadf65be419b1c

    Joomla_1.5.23-Stable- Full_Package.tar.gz49346027332d64d25e8236f7cc30ad1107164c2a61f

    Joomla_1.5.23-Stable- Full_Package.tar.bz243025563455f1ad25562122a3433908398320d502d
     




    Tracker Name
    Field Name
    Tracker Item Id
    Summary
    Open Date

    No Tracker Items Found
     




    Associated Item
    Comment

    No Associated Items Found
     





    GA_googleFillSlot("Joomla_JoomlacodeFooter";);



    ©2005-2008 Open Source Matters, Inc. All rights reserved. Joomla Hosting by Rochen Ltd.   
    Accessibility Statement   
    Privacy Policy   
    Gforge




    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.";);
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E";));


    var pageTracker = _gat._getTracker("UA-544070-8";);
    pageTracker._trackPageview();


  • avatar
    • 0
    • 0
    Chuck

    Just found this page - wow, thanks for all the details! I found a handful of viruses in my compressed backup, which is causing the server to overload. Joomla is up-to-date (1.5.23) and my hosting company helped out and removed malware where they could. I'm a novice, so I'm looking for any help I can get.

    How can I remove the trojans from my compressed backup? Norton ran a scan and couldn't repair the items. I'm a Mac, btw. Thanks for the great post and any help.

  • avatar
    • 0
    • 0
    AutoGlassIdol

    Thanks a lot for this tips, my 7 site got hacked and i was so frustrated!! This is truly very very helpful tips. Thanks you so much

  • avatar
    • 0
    • 0
    Bhathiya

    Thanks really helpful stuff to be learned. http://example.com/administrator?foobar is really impressive way to secure the back-end login page.

  • avatar
    • 0
    • 0
    miami web pro

    they hacked my site not too long ago :(

  • avatar
    • 0
    • 0
    Paneru

    This week, my all three joomla site hacked. This is a great lesson for me.

  • avatar
    • 0
    • 0
    Concerned Site owner

    My site too was recently hacked and defaced, let's not even begin to try to understand why someone would do it but for some sad self gratification, anyway I found they replaced the index.php and made it look like a turkish group had performed the attack however the site was damaged considerably more than that, I have discovered files and scripts in many of Joomla's base folders, not only that, I have recently discovered some erratic component behaviour too.

    A security component call GuardXT seems to have issues with locking the configuration.php file, however I'm not sure if it's the component at fault or something else is controlling it's actions. I have changed the CHMOD permissions of the configuration.php file and confirmed it by FTP, yet while the file is set to 644 Joomla administration can still set the configurations, this action should be impossible. NOT!

    One of my sites is well overdue an update from v1.5.23 to the latest, however my concerns are how do I migrate my existing database content to the new installation. I'm aware I am going to have to re-think the whole site because many of the existing plugins and modules will cease to function in Joomla's latest version. I will stand to lose thousands of pages of content if I cannot successfully migrate my old content. Any advice on all the above waffle would be much appreciated. I monitor your replies with anticipation...

Powered by Compojoom comment
English

Contributing Authors

Join our community!

Recommend us on Google+