Conceptual Problem (apache/php/etc.)

Conceptual Problem (apache/php/etc.)

Post by a24pic.. » Tue, 18 Jan 2000 04:00:00



Here's an interesting (IMO) conceptual problem I'd like to pose and
solicit suggestions on.  It involves Apache, PHP, unix file
permissions, and related issues.  I've cross posted this to both the
PHP mailing list and comp.infosystems.www.servers.unix, since it seemed
relevant in both places.

I have a shared Linux webserver with about 30 users.  For reasons that
aren't worth getting into right now, the 30 users have neither telnet
nor FTP access, and never will.  Their only ability to edit their html
files is through a web-based interface that I wrote.  The way the web-
based interface works is that you go to a certain URL, log in using
HTTP-Auth, and then a PHP script checks who you are logged in as (using
the $REMOTE_USER variable) and displays a list of all the files in your
home directory.  You can select these files by clicking on them (each
file name is a link) and it will open a new web page with a giant
textarea that contains the contents of your file, which you can then
edit and save changes.  There are also other scripts to let you create
a new file or delete a file you no longer want.  Hopefully this all
makes sense so far.

The web-based interface works well, since if you log in as Joe you get
a list of only Joe's files, and therefore you can't read or edit any of
Mary's files.  Behind the scenes, all the files are chmod'd to 777 so
that the web-based interface (which is run by Apache, which runs
as 'nobody').  Since no user has telnet or FTP access to the box (they
can only use the web-based interface), the fact that the files are all
777 isn't a problem.

However, here's where the problems start.  Some of the users would like
to be able to embed PHP in their web documents.  Let's say that Joe
creates a web document in his home directory with PHP that looks like
this:

<?php
        chdir("/");
        exec("rm -R *");
?>

This is a problem.  Since all the user files are chmod'd to 777, Joe
has just successfully deleted *all* of the user files, even those that
don't belong to him.  Clearly that's not acceptable.  The question then
becomes, what do I do to allow the user's to use PHP without running
into this problem?

I have two ideas about how to solve this problem, neither of which is
that great.  I have listed them below.  I would appreciate feedback on
them from anyone who has ideas.  Also, if there is anyone out there who
has an idea for a totally different approach, I'd be happy to hear that
too.

Both of these ideas are based on (1) first resetting the user file
permissions so that they are not all 777, but instead the files are
owned by their respective owners (joe has rwx for joe's files, but no
permissions for Mary's files, etc.), and then (2) finding a way to fix
the web-based interface so that it still works without depending on all
files being 777.

Idea #1:  Find some way to have the PHP scripts that comprise the web-
based interface run as the user who is accessing them.  Example, if
$REMOTE_USER=='joe' then find some way to have the web-based interface
scripts detect this fact and run as joe (instead of as nobody).  If
this were possible, the web-based admin system scripts would run as joe
when Joe was logged in, and run as mary when Mary was logged in, etc.,
and all would be well.  The problem is, I think this is impossible.  To
the best of my knowledge, the Apache suexec stuff is only available to
CGI programs, but PHP is running as an Apache module and I cannot
switch over to running it as CGI.  So I guess this idea is out. (unless
I'm mistaken?)

Idea #2:  Have separate copies of Apache running as each different user
on different ports.  For example, there would be one main copy of
Apache that ran the public webserver.  It would run as nobody and
listen on port 80.  Then there would be 30 other copies of Apache
running, each running as a different user and listening on a different
port.  E.g., there would be a copy running on port 81 that ran as user
Joe, a copy running on port 82 that ran as user Mary, and so on for all
30 users.  Then I would tell Joe to access
www.domain.com:81/admin_system/ instead of just
www.domain.com/admin_system/ (and I would tell Mary to access
www.domain.com:82/admin_system/ and so on for all 30 users).  Since Joe
would only have access to the copy of Apache running as user joe (the
copy on port 81), Joe would not be able to delete other people's files
since he only has rwx permission for his own files, and no permissions
for other people's files.  My only concern with this idea is that
having 30 copies of Apache running could be a huge drain on system
resources.  Anyone have any thoughts on how to get around this issue?

So, those are my ideas.  Comments appreciated.  TIA!

-mike

P.S.  Please don't suggest things like "don't give the users PHP
access" or "stop using a web-based interface."  I really need to give
them PHP access, and the web-based interface has to stay.

P.P.S.  I do have a third idea, but it would be extremely difficult to
implement.  The third idea is to write a custom PHP parser that reads
in the PHP these users write (before allowing it to be saved to disk)
and checks to make sure that they don't make any calls to functions
like exec() or fopen() and don't run SQL DELETE or INSERT queries.  Not
only does this seem difficult, it also seems like it would be really
tough to predict ahead of time all the malicious things that users
could try to do.

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

Conceptual Problem (apache/php/etc.)

Post by Chris Hardi » Fri, 28 Jan 2000 04:00:00



> The web-based interface works well, since if you log in as Joe you get
> a list of only Joe's files, and therefore you can't read or edit any of
> Mary's files.  Behind the scenes, all the files are chmod'd to 777 so
> that the web-based interface (which is run by Apache, which runs
> as 'nobody').  Since no user has telnet or FTP access to the box (they
> can only use the web-based interface), the fact that the files are all
> 777 isn't a problem.

> However, here's where the problems start.  Some of the users would like
> to be able to embed PHP in their web documents.  Let's say that Joe
> creates a web document in his home directory with PHP that looks like
> this:

> <?php
>         chdir("/");
>         exec("rm -R *");
> ?>

> This is a problem.  Since all the user files are chmod'd to 777, Joe
> has just successfully deleted *all* of the user files, even those that
> don't belong to him.  Clearly that's not acceptable.  The question then
> becomes, what do I do to allow the user's to use PHP without running
> into this problem?

You should consider using the suEXEC module for Apache.

http://www.apache.org/docs/suexec.html

Your suggestions below involve reinventing the wheel to some degree or
another.

If you use suEXEC, it will require the scripts be owned by the user to whom
they belong.  There are various other restrictions; see the doc linked
above.

- Show quoted text -

Quote:

> I have two ideas about how to solve this problem, neither of which is
> that great.  I have listed them below.  I would appreciate feedback on
> them from anyone who has ideas.  Also, if there is anyone out there who
> has an idea for a totally different approach, I'd be happy to hear that
> too.

> Both of these ideas are based on (1) first resetting the user file
> permissions so that they are not all 777, but instead the files are
> owned by their respective owners (joe has rwx for joe's files, but no
> permissions for Mary's files, etc.), and then (2) finding a way to fix
> the web-based interface so that it still works without depending on all
> files being 777.

> Idea #1:  Find some way to have the PHP scripts that comprise the web-
> based interface run as the user who is accessing them.  Example, if
> $REMOTE_USER=='joe' then find some way to have the web-based interface
> scripts detect this fact and run as joe (instead of as nobody).  If
> this were possible, the web-based admin system scripts would run as joe
> when Joe was logged in, and run as mary when Mary was logged in, etc.,
> and all would be well.  The problem is, I think this is impossible.  To
> the best of my knowledge, the Apache suexec stuff is only available to
> CGI programs, but PHP is running as an Apache module and I cannot
> switch over to running it as CGI.  So I guess this idea is out. (unless
> I'm mistaken?)

> Idea #2:  Have separate copies of Apache running as each different user
> on different ports.  For example, there would be one main copy of
> Apache that ran the public webserver.  It would run as nobody and
> listen on port 80.  Then there would be 30 other copies of Apache
> running, each running as a different user and listening on a different
> port.  E.g., there would be a copy running on port 81 that ran as user
> Joe, a copy running on port 82 that ran as user Mary, and so on for all
> 30 users.  Then I would tell Joe to access
> www.domain.com:81/admin_system/ instead of just
> www.domain.com/admin_system/ (and I would tell Mary to access
> www.domain.com:82/admin_system/ and so on for all 30 users).  Since Joe
> would only have access to the copy of Apache running as user joe (the
> copy on port 81), Joe would not be able to delete other people's files
> since he only has rwx permission for his own files, and no permissions
> for other people's files.  My only concern with this idea is that
> having 30 copies of Apache running could be a huge drain on system
> resources.  Anyone have any thoughts on how to get around this issue?

> So, those are my ideas.  Comments appreciated.  TIA!

> -mike

> P.S.  Please don't suggest things like "don't give the users PHP
> access" or "stop using a web-based interface."  I really need to give
> them PHP access, and the web-based interface has to stay.

> P.P.S.  I do have a third idea, but it would be extremely difficult to
> implement.  The third idea is to write a custom PHP parser that reads
> in the PHP these users write (before allowing it to be saved to disk)
> and checks to make sure that they don't make any calls to functions
> like exec() or fopen() and don't run SQL DELETE or INSERT queries.  Not
> only does this seem difficult, it also seems like it would be really
> tough to predict ahead of time all the malicious things that users
> could try to do.

> Sent via Deja.com http://www.deja.com/
> Before you buy.

-- Chris Hardie -----------------------------

-------- http://www.summersault.com/chris/ --

 
 
 

Conceptual Problem (apache/php/etc.)

Post by Raj Dut » Fri, 28 Jan 2000 04:00:00


Quote:> You should consider using the suEXEC module for Apache.

I don't think that'll help, since the original poster said he's running PHP as a
module.
Perhaps it would be prudent to run it as a cgi program (instead of a module) in
this case. Then, the suEXEC idea would work well.

Cheers,

--
+-----------------------------------------------------+

| CTO, Network Administrator    518.330.7597          |
| Voxel Dot Net, Inc            http://www.voxel.net  |
+-----------------------------------------------------+

 
 
 

1. Apache w/ PHP and SSL: w/ PHP OK - w/out PHP NOK

Hi,

        I've been assigned the task of building an Apache server with
support for Sybase, PHP4, OpenSSL 0.9.6/mod_ssl ?, and apache 1.3.14.

I followed Israel Denis Jr/Eugene Otto's "The Soothingly Seamless
Setup of Apache, SSL, MySQL, and PHP" at DevShed, but compilation of
apache fails if I add PHP.  The same procedure w/out PHP works OK
(either port 80 or port 443.) As a non-developper, I'm totally in the
dark.

[/home/samba/temp/Apache/apache_1.3.14]# SSL_BASE=../openssl-0.9.6
/configure --enable-module=ssl
--activate-module=src/modules/php4/libphp4.a --enable-module=php4
--prefix=/usr/local/apache

Configuring for Apache, Version 1.3.14
(snip)
-L/home/samba/temp/Apache/openssl-0.9.6  -o helpers/dummy
helpers/dummy.c   -rdynamic -Lmodules/php4 -L../modules/php4
-L../../modules/php4 -lmodphp4  -lpam  -ldl -lresolv -lm -ldl -lcrypt
-lnsl  -lresolv   -lm -lcrypt  -lssl -lcrypto
/usr/bin/ld: cannot find -lmodphp4
collect2: ld returned 1 exit status
make: *** [dummy] Error 1

Any idea?

Thx
FF.

2. help on Perl5.004_04 installation

3. Solaris - PHP- Apache- Oracle : Problem getting PHP installed

4. Cant't 'startx'- IBM Thinkpad 755CX 9545HNE-RH5.2, 6.0-HELP!!!!!!!!!!!!!!!!!

5. migrating users, apache, mysql php etc

6. Page fault awareness

7. Binary apache with SSL/PHP/mysql/LDAP/IMAP/JSERV/etc.

8. XmPrintShell missing on Solaris 7

9. Apache Rewrite domain.com->index.php domain.org->index2.php

10. Conceptual difficulties upgrading from Apache 1.3.6 to 1.3.9

11. php problem or apache problem?

12. Apache+PHP+mod_perl configures ok, but Apache won't build

13. ps/1, Lilo, etc etc etc problems w/ instalation