Jump to content

Recommended Posts

I have an email address which when any emails are received they're use postfix to open a php file, which then on the first line execute php via linux. This works a treat and then will do the parsing of the email and upload attachments to my server. The issue is however, security at the moment the folder is set to 777 rights, NOT by me! 

#!/usr/bin/php -q
<?php
   
   //run this php script, doing this we will be using user "nobody"

I have tried setting up a new group and owner called upload but it doesn't work because at the point of execution we are set to linux's nobody user. 

 

I thought I could switch the user using the following command 

#! runuser -l upload -c /usr/bin/php -q
<?php 

  //my php script will now run 

However this didn't work! 

 

I have also tried altering the nobody alias to "upload" and then altered the folder owner and group to match this user, which didn't work. 

 

The only thing I have remotely got to work is setting the group to nobody allowing the file to upload to the server, but again this is not perfect because it seems there are three users required to upload hence why I tried to set up a new group. 

 

Any ideas would be appreciated, my usual stop of google isn't helping too much  

 

 

 

Wouldn't you be required to supply the password for the user in doing that though? 

 

Also the initial call to the script is being done via the cpanel so when an email comes in, it fires off to the scripted file 

/path/to/my/script.php

//Then within the script this happens 

#!/usr/bin/php -q
<?php

Wouldn't you be required to supply the password for the user in doing that though?

No. You can configure sudo to not require passwords if need be, even locked down to specific commands as well.

 

Also the initial call to the script is being done via the cpanel so when an email comes in, it fires off to the scripted file

Surely you can configure what script is executed? Even still, you could easily enough create this simple wrapper using PHP instead of Bash if need be.

So if I've understood you right I would do something like this. 

 

1. In the Cpanel alter the postfix alias to call a shell scrip 

/home/my_server/runShellScrip.sh

2. Within this shell script have the following information 

#!/bin/bash
sudo -u upload /home/my_server/public_html/upload/upload_script.php

3. Keep the called php script the same 


#!/usr/bin/php -q
<?php
  
   //call the php code, parse the email and upload the attachments 

It poses something of a security risk yeah.

 

You should be able to do it on a per user basis however which makes it pretty solid IMO.

 

Defaults requiretty
Defaults:upload !requiretty
There might also be some option to execute it via su but I would need to investigate that a bit.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.