store | blogs | forums | twitter | facebook | wiki | mailing lists | downloads | support portal
Atomic Secure Linux
It is currently Sun May 26, 2013 5:28 am

» Feed - Atomicorp

All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic Share/Bookmark  [ 9 posts ] 
Author Message
 Post subject: ModSecurity: Failed to delete file /tmp/...
Unread postPosted: Sat Jun 09, 2012 7:29 am 
Offline
Forum User
Forum User

Joined: Mon May 07, 2012 9:37 am
Posts: 49
Location: Zurich
Hello,

I have PHP5.2 running as cgi and whenever a user tries to upload file via Webform, the following error appears:

Code:
[Sat Jun 09 13:22:47 2012] [error] [client x.x.x.x] ModSecurity: Multipart: Failed to delete file (part) "/tmp/20120609-132240-T9MyAFBKms4AAEojOPkAAAAJ-file-jpX7CM" because 1(Operation not permitted) [hostname "x"] [uri "/cgi-bin/php.fcgi/forms_test/form_base.php"] [unique_id "T9MyAFBKms4AAEojOPkAAAAJ"]


It works fine, when I disable mod_security or run PHP 5.3 as a module.

The files in /tmp are created as user:psacln.

Anyone know, how to solve this?

kind regards

-Stephan


Top
 Profile  
 
 Post subject: Re: ModSecurity: Failed to delete file /tmp/...
Unread postPosted: Mon Jun 11, 2012 4:19 am 
Offline
Forum User
Forum User

Joined: Mon May 07, 2012 9:37 am
Posts: 49
Location: Zurich
I figured it out (looks good so far..):

We had two problems: mod_security not being able to create subdirs in /var/asl/data/audit... and file-uploads not working.

I had to do this (found in the thread about mod_ruid2):
Code:
echo "umask 0" >> /etc/sysconfig/httpd

new file /etc/httpd/conf.d/01_mod_security_changes.conf:
Code:
<IfModule mod_security2.c>
SecAuditLogDirMode 0777
SecTmpDir /var/lib/php/tmp
</IfModule>


Created /var/lib/php/tmp and set it to chmod 777 and removed the sticky bit (chmod -t).

Code:
service httpd configtest && service httpd stop && service httpd start


aaaand....file uploads work (temporary files are created and removed again in /var/lib/php/tmp) and directories and files are created in /var/asl/data..

regards

-Stephan


Top
 Profile  
 
 Post subject: Re: ModSecurity: Failed to delete file /tmp/...
Unread postPosted: Mon Jun 11, 2012 12:28 pm 
Offline
Atomicorp Staff - Site Admin
Atomicorp Staff - Site Admin
User avatar

Joined: Thu Feb 07, 2008 7:49 pm
Posts: 3249
Location: Chantilly, VA
Those are some potentially dangerous permissions, you are making everything world writable and readable by default with apache, which isnt something you want to do with a shared environment. Especially making it all world writable.

_________________
Michael Shinn
Atomicorp - Security For Everyone

Co-Author of Troubleshooting Linux Firewalls.


Top
 Profile  
 
 Post subject: Re: ModSecurity: Failed to delete file /tmp/...
Unread postPosted: Wed Jun 13, 2012 7:14 am 
Offline
Forum User
Forum User

Joined: Mon May 07, 2012 9:37 am
Posts: 49
Location: Zurich
Thanks for the feedback. I realize it's world read-/writeable, but assumed that since they are only temporary files that get deleted right away, it would be ok.

Do you know how I can set the permissions to be safe and still use mod_security with suexec php?

regards -Stephan


Top
 Profile  
 
 Post subject: Re: ModSecurity: Failed to delete file /tmp/...
Unread postPosted: Wed Jun 13, 2012 10:40 am 
Offline
Atomicorp Staff - Site Admin
Atomicorp Staff - Site Admin
User avatar

Joined: Thu Feb 07, 2008 7:49 pm
Posts: 3249
Location: Chantilly, VA
Quote:
echo "umask 0" >> /etc/sysconfig/httpd


So that means all the files apache we create, ever, not just the tmp files will be worldwritable and worldreadable:

[mshinn@unit emails]$ umask 0
[mshinn@unit emails]$ touch foo
[mshinn@unit emails]$ ls -al foo
-rw-rw-rw- 1 mshinn mshinn 0 Jun 13 10:38 foo

You probably dont want that if you have a shared user environment.

_________________
Michael Shinn
Atomicorp - Security For Everyone

Co-Author of Troubleshooting Linux Firewalls.


Top
 Profile  
 
 Post subject: Re: ModSecurity: Failed to delete file /tmp/...
Unread postPosted: Wed Jun 13, 2012 6:17 pm 
Offline
Forum User
Forum User

Joined: Mon May 07, 2012 9:37 am
Posts: 49
Location: Zurich
Ouch! No, I definitely did not want that! I removed 'umask 0' from the configuration, restarted apache and corrected the file permissions.

It seems it wasn't necessary and mod_security still works fine with the other changes.

Thanks for your support and feedback. Greatly appreciate it. Also thanks for ASL, btw.. I'm just slowly starting to grasp, just how great it really is, now that we finished migration and it's been running in a production environment for a couple of days.

kind regards -Stephan


Top
 Profile  
 
 Post subject: Re: ModSecurity: Failed to delete file /tmp/...
Unread postPosted: Wed Jun 13, 2012 6:34 pm 
Offline
Forum User
Forum User

Joined: Mon May 07, 2012 9:37 am
Posts: 49
Location: Zurich
actually, I spoke too soon regarding mod_security.. I had forgotten that I had set 'SecRequestBodyAccess Off' because uploads didn't really work, even with /var/lib/php/tmp set to chmod 777.

When I uploaded a file it reported:

[Thu Jun 14 00:30:08 2012] [error] [client x.x.x.x] ModSecurity: Failed to open temporary file for reading: /var/lib/php/tmp/20120614-002956-T9kUY1BKms4AAHPzdgAAAAAJ-request_body-fPuWHQ [hostname "###"] [uri "/cgi-bin/php.fcgi/form.php"] [unique_id "T9kUY1BKms4AAHPzdgAAAAAJ"]

So, back to square 1.5, I guess. mod_security works, but only without scanning uploads.

regards -Stephan


Top
 Profile  
 
 Post subject: Re: ModSecurity: Failed to delete file /tmp/...
Unread postPosted: Wed Jun 13, 2012 7:25 pm 
Offline
Atomicorp Staff - Site Admin
Atomicorp Staff - Site Admin
User avatar

Joined: Thu Feb 07, 2008 7:49 pm
Posts: 3249
Location: Chantilly, VA
Any particular reason you are running php as cgi?

_________________
Michael Shinn
Atomicorp - Security For Everyone

Co-Author of Troubleshooting Linux Firewalls.


Top
 Profile  
 
 Post subject: Re: ModSecurity: Failed to delete file /tmp/...
Unread postPosted: Thu Jun 14, 2012 2:55 am 
Offline
Forum User
Forum User

Joined: Mon May 07, 2012 9:37 am
Posts: 49
Location: Zurich
yes, to have PHP 5.2 and PHP 5.3 in parallel.

We just migrated from old centos4.5-servers which had PHP 5.2.

On the new servers I have PHP 5.2 as php-cgi and PHP 5.3 as apache module (installed regularely via yum).

We have some hostings with very old stuff (joomla 1.0, osCommerce and some others that get warnings from 5.3) and wanted to offer our customers a way to test their stuff in 5.3 first.

regards -Stephan


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic Share/Bookmark  [ 9 posts ] 

» Feed - Atomicorp

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group