LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 11-30-2007, 04:22 PM   #1
PCSpectra
LQ Newbie
 
Registered: Nov 2007
Posts: 2

Rep: Reputation: 0
PHP and shell scripts


I have some PHP scripts which allow uploading of files and storing of those files inside the docroot somewhere. I cannot store the files outside of docroot!!!

PHP is also running as user: apache

For the reasons above I have been trying to figure out a secure alternative using shell scripts.

My plan it to create several shell scripts:
- movefile.sh
- deletefiles.sh
- createfolders.sh

The idea is to hopefully have PHP invoke each of these shell scripts programatically as the need arises. After PHP uploads a file from the browser it needs to move it to a directory inside the docroot, something like:

var/www/uploads/

I figured I could store files inside uploads with the permission 755. The problem is PHP is user: apache and if it's responsible for creating the directories/files theat means they are not secure from tampering from the outside world - I think anyways.

So what I was thinking: If it's possible to create the above shell scripts and have them run as a different user than "apache" (or whatever its run as) such as a "shell". So long as the shell scripts are the owners of the files/folders then writing to them any other way with permission 755 is impossible (especially from the outside world).

My question becomes, is there a way I can make a shell script run under a specified user when invoked rom PHP or does the shell script inherit PHP's attributes, thus becoming user: "apache".

I've poked around Google and found a few articles and it seems possible by setting the script SETUID flag???

Now your familiar with my situation, what can you recommend? Is this possible?

I am aware it's possible to run PHP as it's own user (phpsuexec or CGI) but because most LAMP setups have PHP run as a apache module I'd rather the shell script approach if possible.

Cheers
 
Old 11-30-2007, 05:42 PM   #2
harry edwards
Member
 
Registered: Nov 2007
Location: Lincolnshire, UK
Distribution: CentOS, Fedora, and Suse
Posts: 365

Rep: Reputation: 48
I'm not sure if this is an acceptable alternative:

http://www-uxsup.csx.cam.ac.uk/~jw35...html/x2502.htm

It basically entails using apache to stop http access to certain file types; hence, once uploaded they are no longer accessible.
 
Old 11-30-2007, 06:38 PM   #3
vermaden
Member
 
Registered: Jan 2006
Location: pl_PL.lodz
Distribution: FreeBSD
Posts: 406

Rep: Reputation: 89
Quote:
My question becomes, is there a way I can make a shell script run under a specified user when invoked rom PHP or does the shell script inherit PHP's attributes, thus becoming user: "apache".
You can do that this way for example:
Code:
$ sudo -u user script.sh

Last edited by unSpawn; 12-01-2007 at 03:48 AM. Reason: Fix quoting for user
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php/shell script to install mysql,apache and php automatically stranger_6_7 Linux - General 2 08-11-2009 02:07 AM
Shell scripts consty Programming 2 02-18-2007 09:41 PM
Calling shell scripts from PHP as other users Thin Programming 1 12-02-2005 08:17 AM
PHP and Shell scripts haze Programming 4 04-15-2005 02:52 AM
Need Help with Shell Scripts!!!!!!!!!!! vicsharps Linux - Newbie 3 03-07-2002 09:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 09:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration