phpMyAdminにおける任意スクリプト実行可能な脆弱性の検証

 phpMyAdmin(3.3.10.2未満、3.4.3.1未満)には、リモートから任意のスクリプトが実行可能な脆弱性があります。このエントリでは、この脆弱性が発生するメカニズムと対策について報告します。

概要


 phpMyAdmin2


CVE-2011-2505

CVE-2011-2506


 


phpMyAdmin 3.3.10.2

phpMyAdmin 3.4.3.1


 phpMyAdmin使

影響


 PHPNTT
 PoC

CVE-2011-2505の概要


 
 CVE-2011-2505register_globals?register_globals
 libraries/auth/swekey/swekey.auth.lib.php 266
if (strstr($_SERVER['QUERY_STRING'],'session_to_unset') != false)
{
    parse_str($_SERVER['QUERY_STRING']);
    session_write_close();
    session_id($session_to_unset);
    session_start();
    $_SESSION = array();
    session_write_close();
    session_destroy();
    exit;
}

 parse_str使PHP2'a=xyz&b[x]=p23&_SESSION[user]=yamada'
<?php
  session_start();
  parse_str('a=xyz&b[x]=p23&_SESSION[user]=yamada');
  var_dump($a);
  var_dump($b);
  var_dump($_SESSION);

【実行結果】
string(3) "xyz"
array(1) {
  ["x"]=>
  string(3) "p23"
}
array(1) {
  ["user"]=>
  string(6) "yamada"
}

 parse_str($_SERVER['QUERY_STRING']); URLexit;
 CVE-2011-2505
 $_SESSION = array(); 


session_write_close(); 

session_id($session_to_unset); ID

ID


 $session_to_unset session_to_unsetparse_str
 (3.4.3.1)
if (!empty($_GET['session_to_unset']))
{
 session_write_close();
 session_id($_GET['session_to_unset']);
 session_start();
// 以下同じ

 parse_strsession_to_unset使session_to_unset使parse_strregister_globalsregister_globals
 CVE-2011-2505

CVE-2011-2506の概要


 CVE-2011-2506ConfigGenerator.class.phpPHPsetup/lib/ConfigGenerator.class.php38
    // servers
    if ($cf->getServerCount() > 0) {
        $ret .= "/* Servers configuration */$crlf\$i = 0;" . $crlf . $crlf;
        foreach ($c['Servers'] as $id => $server) {
            $ret .= '/* Server: ' . strtr($cf->getServerName($id), '*/', '-') . " [$id] */" . $crlf

 /* Server:

config/config.inc.php


/* Server: the test server [1] */
 

 $cf->getServerName($id)the test server$id1
 strtr*-


*/ system('echo /etc/passwd'); /*
 

 systemOS


/* Server: */ system('echo /etc/passwd'); /* [1] */
 

 


/* Server: -/ system('echo /etc/passwd'); /* [1] */
 

 strtrstrtr232n3n2*/3-2*1*-*/-3--
 $id$idCVE-2011-2506
 (3.4.3.1)
            $ret .= '/* Server: ' . strtr($cf->getServerName($id) . " [$id] ", '*/', '-') . "*/" . $crlf

 $cf->getServerName($id) . " [$id] "strtr使
 CVE-2011-2506CVE-2011-2505CVE-2011-2506PHP
 PoCHTTP
GET /phpmyadmin/setup/index.php                                  セッションID、トークンの取得など
GET /phpmyadmin/?_SESSION[ConfigFile][Servers][*/攻撃スクリプト  セッション変数汚染
POST /phpmyadmin/setup/config.php                                攻撃コードの埋め込み
GET /phpmyadmin/config/config.inc.php?eval=攻撃コード            攻撃コードの実行

対策


 phpMyAdminsetupconfigphpMyAdmin*2phpMyAdmin


phpMyAdmin


 


phpMyAdmin

phpMyAdminIP

phpMyAdminSSLHTTPBASIC


 HTTPphpMyAdminHTTP使ApachephpMyAdminHTTPphpMyAdminHTTPsetupconfigApachephpMyAdmincookie
 config


config


 phpMyAdmin

まとめ


 phpMyAdminCVE-2011-2505CVE-2011-2506
 evalphpMyAdmin
 調PHPphpMyAdmin
 parse_str使2parse_strphpMyAdmin3.4.3.1調parse_str使1libraries/auth/swekey/swekey.auth.lib.php 146調

 phpMyAdminphpMyAdminphpMyAdmin使phpMyAdmin使phpMyAdminIPHTTP
 configconfigphpMyAdmin


 *3

 phpMyAdmin

[PR]

*1:PHPオンラインマニュアルによると、「from と to の長さが異なる場合、長い方の余分な文字は無視されます。」とあります

*2:これら設定用のスクリプト自体には認証機能はありません。

*3:phpMyAdminのどのバージョンからこのメッセージが表示されるかは調べていません