phpMyAdmin 3.5.8 and 4.0.0-RC2 - Multiple Vulnerabilities

  • A+
所属分类:lcx
[waraxe-2013-SA#103] - Multiple Vulnerabilities in phpMyAdmin
===============================================================================

Author: Janek Vind "waraxe"
Date: 25. April 2013
Location: Estonia, Tartu
Web: http://www.waraxe.us/advisory-103.html


Description of vulnerable software:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

phpMyAdmin is a free software tool written in PHP, intended to handle the
administration of MySQL over the World Wide Web. phpMyAdmin supports a wide
range of operations with MySQL.

http://www.phpmyadmin.net/home_page/index.php


###############################################################################
1. Remote code execution via preg_replace() in "libraries/mult_submits.inc.php"
###############################################################################

Reason:
  1. insufficient sanitization of user data before using in preg_replace
Attack vectors:
  1. user-supplied parameters "from_prefix" and "to_prefix"
Preconditions:
  1. logged in as valid PMA user
  2. PHP version "

3. try to export that database or table, you have now additional option:

"Save on server in the directory ./"

Confirm that option, let the format be as "SQL".
"File name template" change to "@DATABASE ()  php" and click "Go" button.

Server responds with "Dump has been saved to file ./test.php.sql."

4. Request created file with webbrowser:

http://localhost/PMA/test.php.sql

In case of success we can see output of phpinfo() function, which
confirms remote code execution.


###############################################################################
3. Local File Inclusion in "export.php"
###############################################################################

Reason:
  1. insufficient sanitization of user data before using in include_once
Attack vectors:
  1. user-supplied POST parameter "what"
Preconditions:
  1. logged in as valid PMA user
  2. PHP must be  $one_post_value) {
    $GLOBALS[$one_post_param] = $one_post_value;
}

PMA_Util::checkParameters(array('what', 'export_type'));

// export class instance, not array of properties, as before
$export_plugin = PMA_getPlugin(
    "export",
    $what,
    'libraries/plugins/export/',
    array(
        'export_type' => $export_type,
        'single_table' => isset($single_table)
    )
);
------------------------[ source code end ]------------------------------------


We can see, that user-supplied parameter "what" is used as second argument for
the function PMA_getPlugin(). Let's follow execution flow:


Php script "libraries/plugin_interface.lib.php" line 20:
------------------------[ source code start ]----------------------------------
function PMA_getPlugin(
    $plugin_type,
    $plugin_format,
    $plugins_dir,
    $plugin_param = false
) {
    $GLOBALS['plugin_param'] = $plugin_param;
    $class_name = strtoupper($plugin_type[0])
        . strtolower(substr($plugin_type, 1))
        . strtoupper($plugin_format[0])
        . strtolower(substr($plugin_format, 1));
    $file = $class_name . ".class.php";
    if (is_file($plugins_dir . $file)) {
        include_once $plugins_dir . $file;
------------------------[ source code end ]------------------------------------

As seen above, second argument "$plugin_format" is used in variable "$file"
and after that in functions is_file() and include_once(). No sanitization
is used against user submitted parameter "what", which leads to directory
traversal and local file inclusion vulnerability. In case of older PHP version
it may be possible to use null byte attack and include arbitrary files on server.


###############################################################################
4. $GLOBALS array overwrite in "export.php"
###############################################################################

Reason:
  1. insecure POST parameters importing
 Attack vectors:
  1. user-supplied POST parameters
Preconditions:
  1. logged in as valid PMA user

PMA security advisory: PMASA-2013-5
CVE id: CVE-2013-3241

Affected is PMA version 4.0.0-RC2


Php script "export.php" line 20:
------------------------[ source code start ]----------------------------------
foreach ($_POST as $one_post_param => $one_post_value) {
    $GLOBALS[$one_post_param] = $one_post_value;
}

PMA_Util::checkParameters(array('what', 'export_type'));
------------------------[ source code end ]------------------------------------

We can see, that arbitrary values in $GLOBALS array can be overwritten by
submitting POST parameters. Such way of input data importing can be considered
as very insecure and in specific situation it is possible to overwrite any
variable in global scope. This can lead to many ways of exploitation. Below is
presented one of the possibilities.


Php script "export.php" line 59:
------------------------[ source code start ]----------------------------------
$onserver = false;
$save_on_server = false;
...
 if ($quick_export) {
        $onserver = $_REQUEST['quick_export_onserver'];
    } else {
        $onserver = $_REQUEST['onserver'];
    }
    // Will we save dump on server?
    $save_on_server = ! empty($cfg['SaveDir']) && $onserver;
...
// Open file on server if needed
if ($save_on_server) {
    $save_filename = PMA_Util::userDir($cfg['SaveDir'])
        . preg_replace('@[/\]@', '_', $filename);
...
    if (! $file_handle = @fopen($save_filename, 'w')) {
        $message = PMA_Message::error(
...
/* If we saved on server, we have to close file now */
    if ($save_on_server) {
        $write_result = @fwrite($file_handle, $dump_buffer);
        fclose($file_handle);
------------------------[ source code end ]------------------------------------

As seen above, when configuration setting "SaveDir" is set, then it is possible
to save database dump to the PMA webserver. By default "SaveDir" is unset and 
this prevents possible security problems. As we can overwrite any variables in
global scope, it is possible to set "SaveDir" to arbitrary value. This will
lead to directory traversal vulnerability - attacker is able to save database
dump to any directory in webserver, if only filesystem permissions allow that.
Database dump can be with extension ".sql". If attacker can dump database
with php code and tags in it, this content will be in dump file. If filename
is something like "foobar.php.sql", then by default most Apache webserver
installations will try to parse this dump file as php file, which can finally
lead to the remote code execution vulnerability.



Disclosure timeline:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

16.04.2013 -> Sent email to developers
16.04.2013 -> First response email from developers
16.04.2013 -> Sent detailed information to developers
24.04.2013 -> New PMA versions and security advisories released
25.04.2013 -> Current advisory released


Contact:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

come2waraxe () yahoo com
Janek Vind "waraxe"

Waraxe forum:  http://www.waraxe.us/forums.html
Personal homepage: http://www.janekvind.com/
Random project: http://albumnow.com/
---------------------------------- [ EOF ] ------------------------------------

source

文章来源于lcx.cc:phpMyAdmin 3.5.8 and 4.0.0-RC2 - Multiple Vulnerabilities

相关推荐: 批处理,Bat 产生,生成一组连续递增,递减的数字

使用批处理、Bat 产生、生成一组连续递增、递减的数字: 语法:for /l %%a in (A,B,C) do echo %%a 参数A:这段连续的数值开始的数值,即产生从A到B之间的数(包含A和B自身)。 参数B:需要递增的值(如果该值为负数,则是递减,但…

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: