Current location: Hot Scripts Forums » Programming Languages » PHP » PHP extracting rar files.

PHP extracting rar files.

Reply
  #1 (permalink)  
Old 03-02-08, 06:56 AM
scott2500uk's Avatar
scott2500uk scott2500uk is offline
Wannabe Coder
 
Join Date: Apr 2006
Posts: 236
Thanks: 1
Thanked 2 Times in 2 Posts
PHP extracting rar files.

I currently have a file uploader script on my site and I allow rar and zip files to be uploaded but to my amazment i saw a lot of rar files being uploaded and then saw that they were being extracted revieling php files.

Luckily for me I stop the read access of php scripts in my upload directory so the user was not able to run these php scripts.

What has me stumped is how the user managed to extract these rar files?

does any one know how they might have done that?

Firstly I have no files anyway on my webserver that has unrar functionality.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 03-02-08, 07:12 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 7,572
Thanks: 5
Thanked 27 Times in 24 Posts
You need the RAR extension. http://www.php.net/rar

Either that, or you ned an executable which you can call via exec().
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 03-02-08, 08:32 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,029
Thanks: 14
Thanked 34 Times in 33 Posts
Quote:
Originally Posted by scott2500uk View Post
I currently have a file uploader script on my site and I allow rar and zip files to be uploaded but to my amazment i saw a lot of rar files being uploaded and then saw that they were being extracted revieling php files.
Your server is likely compromised now. You should have your ISP run a thorough check of the system for backdoors, rootkits, etc etc.

Quote:
Originally Posted by scott2500uk View Post
What has me stumped is how the user managed to extract these rar files?
As Nico mentioned, your server may already have the RAR extension loaded, or the hackers may have previously uploaded files that allowed them to install the RAR extension without your knowledge.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data (scroll down)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 03-02-08, 08:37 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 7,572
Thanks: 5
Thanked 27 Times in 24 Posts
Another thought is, are you sure they extracted the file? Or could they have fooled your uploader by giving the uploaded php file a fake MIME type?

In your script, are you relying on the type value in $_FILES['file']['type'] to verify the files?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 03-02-08, 12:34 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,029
Thanks: 14
Thanked 34 Times in 33 Posts
Quote:
Originally Posted by Nico View Post
In your script, are you relying on the type value in $_FILES['file']['type'] to verify the files?
Also known as "Certain Death".
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data (scroll down)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 03-04-08, 02:26 AM
scott2500uk's Avatar
scott2500uk scott2500uk is offline
Wannabe Coder
 
Join Date: Apr 2006
Posts: 236
Thanks: 1
Thanked 2 Times in 2 Posts
they didnt fake the mime type as they uploaded a rar file and when i downloaded it it had the c99 shell inside it. Looking in the directory they had uploaded the file to they had managed to extract the c99 file to the same directory as the rar was in.

my webhost provider has looked over the server and nothing seems out of place.

the upload directory was the only place with write permissions so they could only upload files there. they could look at source of my files but not config files as I keep them outside readable directories.

The only bad thing they did was to chmod the upload folder to 0101 so I was unable to use that folder. A quick email to my webhosting provider and they deleted the folder for me.

They must have used an exploit in the cms Im using to run a exec() command to unrar the file they had uploaded. Im sure we have unrar loaded up as cpanel uses that function.

The thing is there is no known exploits in the cms im using for running remote commands.

Im still lost at how they did it.....

Edit: Nico i dont use that method to check file type. I check the extensions used on the file. eg: .jpg .gif etc If any dont match my allowed extensions then the file is blocked.

Plus if any files that are uploaded with these extensions:

$imagetypes = "gif|jpg|png|swf|swc|psd|tiff|bmp|iff|jp2|jpx|jb2| jpc|xbm|wbmp";

I use get_image_size() to check they are actual images not just php files with renamed extensions.

Last edited by scott2500uk; 03-04-08 at 02:32 AM. Reason: update
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
create files in php banli PHP 3 10-31-08 09:49 PM
.csv files to php TGyll Script Requests 7 01-25-07 03:22 AM
Using PHP Echo in ASX Media Files sixflagsga PHP 8 02-16-06 01:56 PM
Attach files to your form mail using PHP OMID SOFT Script Requests 0 04-17-04 07:26 PM
Chmoding files with php... tsb PHP 5 02-11-04 05:35 PM


All times are GMT -5. The time now is 09:52 PM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.