CVE-2013-3239 (published 2013-04-26T03:34Z)

phpMyAdmin 3.5.x before 3.5.8 and 4.x before 4.0.0-rc3, when a SaveDir directory is configured, allows remote authenticated users to execute arbitrary code by using a double extension in the filename of an export file, leading to interpretation of this file as an executable file by the Apache HTTP Server, as demonstrated by a .php.sql filename.

Severity: MEDIUM
CVSS v2 base score: 4.6 (AV:N/AC:H/Au:S/C:P/I:P/A:P)

Weakness information:
cwe_id: CWE-94
cwe_name: Improper Control of Generation of Code ('Code Injection')
description: The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.
extended_description: 
            When a product allows a user's input to contain code syntax, it might be possible for an attacker to craft the code in such a way that it will alter the intended control flow of the product. Such an alteration could lead to arbitrary code execution.
            Injection problems encompass a wide variety of issues -- all mitigated in very different ways. For this reason, the most effective way to discuss these weaknesses is to note the distinct features which classify them as injection weaknesses. The most important issue to note is that all injection problems share one thing in common -- i.e., they allow for the injection of control plane data into the user-controlled data plane. This means that the execution of the process may be altered by sending code in through legitimate data channels, using no other mechanism. While buffer overflows, and many other flaws, involve the use of some further issue to gain execution, injection problems need only for the data to be parsed. The most classic instantiations of this category of weakness are SQL injection and format string vulnerabilities.
         
         

Fix information:
repo_url: https://github.com/phpmyadmin/phpmyadmin
commit_details: repo_url: https://github.com/phpmyadmin/phpmyadmin
author: Marc Delisle
author_date: 2013-04-20 07:07:29-04:00
msg: Security: remove dots in template to avoid a remote code execution vulnerability
repository: repo_url: https://github.com/phpmyadmin/phpmyadmin
repo_name: phpmyadmin/phpmyadmin
description: A web interface for MySQL and MariaDB
repo_language: PHP
owner: phpmyadmin
file_changes: filename: export.php
change_type: ModificationType.MODIFY
diff: @@ -272,6 +272,8 @@ function PMA_exportOutputHandler($line)
                 'Export/file_template_table', $filename_template);
         }
     }
+    // remove dots in template to avoid a remote code execution vulnerability
+    $filename_template = str_replace('.', '', $filename_template);
     $filename = PMA_expandUserString($filename_template);
     $filename = PMA_sanitize_filename($filename);
 

programming_language: PHP
repo_url: https://github.com/phpmyadmin/phpmyadmin
commit_details: repo_url: https://github.com/phpmyadmin/phpmyadmin
author: Marc Delisle
author_date: 2013-04-21 06:41:02-04:00
msg: Security: block another case of remote execution vulnerability
repository: repo_url: https://github.com/phpmyadmin/phpmyadmin
repo_name: phpmyadmin/phpmyadmin
description: A web interface for MySQL and MariaDB
repo_language: PHP
owner: phpmyadmin
file_changes: filename: export.php
change_type: ModificationType.MODIFY
diff: @@ -272,10 +272,10 @@ function PMA_exportOutputHandler($line)
                 'Export/file_template_table', $filename_template);
         }
     }
-    // remove dots in template to avoid a remote code execution vulnerability
-    $filename_template = str_replace('.', '', $filename_template);
     $filename = PMA_expandUserString($filename_template);
-    $filename = PMA_sanitize_filename($filename);
+    // remove dots in filename (coming from either the template or already
+    // part of the filename) to avoid a remote code execution vulnerability
+    $filename = PMA_sanitize_filename($filename, $replaceDots = true);
 
     // Grab basic dump extension and mime type
     // Check if the user already added extension; get the substring where the extension would be if it was included

programming_language: PHP
filename: sanitizing.lib.php
change_type: ModificationType.MODIFY
diff: @@ -134,18 +134,29 @@ function PMA_sanitize($message, $escape = false, $safe = false)
 
 
 /**
- * Sanitize a filename by removing anything besides A-Za-z0-9_.-
+ * Sanitize a filename by removing anything besides legit characters 
  *
  * Intended usecase:
- *    When using a filename in a Content-Disposition header the value should not contain ; or "
+ *    When using a filename in a Content-Disposition header the value
+ *    should not contain ; or "
+ *
+ *    When exporting, avoiding generation of an unexpected double-extension file
  *
  * @param   string  The filename
+ * @param   boolean Whether to also replace dots 
  *
  * @return  string  the sanitized filename
  *
  */
-function PMA_sanitize_filename($filename) {
-    $filename = preg_replace('/[^A-Za-z0-9_.-]/', '_', $filename);
+function PMA_sanitize_filename($filename, $replaceDots = false) {
+    $pattern = '/[^A-Za-z0-9_';
+    // if we don't have to replace dots
+    if (! $replaceDots) {
+        // then add the dot to the list of legit characters
+        $pattern .= '.';
+    }
+    $pattern .= '-]/';
+    $filename = preg_replace($pattern, '_', $filename);
     return $filename;
 }
 

programming_language: PHP