473,386 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

risk of chmod 0777

Hi all,

I've a directory in wich I save pictures of items to sell. Those pictures
are uploaded by users and I've a ftp program that need to resize some of
them (too long to explain why).
Since the owner is httpd and I connect to the ftp server using an other
user, I can't modify them as they are protected (mode 0644) and I can't
change any group rights.

I can create a script (user httpd) that does change the mode to 0777 but
since I understand NOTHING about rights, it this idea a bad idea ??? what do
I risk ? my ftp doesn't have any guest access !

Thanks for helping.

Also joker question: what does "execute" mode mean ?

Bob
Jul 3 '07 #1
3 2575
In our last episode, <46**********************@news.sunrise.ch>, the lovely
and talented Bob Bedford broadcast on comp.lang.php:
Hi all,
I've a directory in wich I save pictures of items to sell. Those pictures
are uploaded by users and I've a ftp program that need to resize some of
them (too long to explain why).
Since the owner is httpd and I connect to the ftp server using an other
user, I can't modify them as they are protected (mode 0644) and I can't
change any group rights.
I can create a script (user httpd) that does change the mode to 0777 but
since I understand NOTHING about rights, it this idea a bad idea ???
Exceedingly horrible.
what do I risk ?
Essentially your server and all the data you have on it and your reputation
if your server is compromised in such a way as to produce an annoyance on
the internet.
my ftp doesn't have any guest access !
If the httpd files are 644, anyone, even ftp running as nobody (i.e. the
least privileged user) can read them. Your program using ftp can read the
files, modify them, and write them to a place where it does have write
privileges. You shouldn't be serving raw uploads anyway. The problem is:
if you can write these files via anonymous ftp, so can anyone else.

Files should be sanitized, resized, and moved by the php that handles the
POST data.
Thanks for helping.
Also joker question: what does "execute" mode mean ?
It means it is allowable for the file to be executed as a program, and if
you do not see why this is a bad idea for uploaded files, you need to get
out of the computer business. For some servers (i.e. apache), the execute
bit is used to indicate that the file should be parsed for server-side
includes when it is being served. At the very best this is a waste of the
server's time if the file is an image which naturally should not contain any
server instructions. At worst, it would allow malicious server instructions
in an image file to be executed. Don't set the execute bit on any file that
should not contain SSIs.

--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 567 days to go.
Friends of Lizbeth: help replace failed a/c at Austin's no-kill shelter
<https://secure.groundspring.org/dn/index.php?aid=12349>
Jul 3 '07 #2
Hi Lars, thanks for replying
>what do I risk ?

Essentially your server and all the data you have on it and your
reputation
if your server is compromised in such a way as to produce an annoyance on
the internet.
>my ftp doesn't have any guest access !

If the httpd files are 644, anyone, even ftp running as nobody (i.e. the
least privileged user) can read them. Your program using ftp can read the
files, modify them, and write them to a place where it does have write
privileges. You shouldn't be serving raw uploads anyway. The problem is:
if you can write these files via anonymous ftp, so can anyone else.
No, anonymous access to FTP is disabled. So no risk I think
Anyway 644 doesn't allow me to write on it, as with my program I'm not
httpd....so I'm stuck. As I understand, for having the right to write on
this dir I must set 664 instead of 777, this way I may read and write to the
directory. If not, I've to set to 666, keeping in mind there is no access to
anonymous, I should be ok ??? could you please confirm this ?
Files should be sanitized, resized, and moved by the php that handles the
POST data.
As it's a mutualized server, big images (more than 4mio pixels, quite common
those days) can't be resized in the PHP script due to the memory limit,
that's why I do it using a ftp connection in my own program (compiled
program).
>Also joker question: what does "execute" mode mean ?

It means it is allowable for the file to be executed as a program, and if
you do not see why this is a bad idea for uploaded files, you need to get
out of the computer business. For some servers (i.e. apache), the execute
bit is used to indicate that the file should be parsed for server-side
includes when it is being served. At the very best this is a waste of the
server's time if the file is an image which naturally should not contain
any
server instructions. At worst, it would allow malicious server
instructions
in an image file to be executed. Don't set the execute bit on any file
that
should not contain SSIs.
Execute isn't set for images dir, that's ok.

Thanks for helping.
Jul 3 '07 #3
Bob Bedford schrieb:
>Files should be sanitized, resized, and moved by the php that handles the
POST data.
As it's a mutualized server, big images (more than 4mio pixels, quite common
those days) can't be resized in the PHP script due to the memory limit,
that's why I do it using a ftp connection in my own program (compiled
program).
You might be interested in taking a look at RadUpload:
http://www.radinks.com/upload/

It is a Java applet for easy FTP file upload, the pro version can resize
images at the client side, before they are uploaded, which saves upload
capacity and reduces server-side processing.

Of course it does not solve your actual chmod problem. I use a separate
FTP user (outside the www root directory) for uploads only. This is my
procedure (I am not sure if it is optimal from a security point of view;
it works even with safe_mode, anyway):
- upload files with RadUpload (logging in as upload user)
- upload user moves them into a receiving directory (chmoded 0777) via
ftp_get()
- PHP user chmods them to 0666 (else it would not be possible to delete
or download them from the server via FTP later), does all needed
post-processing and moves them into their final destination directories

Of course it would make things much easier if it were possible to hand
over a file from one user to another, or to assign FTP and PHP to one
user id. I guess the latter is possible if you configure your server
yourself; but as I always work on shared hosting I don't know about
these things.

--
Markus
Jul 4 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Daniel | last post by:
Hi, From what I read from the PHP manual, chmod on a Windows platform should have no effect, and that seems totally normal (unless someone on sourceforge has a windows port of that!). I...
6
by: Ask Josephsen | last post by:
Hi NG If I write the following: <?php $file="myfile.JPG"; if ( getmyuid()==fileowner ( $file ) ) { chgrp ( $file, getmygid() ); chown ( $file, getmyuid() );
1
by: Michael Lubavin | last post by:
Hi, I am having a perl cgi script that needs to be able to create and write a new file. Is there a way I can use chmod within the script to give temporary world access to my directory, and then...
2
by: Freebird | last post by:
Hello everyone, =] I need your help, I'm creating a script that will work in many servers, and there's this part, where you can update a list, so the script goes from the client's machine to...
3
by: Rik | last post by:
Hello, first of all, my provider sucks, newsserver is down for the #nth time now, offcourse when I have an urgent question.... So this will be me first time using Google Groups, forgive me if...
0
by: foekall | last post by:
I used this script and test on my hosting. Evertimes appear "change permission to 777 failed. ". So, how to solve this error. Please kindly check for me and teach me. <?php $MAX_SIZE =...
1
by: Sonnich Jensen | last post by:
Hi all I have problem with: $ff=dirname(__FILE__); chmod("$ff/uus", 777); chmod("uus", 777); which can I not change the directories?
1
by: lawrence k | last post by:
I've a simple script to transfer some files from one domain to another, with both domains living on the same server. The files in both directories are already chmod 777. Yet after transfer, I try...
5
by: phpmagesh | last post by:
Hi to all, I want to know what this means, 'chmod 0777' . I know its some thing like read only or write or read. can any one tell me for which action they will use that Thanks in advance, ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.