Archived Boards and Threads... > Parham's PHP Tutorials

Why chmod 777 is NOT a security risk

(1/21) > >>

[Unknown]:
Alright, so say I tell you that to have attachments work properly, your attachment folder needs to be 777.  The first thing people ask me is...

  - Isn't this a security risk?
The short answer is: no, not really... it isn't.  Keep reading for the long answer.

  - So, what, you're saying EVERYTHING should be 777?!?
Not hardly.  Just some things in the forum's directory.  Not, of course, that you should do so with the entire directory - but it won't matter much if you do, so long as your server is configured reasonably correctly.

  - But... wait a minute.  The three numbers stand for "Owner," "Group," and "Everyone."  Doesn't that mean anyone can write to the files if I make it 777? (writable by all!?)
Well, technically, yes.  But, the person first has to get into your server and be able to touch the file in the first place.  They also have to have access to the directory the file is in, and the directory that file is in.  At some point, you should have a directory (probably your username) which isn't 777.

  - Isn't it safer, at least, not to use 777?  What if a hacker got in?!
If a hacker gets in and wants to cause you trouble.... there is nothing you can do.  You can have the file permissions as strict as you want, but the database will be wide open.  So, yeah... you can protect the files that don't change from being deleted, but not your posts.
Which is more important?  The files you can download again from here or the data you cannot get back?

  - Isn't it unlikely a hacker would get into my server so much they could delete posts?
Not that unlikely, but no more or less likely than if they could use 777 to their advantage.  Think of the database as ALWAYS 777.

  - Doesn't MySQL have permissions?  Can't I make it so they can't delete?
The forum won't work if you do that.  It needs to be able to delete.  If it can delete, so can the hacker.  Dillema, huh?

  - I believe you, but my host doesn't.  They don't want me to make everything 777, they say it's not safe.
So have them read this.  If they can't refute it, prove it wrong, or at least even challenge it then I guess they have to let you do 777 ;D.

  - Even if 777 isn't a problem, why should I bother?
Because it makes things, like for example the package manager and attachments, work better.

Any other questions? (so far I made all these up, sorry if they aren't realistic :P.)  Feel free to ask and I'll answer away.  I challenge you to prove me wrong.... show me that somehow 777 is all that bad.

-[Unknown]

David:
If you are on a shared server that is not chrooted on ftp or ssh login other users will be able to navigate throughout your directories.  If you have your attachments directory chmodded to 777 but its parent to 770 then they will not be able to do this as they will not be able to reach the parent.

This is how I would chmod my files and directories in a shared environment.
Read only files are 440.
Read only directories are 550.
Write files are 660.
Write directores are 770.

The ideal setup would be to have the server run in a chroot (jailed) environment.
Apache and PHP both run under SUExec.
Owner and group are both your user, since Apache runs under your user account.

If your server does not support SUExec then set the owner of the files and directories to your account and the group to the group that Apache runs under.  This still means that you can leave everyone at 0, no access, as Apache will gain access via the group.  Running in this sort of setup will not loose anything that chmodding your files to 777 allows.

[Unknown]:
The problem is that a lot of servers are not configured properly.  But, I'll add to it that you should, by all means, have your public_html folder set to 770 or less.  But subdirectories and files can be 777...

-[Unknown]

David:

--- Quote from: [Unknown] on November 20, 2003, 03:50:37 AM ---The problem is that a lot of servers are not configured properly.
--- End quote ---
You hit the nail on the head.  Many servers do not have users and groups set correctly nor does the host really understand what they do.

Bouminok:
How would you say - in brief terms - how a server should be correctly configured?

Navigation

[0] Message Index

[#] Next page

Go to full version