Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about LibCURL and security

Status
Not open for further replies.

pgosse

Programmer
Joined
Sep 26, 2001
Messages
42
Location
CA
Hi all. I'm wondering about any security issues which might arise from using LibCURL to move files around on a server, and indeed the feasibility of acheiving my goal.

I've got two sites which are located thusly on the same server:

/u0/vservers/cms.mysite.com/html/gateway/
/u0/vservers/
The first is a content management system, the other the live site.

What I'd like to accomplish is to allow people to upload image and document files into the CMS, and then use something similar to the following (which I found in an article on to transfer files from the cms to the live site.

The code might look like this (I've just modified the code from the article):

Code:
<?PHP 
// FTP this script to a server
$file = '/u0/vservers/cms.mysite.com/_images/image_file.jpg';
$fp = fopen($file,'r'); 
$url = 'ftp://username:password@mydomain.com:21/u0/vservers/[URL unfurl="true"]www.mysite.com/_images/image_file.jpg';[/URL] 
$ch = curl_init();     
curl_setopt($ch, CURLOPT_URL, $url);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt($ch, CURLOPT_UPLOAD, 1);  
curl_setopt($ch, CURLOPT_INFILE, $fp);  
curl_setopt($ch, CURLOPT_FTPASCII, 0);  
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file));  
$result = curl_exec($ch);  
curl_close($ch);  
?>

I will also need to change things such that this uses ftps instead of plain ftp.

Can anyone identify any major security holes that might arise from implementing something like this?

I'd also be interested in any other ideas people might have as to ways to accomplish a secure file transfer between two separate sites on the same server.

One idea I was tossing around was writing a CGI that I would call using su_exec () and having that CGI move the files.

I'll also need to eventually implement code which will allow for the deletion of files from the live site, based on commands issued from the cms.

I greatly appreciate any feedback on this idea.

Thanks in advance,

Pablo
 
I thought about that, but for security reasons I want to have the directories which the files will be uploaded to on the cms, and the directories they will be copied to on the live site, as writeable only by a specific user not the user nobody which apache will be running as. The reason for this is that the environment in which I work has a pretty high level of security and my sysadmin won't be thrilled about opening up a specific directory to be writeable by anyone. I thought about changing ownership and write access for that folder to the nobody user, but then theoretically any process running as nobody could write to this directory and I need it such that only the CMS can do so.

Ideas?

My one thought in accomplishing this is to write a CGI script, which will be executed by libCurl, that accepts the following parameters:

- directory_name
- file_name(s)

which then uses mod_suexec in Apache to su to the specified user, executes the script, su's back to the nobody user and returns true or false to the php script.

Thoughts?

Thanks in advance,
Pablo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top