Wrox Programmer Forums
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 20th, 2004, 02:59 PM
Registered User
 
Join Date: May 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default chmod

Hey

If i have a file on a chmod that allows WORLD to read and execute (not write, however), is it possible for people to view the [php] source? [Assume public ftp access is disabled, please]

Thanks!

 
Old May 20th, 2004, 03:06 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

You may be able to get something from the manual's code:

http://www.php.net/source.php?url=/source.php

HTH,

Snib

<><
 
Old May 21st, 2004, 09:55 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Locally, (i.e. on the physical webserver) poeple would be able to view the code using a text editor, yes. All requests for the file made by a user's browser, however, go through the PHP interpreter. So, no: no one will be able to request the physical file as long as your webserver knows what to do with PHP files (i.e. send them through the PHP parser and return the output, instead of the file).

That said, it wouldn't matter if the system was locked down, such that only the webserver's user (be they called "apache", "httpd", "INET_USR", or whatever your preference may be) had right to read it... if the wbeserver was configured to read PHP files as if they were simple text files, they'd send it through to the user's browser unparsed, regardless. It is the webserver, not the user, that actually reads the file. The user asks the webserver to read it for them, and the wbeserver responds as it is configured to.

With all this said, it is much better to use a file systems policy which only permits the webserver and root to read anything in the web directories. By implication, they're the only two users who should have anything to do with those files.

HTH
Dan
 
Old May 21st, 2004, 11:39 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Right, like Dan said, if you're in a shared hosting environment, other users can get access to your source code if you have given read permission to all three groups. No one outside of the server would be able to open the PHP source though.

Have a read of this article as well:
http://p2p.wrox.com/topic.asp?TOPIC_ID=11962

It's possible to grant read access to only you and your group thereby locking out everyone else.

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old May 21st, 2004, 12:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh, I hadn't thought about shared hosting, when I posted that :).

In most shared hosting environments, the admin tends to set up each site as a user, and deal out files from the user's own public_html directory, making that the root web directory of the site, and adding new sites as new users. That's on all the systems I've actually seen running - but I'm sure that more paranoid sys admins follow a less obvious policy. If this is so, even systems like RedHat (which automatically create the user's /home/username directories and subdirectories as part of the adduser command response) will lock the user's directories to that user, so the files are secured by default. Even people FTPing to the web directories of a specific site, only FTP-in as that user, and so no ownership policy violations can occur.

So in a way, it's a bit of a thoretical problem. You're assuming someone has physically changed the file from the default settings that are used on even the most user-friendly off Unix systems like RedHat, SUSE or OS X.

This is a bit like asking if we could ever have a mass mail virus in Unix (Answer, yes - assuming that every user that ever got it knew the root password for the system they were running, opened the attachment and moved the file it contained to somewhere critical on the file system, switched to root, chowned the file to root, granted execute right on the file and then executed the file... bingo - the first mass mail virus in history to come with its own man page.)
 
Old May 21st, 2004, 01:09 PM
Registered User
 
Join Date: May 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Daniel Walker
...
With all this said, it is much better to use a file systems policy which only permits the webserver and root to read anything in the web directories. By implication, they're the only two users who should have anything to do with those files.

HTH
Dan
You're right, but I think than you have to use "open_basedir" in the php.ini or in your webserver configuration. The problem is, that a user on the webserver, can use/write a PHP script which can read the content of files, which owns another user on the server (because the webserver has access to all files; ok, that is only true, if you use PHP as module and not in CGI mode)

Ciao Alex...
 
Old May 21st, 2004, 02:52 PM
Registered User
 
Join Date: May 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay, thanks.

Just to confirm though, there is no way to bypass apache (asuming apache is running)? On mode 0777, is it not possible for WORLD users to edit files?

Thanks

 
Old May 23rd, 2004, 04:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The only way to get the file, other than as a local user, is via some sort of file transfer. Methods of file transfer (and indeed, any other form of remote communication with the server) are labelled with "Port numbers", identifying which service (if any) on the machine should handle the communication. By default, requests from browsers to webservers come in on Port 80, so if a request comes through labelled "Port 80", the TCP/IP stack of the server will redirect the request to Apache - simply because that is what it is configured to do with requests labelled "Port 80" (the TCP/IP stack doesn't even know or care what happens to the request after that: Unix is completely modular, and, in fact, Windows systems are identical, in this respect, since they use a copied version of the Berkley Unix TCP/IP stack - same as everyone else).

Apache will respond to requests made of it in whatever way it is configured to, and send the response back via "Port 80". Out will go the reponse, back the way it went, with the TCP/IP stack labelling this as a "Port 80" response.

In fact, to see what a browser is actually doing, do this:
1) Open a DOS window or terminal emulator (depending on what OS you are running on your desktop).
2) Type in:
telnet www.google.com 80
Hit return, and you will connect to one of Google's clluster of web serving machines using port 80.
3) At the telnet prompt, type in:
GET / HTTP/1.0
(You may not see anything in the tenet box if you're on Windows, because Windows defaults to "local echo" off, but keep typing - the machine at the Googleplex will be recieving the text, even if you can't see anything on your machine. In fact, change this setting on the windows client by using the Terminal>Preferences option, if you like)
4) Now hit carriage return twice.
Result?
Blurgh! A whole load of HTML: Google's front page, in fact. Now, that page is a PHP page, but all you get is the output. Congratulations, you just experinced a moment in the life of a web browser :). That is exactly the set of signals sent from your browser when it makes a request to http://www.google.com/. "GET", followed by a space, followed by the name of the page (in our case a page of "/" - i.e. whatever the webserver is configured to hand out from its root web direcory) another space, and the protocol, followed by a forward slash, the protocol verion number and two line feeds. That's exactly the sequence of characters a web browser sends. It sure ain't rocket surgery, is it :)? Try connecting to p2p.wrox.com on 80, and GET /forum.asp?FORUM_ID=90 (make sure you specify HTTP version 1.0, not version 1.1, or it throws an error page back at you - but, hey, it's still a page). You'll get the HTML output for the homepage of this forum, delivered to you from from the p2p webserving machine. That's an ASP page, Google's was a PHP page, but you won't see and "Response.Write" or "echo" nonsense, in either case, because exactly the same basic process is followed on both machines, as I outlined earlier. The splurge of HTML sent back, in each case, is exactly what your browser gets back. Although telnet's standard port is 23, we actually specified port 80 in our connection request, turning telnet into a rather crap web browser, in the process. A real browser parses the markup as it comes in, of course and finds HTML elemnets like <img src=...> and makes separate requests for these images, as well, but since we're using telnet, I don't think we'd be able to recognise the images if we requested them (although the server would send them). Does the webserver care? No, it doesn't, but the server logs in each case now contain a curious request entry.

Now, users can do the same thing in reverse with a web browser. they can make a request of another port using any standard web browser (or, indeed, telnet, if they're masochists), simply by appending the port number to their request after a colon. And indeed, it is fairly standard practice for specialist webcontent to be handled on a "high port" (a "port" with a number above 1024 by) configuring the webserver, and any firewall in between, to handle such requests as legitimate web traffic (on Apache, we specify this with a Listen directive, specifying the actual network interface such request can come in on). Example of this, are the Epicmodem-chipset routers, popular for getting people onto broadband connections throughout Europe. These have an embedded operating system that runs a webserver (a hacked copy of Apache, in fact) that handles administrative traffic on a high port. Similarly the IDE-slot FlashROM-based Linux servers that Kyzo sell, use the same principle, running two entire Apaches - one outward facing and delaing requests on Port 80, as per normal, and one on the inward (LAN-facing) network card, dealing admin requests on a high port. The user simply has to know that they must append the high-port-number to all the requests they make via this channel by appending a colon followed by the port number to the request in the addressbar of their browser.

However, if there is nothing that can respond to those requests at that port, then they can make all the requests they want, and they will fall on deaf ears, so the speak.

All that said, why do you want your PHP pages to be given 777 modes, anyaway? LIke I said originally, the users never actually get to read the file: it is the web server's user that actually reads the file (and in fact, the best configuration to use, is to configure the wbeserver to run as "nobody", since that way they can only run or run anything marked as available to anybody.

The user never gets sent the actual file, they get sent a copy of the file. And if the webserver is configured to pipe every PHP file through the PHP parser first, then all they get is a copy of the parsed output... So the only user that ever gets to rad the actual file is "nobody". "nobody" doesn't need write access to the file, since the one thing a webserver never does is write files (yes, PHP can write files, butt hat's a different user again - or should be).

So, to answer your question. If you give modes 777 to all your web files, will Apache give a Monkey's? Answer - No. Will other users be able to change and moddify those files: it depends - if you've left port 23 open, they'll be able to telnet in and edit to their heart's content, yes, becaues - even if they're loging in remotely - they are actually running on a command line as if they were local users. If you've closed off 23, but left port 22 open, they'll have to use a secure shell client, like PuTTY, but they'll still have as much access as if they were sitting typing away at the server. Either way, they'll have to have the login details for at least someone on the system before doing so, because they'll have to get a command line prompt, but as soon as they have, they'll be able to muck around with the files as much as they want, because by specifying 777, that's what you're saying they can do.

In summary, is there any advantage I can see to giving 777 mode to web files? Answer: none that I can see, no, and a whole host of reasons not to - but its your call :).
 
Old May 27th, 2004, 03:55 PM
Registered User
 
Join Date: May 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for that lengthly reply, Daniel!

Okay, sorry to be persistant...

How about if it's images on 0777? The only way to edit it is if they have ftp/telnet access?

The advantage of 0777 is that PHP seems to need it for reading folders, creating images, etc etc.

Thanks!!
PS: Sorry for the newbie questions :-/

 
Old May 27th, 2004, 04:13 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Quote:
quote:Originally posted by lostroad

The advantage of 0777 is that PHP seems to need it for reading folders, creating images, etc etc.
It doesn't *have* to be 777 though to give PHP write access. Read this article (which I have posted before ;)):
http://p2p.wrox.com/topic.asp?TOPIC_ID=11962

Nik contributed very handy instructions for limiting write access to PHP scripts via group access priviledges, thereby allowing a more secure enviornment. Rather than reiterate the entire article here I'll just point you to it!

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::





Similar Threads
Thread Thread Starter Forum Replies Last Post
Warning: chmod(): Operation not permitted mrcantrell Pro PHP 2 January 20th, 2005 06:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.