Re: reading/writing files outside of web root

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Phil Ewington - 43 Plc wrote:
> For some reason user_prefs will not open
> for read/write even when I tested it under apache.apache and chmod'd to
> 755,
> perhaps because /home is owned by root?

Something went wrong with this test.

You SHOULD have been able to read/write that file in PHP, assuming
'apache' is the user PHP runs as.  Use http://php.net/phpinfo to confirm
that it really *IS* 'apache' user that's running apache/php.

As far as the sudo stuff goes, just be sure you give the PHP user as
LITTLE power as you can to get the job done.

To that end, I think the idea of the PHP user editing a copy of the files,
and then a cron job from root to double-check the files and copy them over
if they seem valid is the best solution.

You can even run all kinds of extra checks in the routine that checks the
syntax of the files.

For example, it's one thing for the .procmailrc to be valid syntax:  But
you could add some extra PHP code to check for some very specific things
you do NOT want to happen.  You could even check that the top part of the
files "match" and only a few (no more than X) new lines have been added by
PHP.

And you could check for specific things in the new lines, like 'root' if
you wanted to disallow somebody messing with 'root' account.

As many extra pieces of armour you can add to make SURE that the file is
being changed in the way you intended is good.

You can even intentionally write the code in a way that makes it easy for
you to add more checks.

Something as simple as:

if (...){
  error_log("Hack attempt: trying to break sendmail with 'root' acces");
  exit;
}

if (...){
  error_log("Hack attempt: ...");
  exit;
}
.
.
.

will let you add in new tests as they occur to you.

When you're done, put yourself in the shoes of a Bad Guy, and pretend your
worst enemy -- the person on this Earth you most dislike, has written this
code, and ask yourself: "How can I break in to this?" :-)

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux