[Forgot Password]
Login  Register Subscribe

23631

 
 

115083

 
 

97147

 
 

909

 
 

78730

 
 

109

Paid content will be excluded from the download.


Download | Alert*
CWE
view XML

Unrestricted Upload of File with Dangerous Type

ID: 434Date: (C)2012-05-14   (M)2017-11-10
Type: weaknessStatus: DRAFT
Abstraction Type: Base





Description

The software allows the attacker to upload or transfer files of dangerous types that can be automatically processed within the product's environment.

Likelihood of Exploit: Medium to High

Applicable Platforms
Language: Sometimes
Language: ASP.NET
Language: Often
Language: PHP
Language Class: Language-independent
Architectural Paradigm: Web-based
Technology Class: Web-Server
Technology Class: Sometimes

Time Of Introduction

  • Implementation
  • Architecture and Design

Related Attack Patterns

Common Consequences

ScopeTechnical ImpactNotes
Integrity
Confidentiality
Availability
 
Execute unauthorized code or commands
 
Arbitrary code execution is possible if an uploaded file is interpreted and executed as code by the recipient. This is especially true for .asp and .php extensions uploaded to web servers because these file types are often treated as automatically executable, even when file system permissions do not specify execution. For example, in Unix environments, programs typically cannot run unless the execute bit is set, but PHP programs may be executed by the web server without directly invoking them on the operating system.
 

Detection Methods
None

Potential Mitigations

PhaseStrategyDescriptionEffectivenessNotes
Architecture and Design
 
 Generate a new, unique filename for an uploaded file instead of using the user-supplied filename, so that no external input is used at all.[R.434.1] [R.434.2]
 
  
Architecture and Design
 
Enforcement by Conversion
 
When the set of acceptable objects, such as filenames or URLs, is limited or known, create a mapping from a set of fixed input values (such as numeric IDs) to the actual filenames or URLs, and reject all other inputs.
 
  
Architecture and Design
 
 Consider storing the uploaded files outside of the web document root entirely. Then, use other mechanisms to deliver the files dynamically. [R.434.2]
 
  
Implementation
 
Input Validation
 
Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a whitelist of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does.
When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, "boat" may be syntactically valid because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as "red" or "blue."
Do not rely exclusively on looking for malicious or malformed inputs (i.e., do not rely on a blacklist). A blacklist is likely to miss at least one undesirable input, especially if the code's environment changes. This can give attackers enough room to bypass the intended validation. However, blacklists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright.
For example, limiting filenames to alphanumeric characters can help to restrict the introduction of unintended file extensions.
 
  
Architecture and Design
 
 Define a very limited set of allowable extensions and only generate filenames that end in these extensions. Consider the possibility of XSS (CWE-79) before allowing .html or .htm file types.
 
  
Implementation
 
Input Validation
 
Ensure that only one extension is used in the filename. Some web servers, including some versions of Apache, may process files based on inner extensions so that "filename.php.gif" is fed to the PHP interpreter.[R.434.1] [R.434.2]
 
  
Implementation
 
 When running on a web server that supports case-insensitive filenames, perform case-insensitive evaluations of the extensions that are provided.
 
  
Architecture and Design
 
 For any security checks that are performed on the client side, ensure that these checks are duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side checks by modifying values after the checks have been performed, or by changing the client to remove the client-side checks entirely. Then, these modified values would be submitted to the server.
 
  
Implementation
 
 Do not rely exclusively on sanity checks of file contents to ensure that the file is of the expected type and size. It may be possible for an attacker to hide code in some file segments that will still be executed by the server. For example, GIF images may contain a free-form comments field.
 
  
Implementation
 
 Do not rely exclusively on the MIME content type or filename attribute when determining how to render a file. Validating the MIME content type and ensuring that it matches the extension is only a partial solution.
 
  
Architecture and Design
Operation
 
Environment Hardening
 
Run your code using the lowest privileges that are required to accomplish the necessary tasks [R.434.4]. If possible, create isolated accounts with limited privileges that are only used for a single task. That way, a successful attack will not immediately give the attacker access to the rest of the software or its environment. For example, database applications rarely need to run as the database administrator, especially in day-to-day operations.
 
  
Architecture and Design
Operation
 
Sandbox or Jail
 
Run the code in a "jail" or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict which files can be accessed in a particular directory or which commands can be executed by the software.
OS-level examples include the Unix chroot jail, AppArmor, and SELinux. In general, managed code may provide some protection. For example, java.io.FilePermission in the Java SecurityManager allows the software to specify restrictions on file operations.
This may not be a feasible solution, and it only limits the impact to the operating system; the rest of the application may still be subject to compromise.
Be careful to avoid CWE-243 and other weaknesses related to jails.
 
Limited
 
The effectiveness of this mitigation depends on the prevention capabilities of the specific sandbox or jail being used and might only help to reduce the scope of an attack, such as restricting the attacker to certain system calls or limiting the portion of the file system that can be accessed.
 

Relationships
This can have a chaining relationship with incomplete blacklist / permissive whitelist errors when the product tries, but fails, to properly limit which types of files are allowed (CWE-183, CWE-184).
This can also overlap multiple interpretation errors for intermediaries, e.g. anti-virus products that do not remove or quarantine attachments with certain file extensions that can be processed by client systems.

Related CWETypeViewChain
CWE-434 ChildOf CWE-813 Category CWE-809  

Demonstrative Examples   (Details)

  1. The following code demonstrates the unrestricted upload of a file with a Java servlet and a path traversal vulnerability. The HTML code is the same as in the previous example with the action attribute of the form sending the upload file request to the Java servlet instead of the PHP code. (Demonstrative Example Id DX-22)
  2. The following code intends to allow a user to upload a picture to the web server. The HTML code that drives the form on the user end has an input field of type "file".

Observed Examples

  1. CVE-2001-0901 : Web-based mail product stores ".shtml" attachments that could contain SSI
  2. CVE-2002-1841 : PHP upload does not restrict file types
  3. CVE-2005-1868 : upload and execution of .php file
  4. CVE-2005-1881 : upload file with dangerous extension
  5. CVE-2005-0254 : program does not restrict file types
  6. CVE-2004-2262 : improper type checking of uploaded files
  7. CVE-2006-4558 : Double "php" extension leaves an active php extension in the generated filename.
  8. CVE-2006-6994 : ASP program allows upload of .asp files by bypassing client-side checks
  9. CVE-2005-3288 : ASP file upload
  10. CVE-2006-2428 : ASP file upload

For more examples, refer to CVE relations in the bottom box.

White Box Definitions
None

Black Box Definitions
None

Taxynomy Mappings

TaxynomyIdNameFit
PLOVER  Unrestricted File Upload
 
 
OWASP Top Ten 2007 A3
 
Malicious File Execution
 
CWE_More_Specific
 

References:

  1. Richard Stanway (r1CH) .Dynamic File Uploads, Security and You.
  2. Johannes Ullrich .8 Basic Rules to Implement Secure File Uploads. 2009-12-28.
  3. Johannes Ullrich .Top 25 Series - Rank 8 - Unrestricted Upload of Dangerous File Type. SANS Software Security Institute. 2010-02-25.
  4. Sean Barnum Michael Gegick .Least Privilege. Published on 2005-09-14.
  5. Mark Dowd John McDonald Justin Schuh .The Art of Software Security Assessment 1st Edition. Addison Wesley. Section:'Chapter 17, "File Uploading", Page 1068.'. Published on 2006.

© 2013 SecPod Technologies