Database credentials can they be seen?

Database credentials can they be seen?

by Heather P -
Number of replies: 4

How do you ask a security question without exposing a security issue to all and sundry if it so happens that it is a security issue?

Scenario is - end user has logged into a Moodle site. For whatever reason the browser / page crashes.

Is it possible that at any point the database credentials of the Moodle site (as opposed to the individuals credentials) could be exposed in plain text on the browser page?

I personally feel that if this was likely it would have been addressed in a really early version of Moodle and is therefore unlikely.

I do however have to ask the question.

If I add in to the theoretical scenario that it would be a Moodle 2.8 or later with https across the site, would it make any difference to the answer?

Thank you for your help in this matter.

Regards

Heather

Average of ratings: -
In reply to Heather P

Re: Database credentials can they be seen?

by Ken Task -
Picture of Particularly helpful Moodlers

Can think of only one instance in which database credentials could be 'exposed' ... more like 'acquired remotely' by un-authorized access.   Did some 'ethical/whitehat hacking' once and discovered this ...

IF php is broken, any index.php file doesn't render pre-hypertext processed, but what appears to be a mix of html and confused state.  Apache server treats .php files as text ... doesn't pre-hypertext process them.   So, someone could acquire config.php file using any command line app like wget, curl, etc.. 

Example wget http://site/config.php https:// could also be used.  Nothing to stop that.  Only diff in those two is http not encripted when data sent over the wire and in https the data is encripted but the data has to be un-encripited on the rec. end.  Anyone using a browser pointed to config.php won't display anything cause there's nothing a browser would understand.   But, the file would be in cache.

Once config.php is acquired one can open it in a text file editor.  One will see then, the DB server, the DB, DB user, DB password for that user.  **IF** the installer used the same user as the root user for the operating system with the same password for the config of MySQL, then that's a big hole.  And, **IF** ssh is opened on server with no restrictions as to IP address, then anyone could use ssh, use the root user name, with root password found in the config.php file to gain shell access as the root user.

So, never use root as DB user.  Never use the same password for the shell root user in the config of MySQL.  And when one sets up the admin user in Moodle, don't use root, and don't use the root users password.

'spirit of sharing' ... and 'whitehat hacking',

Ken

In reply to Heather P

Re: Database credentials can they be seen?

by James McLean -

Database details in Moodle are stored in the $CFG variable, and to dump this data you would have to do it intentionally. Moodle itself is well hardened against people uploading PHP and trying to execute it - but the server admins also need to set their permissions on web directories correctly to aid in protecting against this too.

Best practice for any Production web application (not Moodle specific) states that you should have all debugging messages and server errors hidden from display in the browser and redirected to a text file (via PHP configuration options) should they occur.

That way if an error arises no potentially useful data is given to an unknown user.

Ken's example of a mis-configured PHP server is possible, however unlikely, and certainly not the norm.

HTTPS does not change any of this as this only protects data on the wire from outside snooping.


Average of ratings: Useful (1)
In reply to Heather P

Re: Database credentials can they be seen?

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Without being able to inject arbitrary PHP code into Moodle (so that $CFG variables could be printed) it's unlikely. 

However, consider that Moodle is a pluggable system and we cannot speak for the quality of all plugins you might have recklessly installed on your site wink

So, my advice is that you should set up your database in such a way that you could copy your database credentials right here and not care because your DB is properly firewalled. You shouldn't be allowing access to those ports from outside of your organisation and you shouldn't be using the credentials for anything else. 

In reply to Howard Miller

Re: Database credentials can they be seen?

by Heather P -

Hi

thank you all. I think that is all extremely reassuring. The possibilities of it accidentally happening are sounding mighty slim.

Heather