Hacking and security

Hacking and security

by Robin Greaves -
Number of replies: 34
Hi

This is a very commonplace issue but obviously it generates a lot of pain. It is also a frequent topic (twice weekly?). The references given (eg to http://docs.moodle.org/en/Security) are not that reassuring or helpful to novice users (everyday folk who want to use the web to deliver learning rather than folk with a deeper interest in IT than merely the everyday "driving" of it).

I am concerned (who isn't?!) about my site being hacked, but I find it very hard to interpret/implement the guidance given here. For instance, in the documentation a seemingly simple recommendation (one of the few) is:

  • Disable register globals
This will help prevent against possible XSS problems in third-party scripts.
So I went straight to Admin on my site to do that. However I couldn't find anything that clearly corelated to the advice! I realised I didn't even really know, within the "language" of Moodle, what "disable global registers" means. Where could I find this registration/register? So I gave up and just hope for the best. I continue to monitor the posts here to see what scraps I can to pick up and use.

I feel most non-tekkies would prefer a zero risk installation configuration if that were possible. If altering such a configuration setting such that there would then be a risk I think they would like advice regarding the trade-off being made between function and the probability/severity of the risk. Some sort of risk-register (that word again!) would be great.

Following a post today here I've simply stopped uploads being performed! For me this is not an important element at present. For those out there for whom it is, it would appear than anyone ( who can register) can simply upload files that can rip your system apart see: http://moodle.org/mod/forum/discuss.php?d=63122&parent=284759

But surely I don't need to disable guest access too (a recommendation(?)) in Security? I want a one click access ability to demo the site to potential users. (Not being in a school environment where users can be "obliged" to use the web interface, I am faced with the massive reluctance of people generally to use web services. Requiring the slightest effort of them loses most people. I am working with a software-as-service web company and even they don't engage with web delivered services unless spoon-fed.)

The advice in the documentation here seems to veer between the "obvious" (update your installation, don't install questionable third-party apps etc) to the opaque and/or technical (see above or "Set the mysql root user password" etc).

So, in brief, I find the info provided here both worrying (hacking of Moodle sites is commonplace) and unclear (advice given in documentation is elementary or opaque).

I realise this whole enormous enterprise is sustained/created (?) by volunteers, but wouldn't it be possible to develop the Security page here so that the key advice can be presented in a heirarchy of risk and that can be drilled into for precise instructions? It would save a lot of worry and heartache . . . (and maybe even defeat the magaturks!)

p.s. wouldn't it be possible to incorparate one of those "read this" or "complete the equation" etc devices to stop automated registrations?

Average of ratings: -
In reply to Robin Greaves

Re: Hacking and security

by Mauno Korpelainen -

Hi Robin,

there is only one zero risk installation configuration - local PC, not connected to net and don't let anybody else than you to use it.wink

But seriously reading http://docs.moodle.org/en/Security is a good start, I have no exact statistics (you might find some from net) but about 6 months ago I read some documents about attacks agains different cms programs end lms programs, moodle seems to be very rarely the target of attacks of different hacker groups. The reason is that developers of moodle have made many wise decisions concerning (guest and student) roles, admin settings and the way how moodle is developed. Further reading:

http://www.nmrc.org/pub/faq/hackfaq/
http://help.joomla.org/component/option,com_easyfaq/task,view/id,167/Itemid,268/

In reply to Mauno Korpelainen

Re: Hacking and security

by Robin Greaves -
:D LoL Great advice EXCEPT . . . that you don't know me. I'm probably the worst risk of all! ;)

I have read the Security page (that's where the quote came from), but as I said, I tried to implement the advice and couldn't. I didn't understand it, and comparing the Security advice with my installation, side by side, I couldn't see how the two fitted together!

Glad to know hackers haven't caught on to the possibility of simply uploading viruses etc to Moodle sites as you noted. But shouldn't we try to nail shut that door rather than just live in hope?

Without disputing the "wise decisions" of Moodle folk which you refer to, as an admin/user/novice I don't know how to implement them in such a way that my site remains secure. The possibility may be there but I have no idea if I'm availing myself of it or whether I'm creating gaping security holes. I've prevented uploads as a precaution but I want Guest access. Does that mean my site is wide open to attack?
In reply to Mauno Korpelainen

Re: Hacking and security

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Mauno - I'm not too sure about how safe my computer is when only I am using it. Compared to some of the things I have done, I think I may prefer to have others connected and using my computer! Peace - Anthony
In reply to Anthony Borrow

Re: Hacking and security

by Mauno Korpelainen -

Anthony,

i have seen it myself - when I got my first OWN server it took only one day to get it higgledy-piggledy...out of order and I had to reinstall everything.

Robin,

Guest access is not a big risk because guests have a very limited role. Letting visitors (students) to upload attachments to moodledata folder with permissions 777 is a minor risk if anybody can be your student (use enrolment keys for courses and don't tell them to anybody)...but if you prevent uploading files you loose something valuable from your moodle. Check Security section from your moodle Administration menu: Site policies, HTTP security, Module security and Anti-Virus and make changes if you feel that it's necessary.

Trojan viruses are sly but you or some of your students may as well get them from any web page - install clam AV or some trusted commercial virus software to your server.

My opinion is that for example critical hard disc failure is more probable risk of losing data in moodle with default settings than nasty hackers attacking your moodle. Take the backup files anyway regularly.

In reply to Mauno Korpelainen

Re: Hacking and security

by Robin Greaves -
I'm confused between what you say here: "777 is a minor risk if anybody can be your student" and what you spoke about in the other thread regarding the megaturk attackers simply uploading php files and then hacking the site through them. Could you explain?

My server is professionally hosted, and I'm as certain as I can be that their security is up to the mark. They have a shared SSL certificate that I could use (to enable the HTTPS) or I could purchase a specific one. They say that if I do lock myself out for some reason, they can get me back in, so I shouldn't worry.

I'm really just concerned that what I do as the administrator (with a very small "a") of the site shouldn't compromise site security AND that I do what I can to improve it. I'll check what AV my host uses. If it's CLAM then I'll enable that. Thanks for the advice.
In reply to Robin Greaves

Re: Hacking and security

by Mauno Korpelainen -

I told later in that thread that Megaturks were using (probably) some version of c99 (c99shell.php or c99shell.txt and so on) to get sites hacked but the route was Joomla or Mambo and some of 3rd party components (extensions) of Joomla or Mambo. I in fact opened one file that I found, got trojan virus infection, cleaned it and read the code that file had but have already deleted the file. You may still find both those trojan viruses (c99 family) and files like c99shell.txt with google (and hacked sites - try for example megaturks and joomla or megaturks and moodle) but opening any file like that must be done in an environment that has nothing valuable and can be destroyed immediately. Some of those files may really damage your server and give control of your server to a hacker who knows what and where to search.

The script was designed for the file structure of Joomla - not for moodle. Of course some hacker could try a similar trick (I don't want to give any tips for any hackers...) with moodle but I haven't seen any such attacks done through moodle (PHP Backdoor or c99) and to be honest I don't even know if it would work with moodle. It is very unlikely that anyone of your students knows how to hack sites - and those few megaturks (or other groups)  are using similar methods and similar files. That's why I said the risk to be minor - most virus scanners find and delete c99 trojans but not all servers have real-time virus detection. That risk might be about 1 / 1000000

In reply to Mauno Korpelainen

Re: Hacking and security

by Mauno Korpelainen -

I just checked that c99 hacking can't work in moodle - and not even in new versions of Joomla anymore if default settings are used. It is possible only if register globals is on and register globals should be set off in moodle (or actually php.ini or .htaccess file).

So the risk of c99 attacks through moodle is zero.

In reply to Mauno Korpelainen

Re: Hacking and security

by Robin Greaves -
Thanks Mauno. That is really informative AND reassuring. smile But how do I check that the "register globals" is set off??? mixed
In reply to Robin Greaves

Re: Hacking and security

by Mauno Korpelainen -
Administration -> Server -> PHP info
In reply to Mauno Korpelainen

Re: Hacking and security

by Robin Greaves -
Ooops, I spoke too soon. I thought it would be easy! My register_globals is set to "on" for both Local and master values (whatever that may mean). So, next question, how to turn it/them to "off" - there's no facility on the page you cite - and what other things will/may change when I change them to "Off" (assuming that's what I should do)??
In reply to Robin Greaves

Re: Hacking and security

by Mauno Korpelainen -

You should contact your host and ask if they have considered changing the master value in php.ini and if not is it possible to use local .htaccess files or php.ini files to change that and other php.ini settings (or read support/help/faq files of your host)

When you place a .htaccess file in a directory, it will affect that directory and all directories below that one. The best place is usually root folder but you may also have several .htaccess files for different needs.

To create a .htaccess file:
Create an empty text file (named htaccess.txt) in Notepad
Add the contents of your .htaccess file
Upload the file to your package in the appropriate directory for what you want to do
Rename the file .htaccess
Note - You can also save the file directly in NotePad as ".htaccess" by putting quotes around the name during the save.  But if you do that be sure your FTP program will still upload it in ASCII format.

In .htaccess file you need to have this row

php_flag register_globals        0

In local php.ini file you should have line

register_globals = Off

Average of ratings: Useful (1)
In reply to Mauno Korpelainen

Re: Hacking and security

by Timothy Takemoto -

Thank you for this advice on how to make a moodle installation more secure.

By the way might it be a good idea to also include

php_flag allow_url_fopen   0

in the htaccess file?

Perhaps there are other things that one could include in a standard-improve-security .htaccess file? It might even be included in the installation by default. I seem to remember that there was a generic recommended, ready-to-use htaccess file included with Moodle once. Is it still there somewhere?

In reply to Mauno Korpelainen

Re: Hacking and security and news from joomla

by Andy Tagliani -
About Joomla, joomla.org seems hacked today, see thread on joomla

I dont know the server or the joomla software
Andy
In reply to Andy Tagliani

Re: Hacking and security and news from joomla

by Mauno Korpelainen -

It just shows that hackers search and find new vulnerabilities all the time. I visited yesterday some sites of those turkish hackers to get some info about the current situation of their attacks and joomla is still one of their main targets. Also joomla component com_moodle was in their lists and has been used for hacking sites that have register globals on.

A couple of moodle sites had been hacked most likely because moodledata folder (or uploaddata folder) was inside webroot (probably with permissions 777 and no .htaccess files to cotrol access) and often inside moodle folder with name http://nameoftheserver/moodle/moodledata

In reply to Mauno Korpelainen

Re: Hacking and security and news from joomla

by Andy Tagliani -
Yes, if i search in google many websites with moodledata shows me up and they have folder rights 777. I can download the backupfiles and install them on my own server. Some weeks ago i give a school in belgium the information, that this is (not only) a security risk, one course called classroom test solution. Until today i have no answer and they did not change anything.

I dont know why they did do this, 770 are enough in the first moment. I mean the folder inside they can not do anything in the most cases, because moodle create this folder with those known folder names.

A good idea is, moodle publish some information in a special textfile in the core file packages.

Andy

In reply to Andy Tagliani

Re: Hacking and security and news from joomla

by Julian Ridden -
ideally moodledata should not be in a web visible directory.

i always keep my moodledata out of the public_html to ensure such a risk does not exist. I am sure I have also seen that written in the documentation somewhere.

The idea behind file.php is to allow for secure access to a directory that is not visible otherwise.

On a side note, I prefer to not refer to this directory by this name just as an extra layer of security. the moodledata directory can actually be called anything you like. Keeping away from a standard naming convention makes it that little bit harder to guess.
In reply to Julian Ridden

Re: Hacking and security and news from joomla

by Mauno Korpelainen -
Yes, all those things are clearly said in installation and security documentation but sometimes people just don't/can't create moodledata folder out of the webroot and don't even know that they can use any name for both moodledata and moodle folder. Another "funny" thing is that guessing usernames and passwords may be really easy - username "test" with password "test" is quite well-known among test sites or users called "admin", "moodle", sitename or name of the main admin...wink
In reply to Julian Ridden

Re: Hacking and security and news from joomla

by Andy Tagliani -
Julian

It was not a criticism into your direction.

The problem is (this is my meaning), that a lot of moodlers are happy when they have successfull installed moodle. So my thought was, is it no possible to deliver a simply textfile with some information and expamples, which rights for which folders, an example for a moodledata folder outside the root, and whatever more?

The moodle doc is a pretty good and helpfull place, but there you did not find information in every language!

Andy


In reply to Andy Tagliani

Re: Hacking and security and news from joomla

by Mauno Korpelainen -

Yes, documentation can and should always be improved.

That Joomla main site hacking was made with remote file inclusion and the most amazing thing is they had left one of their main sites, The Joomla! Shop site with register globals emulation on. It was enough for hackers to get access to the Joomla main site, the developer site, the help site and last but not least the shop... http://forum.joomla.org/index.php/topic,203290.0.html

Just to remind how one wrong setting in one weak point may cause a lot of trouble.

In reply to Andy Tagliani

Re: Hacking and security and news from joomla

by Julian Ridden -
Considering that many installers of Moodle are not technically literate, maybe there are ways we can make this process more secure by adding an extra step to the install process.

After core file installation has been complete, how about an alert screen displaying security risks and highlighting (as we do with environment checks before the instal process starts) weaknesses.

i.e. alerting on unsafe file permissions, a follow up alert on register_globals, etc.

It is far from perfect I know, but I think would have a far greater impact and effectiveness than a readme file.

JR
In reply to Julian Ridden

Re: Hacking and security and news from joomla

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Julian - I agree that this would be a nice check - we get similar warnings for roles. It would be good to be able to check this - especially in a hosted situation where the Moodle admin may not have full control over the system. At least having a page to check to make them aware of potential security holes would be very helpful. Why don't you add this to the tracker as a feature request. It would be a nice addition for Moodle 2.0! Peace - Anthony p.s. - Sometime this week I would like to get the Moodle Networking stuff setup on our servers. Let me know if one day is better than another.
In reply to Anthony Borrow

Re: Hacking and security and news from joomla

by elearning edu -

I have a moodle server and it was very stable.  Recently we noticed strange behvior on the server side.  In one case the login file was bloated to 4 GB.  We were forced to suspend the account.  In another case the client did not use the web mail but noticed 143 MB of space occupied.

We were using moodle to converge with Gong, FMS2, Mambo and Joomla.  On one occasion we had the security issue arose from Mambo.  Now we noticed that Joomla integration/joomla-moodle combo pose the security threat.

We struggle and study.  Any enlightenment or experience from other members?

Nagarajan

In reply to elearning edu

Re: Hacking and security and news from joomla

by Mariana vd Walt -
Hello Nagarajan

Can you maybe elaborate on the "joomla-moodle combo" that you mention. How do you combine them? Do you have a single login, or double login? And what solution do you use either way?

Regards
Mariana
In reply to elearning edu

Re: Hacking and security and news from joomla

by Mauno Korpelainen -

There is one thing I did not remember to mention - Joomla and mambo have both a special way of handling register globals. Setting register globals off at server level is not enough. Joomla has a file globals.php in Joomla root that emulates register globals. Check globals.php and if you find line
define('RG_EMULATION',1)
change it to
define('RG_EMULATION',0)

This has been on by default for a long time because some joomla 3rd party extensions have not been written to work with this setting set to `OFF` and will not function properly but ALL joomla components allow remote file inclusion if this setting is on and those turkish hackers use this all the time to upload files all over the world - they only need one file that usually is some version of "c99" or "r57". And that file does not even need to be in your server! ( Read for example http://en.wikipedia.org/wiki/Remote_File_Inclusion )

In mambo you may still find
$mosConfig_register_globals = '1';
from configuration.php and if you find change it to
$mosConfig_register_globals = '0';

Did you check error logs? If they have already got full access to your site it could be wise to change all administrators passwords too.

In reply to Robin Greaves

Re: Hacking and security

by Just H -
Hi Robin

Not the answer you are after but the reality is: if you want a site that is open to the public and you are going to be responsible for the admin of that site, then you need to learn about server security.

As far as I'm aware, "Moodle" getting hacked is a very unusual occurrence. The reports of Moodle being hacked tend to end up meaning that someone's Moodle install has been hacked via an insecure server or other script on the server (speaking from experience here, when on a shared host, someone hacked in via what I believe was a server vulnerability and took out most people on that server running various scripts).

The reason you can't find settings in Moodle admin for things like disabling register globals, is that that is a server setting, not a Moodle setting therefore, "Moodle" can't look after that sort of thing.

Using Fantastico to install is, IMHO, also a security vulnerability. Unless things have changed since I last looked, it installs the moodle_data in your web accessible directory due to the fact it doesn't have permissions to install it below there.

For me, bottom line is if you are serious about running any site using any software you need to bite the bullet and learn how to make it as secure as possible, whether that is having direct control over your server or by having enough knowledge to tell the techs what your requirements are, and why if they ask, - and even then there are no guarantees!

Regards
H
In reply to Just H

Re: Hacking and security

by Andy Tagliani -
Yes. i go confirm with the last topics! Only one thing, when i see sometimes what they have done, not will do, they are finished with their ... however you will told this, with their configuration, anything is not work, set the folder rights to 777, all files to 777 and on and on. I´m sure and i mean it not ironic, some did not know which folders and files need which rights.

Some days ago, i read a report on heise.de (the c´t magazine) that some hosting companies and yes some great companies too, set register_globals as the standard on! The problems in some cms linke joomla are not core files i think, the contributions and extensions are need differents configurations like shops, photo albums. When moodle has a check and shows up at the installation, this will be more that a innovative feature!!!

@Harry, you´re right, a topic to this point can have another description, otherwise, a lot of people read this topic with this description.

Andy
In reply to Just H

Re: Hacking and security

by Robin Greaves -
Thanks Harry and everyone, this is turning into a really information rich thread as far as I can see!

But one thing strikes me, and I may have got this completely wrong, but there seem to be 3 or 4 key recommendations contained in the thread that are quite hard for the technically illiterate to find. I agree that we technically illiterate SHOULD bite the bullet, but it's a question of time etc.

HTTPS sign on

I've already checked out SSL and found Moodle needs a dedicated one, which is a shame 'cos my host provides a free shared one.

Globals
Thanks Mauno for the information re server side settings to get Globals set Off. I'll get onto my host.

htaccess
Thanks Mauno for the .htaccess advice. Again, I'll contact my host and see what I can do.

So why isn't all this just standard? Or why doesn't the install advise us, as Andy suggests, that there are security loopholes caused by the server side (usually hosted?) set up that could be fixed? Surely this can all be made a lot more direct for those of us who are technically illiterate but still interested in security, as Andy seems to be suggesting?

I'd love to know what the 777 and 770 thing is all about too. I've never got the hang of Ports, how the various numbers are used by the hardware and software. Is it another question for my host? - they're a lovely lot!
In reply to Robin Greaves

Re: Hacking and security

by Just H -
Hi Robin

"I agree that we technically illiterate SHOULD bite the bullet, but it's a question of time etc."

Know the feeling smile I had no idea about this stuff either when I first stumbled into using Moodle (still don't really!). Basically, I just got even friendlier with Google than I already was.

"So why isn't all this just standard?"

Problem being, and probably why there isn't a step by step guide covering every eventuality in Moodle docs, is that sadly there is no such thing as "standard" really. Too many variables, from your host, platform (e.g. different flavours of linux, windows, IIS, MySql, PHP etc.), intranet site as opposed to intranet or even just installing locally on your PC to have a play.

"I'd love to know what the 777 and 770 thing is all about too."

That's all about permissions of a file/folder i.e. who can and can't read/write to them. I think what Andy was referring too is that in some threads when people are trouble shooting you may see advice to change permissions to 777 etc. What you need to know is that that is a non secure setting and shouldn't be left as such (changing them is to try and rule out permissions being the problem). From what I've read about permissions in general, max for directories is 755 and for files 644 if the directories/files are world accessible.

I think it comes down to how critical your site is, if not so critical, then you have time to find things out on your own, ask specific questions here and with your host etc. with the piece of mind that Moodle itself is not much of a security risk and that "hopefully" your host is up securely. If your site is critical, then I think you need to do some serious Googling or if time doesn't permit, through some money at a tech to go over your set up.

I have no doubt you'll pick things up fast enough, as you can see from this thread, very helpful community here . . . and some actually really know what they are talking about! (Still class myself in the "enough knowledge to be dangerous" category smile)

Don't give up . . . and have fun!
H
In reply to Just H

Re: Hacking and security

by Robin Greaves -
Hi Harry smile

Thanks for replying but I think you've skidded over the issue. There are some really very simple pieces of basic installation "advice" or what you will, that only really come out through the cracks. They MAY be in standard documents but the standard documentation tries to be all things to all people and as with any attempt at this ite generally fails everyone. What's needed is not an answer to every conceivable set up and variation but just basic security info writ large i.e. disable Globals. That may not be possible but at least it would start the conversation with the host, or prompt the novice-self-server to set things up better. It would be fun to learn PHP. It would be fun to learn to handle MySQL. It would be fun to learn CSS. It would be fun . . . I did a masters in Computer Science many years ago, dropped out after passing the fist year (2yr course). I don't want to be a car mechanic. I want to drive! And the standard response of "well pay us to get it sorted" doesn't cut the mustard. This IT world is not of my making and is here to stay for a while. I have to swim as best I can in it. Moodle put itself out there and said come along, so I did. You can't have all this social Web2 touchy-feely stuff without practical ways of getting non-techies involved . . . and safely. I don't care if the Moodle installation gets screwed up. But my clients might. If I had the money to get a horde of techies and a bunch of commercial software that's definitely what I'd do. But I don't.

So, why not make things simple but not leave out the critical basic information. Make the critical basic stuff the headline stuff and not the endless variations and infinite variability. Heavens, if we all tried to write all encompassing tracts then each post here would be as long as this one. (Is this a recursive statement?) smile

Nice talking to you smile And I love the picture! I had something similar but it started to depress me! LoL
In reply to Just H

Re: Hacking and security

by Robin Greaves -
Hi Harry,

You still there?? smile I've tried to see what if anything to do about moodle_data - but my host has fired back asked me if it's a directory or a file . . . and I don't know! I've done a bit of searching and haven't managed to find it. It's a bit needle and haystack. Can you give me any tips??
In reply to Robin Greaves

Re: Hacking and security

by Just H -
Hi Robin

Jan has answered this question in your other thread so guess it's covered. As he mentions, htaccess or asking your host for a folder outside root should cover it.

From the info in your other post, guessing you used Fantastico to install Moodle (why you couldn't find moodle_data, Fantastico changes the name and the location as it can't install outside your root directory I believe).

As you are keen to ensure your site is as secure as possible, once you have it running smoothly and get a chance to catch your breath, might be an idea having a look at your options.

IMHO, Fantastico is great for a quick install of a script to see if it will meet your requirements but personally I wouldn't run a site using a Fantastico install - tends to be a bit behind with versions and therefore, potentially behind with bug/security fixes. Ask your host about shell access, if available, have a look into installing/maintaining using CVS. Fairly easy to swap over an existing install and means maintenance/upgrading is a breeze. smile

Have fun!
H
In reply to Just H

Re: Hacking and security

by Robin Greaves -
Harry, is there an icon for clutching one's head, sinking to one's knees and bursting into tears? :P I've added a footnote to the other thread which blames moodle for the names of folders etc. Apologies to . . . well to Moodle I guess!

As for your last para . . . thanks! Your confidence in me is cheering but wonderfully badly placed :D . . . shell access . . . CVS . . . you have GOT to be joking?!?! TortoiseCVS, "point at Mirrors", is this Puff The Magic Dragon? Sounds like something from the 60's! LoL Anyway, I try to avoid "upgrades" if possible, or at least stay a little behind the curve, I find that "upgrade" is usually a synonym for "downtime" :D

In reply to Robin Greaves

Re: Hacking and security

by Eric Bollens -
Shell access simply refers to connecting to your host via a Unix shell. CVS stands for Concurrent Versions System, a version control system which helps minimize downtime and simplifies upgrades by merging your personal changes with the changes made to the Moodle core. Ideally, with the right system setup, "upgrade" and "downtime" do not need be particularly synonymous. wink