Links to know aboutMusic The Chiara String Quartet Chiara Quartet (MySpace) Greenwood Music Camp UNL School of Music PHP PEAR Installer Manifesto phpDocumentor PEAR phar docblock PHP_Parser PHP_Parser_DocblockParser PHP_ParserGenerator PHP_LexerGenerator PEAR_PackageFileManager PHP_Archive Games_Chess Blogs Joshua Eichorn Paul M. Jones Davey Shafik Popular EntriesSetting up your own PEAR channel with Chiara_PEAR_Server - the official way
(30) Do you develop a website? It is infinitely better to synchronize live and development sites using the PEAR Installer(25) doing the PEAR thing(19) Using PEAR 1.4.0 to install PEAR packages on a remote host(19) phpDocumentor and __get/__set/__call - give us your ideas (RFC)(17) CategoriesPowered by |
Saturday, April 1. 2006Protecting a MySQL user/password in a PHP scriptTrackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
I guess you're taking it for granted that the exec* functions are disabled?
I don't understand why the script is needed to generate the file. If you just 'chown' the existing config file to the www user, and then use the open_basedir settings, the problem is already solved, isn't it?
Hi Greg,
The real problem here is that all websites served by the webserver (presumably Apache) have to be accessible by whichever user that Apache is configured to run as. What you really need is for each website to be owned by a different user, and for Apache to switch to the unique uid/gid to serve each site. Two possible ways to do it are mod_suphp and mod_peruser. Best regards, Stu
If he can cat another user's files, then that's the problem that needs to be fixed. Either the system administrator should be shot for cocking up security so badly, or the user should be for chmoding wp-config.php 0777.
Either way, surely it'd be easier to just change the wp-config.php permissions? If this was a real issue, every single user of every single shared web host would be crying foul.
Hi Greg,
Just read your update. Using ACL's is not the answer I'm afraid. All someone needs to do is to upload a PHP script to read the files in another user's website directory, and they can still read the files. As long as the webserver runs as the same user for accessing all the websites on the box, this hole remains open. Best regards, Stu
My favorite solution to this problem comes from the PHP Cookbook and is mentioned near the end of this article:
Security Corner: Shared Hosting
Hi Greg,
I want to clarify one thing. The most important part of the technique from the PHP Cookbook is that the file is only readable by root. The nobody user should not be able to read the file with the access credentials, otherwise this would be possible: CODE: readfile('/path/to/secret-stuff'); Hope that helps clarify.
Any host I have access to I quickly tested this SetEnv and it resulted in a 500 Internal Server Error - most likely because mod_env isn't installed by default.
And, aren't the db credentials then displayed on a phpinfo()? Surely not much better when anyone can guess some /info.php over only users on the machine being able to see it imho.
Another solution is to set INI settings for database connection information, for example if you are using MySQL you can use the:
mysql.default_port mysql.default_socket mysql.default_host mysql.default_user mysql.default_password So the idea would be to create a file only readable to your account (Unix permissions of 0600) db.conf. Inside this file you would have something like this: php_admin_value mysql.default_host "localhost" php_admin_value mysql.default_user "user" php_admin_value mysql.default_password "password" Then this file would be loaded through Include httpd.conf directive. When it comes to connecting to the db, you'd simply do mysql_connect() without any parameters.
I am the person that asked the question of Greg. I have tried the solution presented by Chris, however, it is still not working. I have placed a .htaccess file in my public_html directory containing the SetEnv commands. However, the .htaccess file must be at least chmod 644 for any webpages to load. Thus, and other user on the CSE server can just cat .htaccess and get the user name and password. I don't really know much about .htaccess files, so perhaps there is a way to fix this.
Thanks, Brandon |
Links in this article
PEAR Installer ManifestoCalendar
QuicksearchMy Latest ReleasesTop Exitspear.php.net (239)
www.php.net (79) pear.chiaraquartet.net (37) pecl.php.net (37) php.net (35) Blog Administration |
|||||||||||||||||||||||||||||||||||||||||||||||||