Go Back   Novahq.net Forum > phphq.Net > phphq.Net Forums
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-25-2008, 05:56 PM
gopat is offline gopat
Registered User

Join Date: May 2008
Posts: 5

phUploader File Upload Vulnerability

I noticed this phUploader security issue at: SecurityFocus.

Below is a summary from: SecurityFocusArchives :

Quote:
phUploader is prone to an arbitrary file-upload vulnerability because the application fails to sufficiently sanitize user-supplied input.
Could you provide a code snippet to sanitize the user input, or better yet add it to a new version?

Great script, keep up the good work!
Reply With Quote
  #2  
Old 05-25-2008, 06:08 PM
Scott is offline Scott
Scott's Avatar
AKA. Panther

Join Date: Sep 2001
Location: Minneapolis, MN
Posts: 10,922

It's not really a vunerability but rather an annoyance. If someone uploads a file with a special character you may not be able to delete it though FTP. Make sure you set file extensions to exclude file types that are prone to cause attacks suchs as exe, src etc as the script cannot tell if the file is an exploit. It may also be helpfull to run a virus scanner in the background like you shoud be doing on a server anyways.

To fix it do this:

After (line 185):
PHP Code:
// For random names
If($random_name){
    
$file_name[$i]=time()+rand(0,100000).".".$ext;
} Else {
    
$file_name[$i]=$_FILES['file']['name'][$i];

Add:
PHP Code:
$sanatize = array(" ""`""\"""\'""\\""/");
$file_name[$i] = str_replace($sanatize,"",$file_name[$i]); 
Thanks for letting me know about this and thanks for using my script!
__________________

04' Dodge SRT-4, Mopar Stage 3, 406whp/436wtq

Last edited by Scott; 05-25-2008 at 06:14 PM.
Reply With Quote
  #3  
Old 05-25-2008, 07:21 PM
gopat is offline gopat
Registered User

Join Date: May 2008
Posts: 5

Sweet! I will do that! Thanks for the speedy reply.
Reply With Quote
  #4  
Old 05-25-2008, 08:05 PM
gopat is offline gopat
Registered User

Join Date: May 2008
Posts: 5

I added the suggested code but encountered an error from the "\" section, which I replaced with "\\" to escape the escape character and avoid the error missing the double quote.

Then I reduced the code to test just file names with spaces, since I really need this feature... My sanitize line is now:
$sanatize = array(" ");

This was very easy to test by uploading file names with spaces. The program completed but it did not remove the spaces in the uploaded file names. Any ideas why? Can you verify this?
Thanks!
Reply With Quote
  #5  
Old 05-25-2008, 08:35 PM
gopat is offline gopat
Registered User

Join Date: May 2008
Posts: 5

Oops, I forgot to mention that the "random_name" variable is set to false, so the code will be executed in the "Else" clause.
Reply With Quote
  #6  
Old 05-26-2008, 05:58 PM
Scott is offline Scott
Scott's Avatar
AKA. Panther

Join Date: Sep 2001
Location: Minneapolis, MN
Posts: 10,922

Sorry, I didn't test the above code before posting it as I was in a rush. I throughly tested this and it works. Remove any previous changes.

Replace:
PHP Code:
// For random names 
If($random_name){ 
    
$file_name[$i]=time()+rand(0,100000).".".$ext
} Else { 
    
$file_name[$i]=$_FILES['file']['name'][$i]; 

With:
PHP Code:
// For random names
If($random_name){
    
$file_name[$i]=time()+rand(0,100000).".".$ext;
} Else {
    
$sanatize = array(" ""`""\"""'""\\""/"); 
    
$file_name[$i]=str_replace($sanatize,"",$_FILES['file']['name'][$i]);

__________________

04' Dodge SRT-4, Mopar Stage 3, 406whp/436wtq
Reply With Quote
  #7  
Old 05-27-2008, 12:51 PM
gopat is offline gopat
Registered User

Join Date: May 2008
Posts: 5

The new code will throw an error (see below), I think due to the back slash cancels the double quote (see fix below). However, I was not able to test my changes in the code.

It worked like a charm after the above change. I was able to test uploading a file with spaces and they were removed as expected. Thanks for your effort!


Quote:
//Error below:
PHP Parse error: syntax error, unexpected '"', expecting ')'

//Here is the line of code that fixed it, note the double back slash...
$sanatize = array(" ", "`", "\"", "'", "\\", "/");
Reply With Quote
  #8  
Old 05-27-2008, 12:55 PM
Scott is offline Scott
Scott's Avatar
AKA. Panther

Join Date: Sep 2001
Location: Minneapolis, MN
Posts: 10,922

Weird!! it's the forums software that was removing my double back slash.. I knew I tested that code right before I posted it.

Glad it worked for you
__________________

04' Dodge SRT-4, Mopar Stage 3, 406whp/436wtq
Reply With Quote
Reply


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

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
incorporate php file upload with MySQL form? pauldridge Tech Support 1 06-16-2010 08:46 AM
Send Email with Attachment from the File Upload ronieperez phphq.Net Forums 2 10-24-2008 07:14 PM
phUploader can erase file? chrbar phphq.Net Forums 3 09-06-2008 05:05 PM
Form verify phUploader so they MUST upload? Lex phphq.Net Forums 1 08-27-2007 06:13 PM
Microsoft Confirms WMF Vulnerability zaitsev Hardware and Software 0 01-02-2006 10:04 AM


All times are GMT -5. The time now is 11:32 AM.




Powered by vBulletin®