views:

39

answers:

1

Short question: how can I test whether or not a directory in my website is in practice writable for the rest of the world (even outside my own machine)?

Context:

I run this website where the hosting provider has implemented an odd security system. To let PHP write files to disk on the (linux) server, the target dir should have write permissions for everyone.

To me this would seem like a gaping security hole (note there are no users uploading stuff, only my PHP script generating files), but my host told me its safe, as they've got other (unspecified) security measures in place to keep the world from accessing my target directory. I'm skeptical, so I want to make sure all is safe.

So, I know my directory permissions -- I have set them and tested them. I know my script can write to that directory. Now I want to make sure I really am the only one who can write to that dir, despite having given everyone file permissions to do so.

For example: is there a PHP function to write to a remote directory, like fopen('http://domain.tld/foo/evil-hack.php', 'w')? I have tested that and it doesn't work, but that doesn't prove to me that somebody else won't find another way.

A: 

The php function CHMOD is your answer:

http://php.net/manual/en/function.chmod.php

addition and fileperms(); should help you too.

Ben Fransen
I know how to test it from the server itself. I want to know how I can test writing to that target directory from another machine (or another user on the same shared host) to make sure that despite giving everyone permission to write, my script actually really is the only one that _can_ write to it, as my host asserts.
avdgaag
Ah I understand what you're trying to achieve. I'm gonna be in the same situation soon because I'm developing a webapplication for multiple users (read: different clients, with different databases). I *think* that when you try to write to a directory which is not a part of your hostingenvironment you can't write to that directory because you're locked in your homedirectory. And maybe apache 'starts' another user for processing the request for two different hostingaccounts. Though this is only a wild guess, as I mentioned, I'm about to face the same situation in a few weeks ;)
Ben Fransen