热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

vue移动端上传文件插件_wordpress插件wpdiscuz任意文件上传漏洞分析

下载链接https:downloads.wordpress.orgpluginwpdiscuz.7.0.3.zip测试环境•windowsphpstudy•phpstorm解压插件
下载链接

https://downloads.wordpress.org/plugin/wpdiscuz.7.0.3.zip

测试

环境

•windows phpstudy•phpstorm

解压插件到wp-content/plugins目录下

登录管理员启用插件,这时文章下面评论区

0a92d8a3f271346d70735304238df90a.png

image.png

上传带GIF头的php文件

0b18b4be10debd5f6ac6c6d7d23ffc4b.png

image.png

可以看到上传成功,图片地址也在回显中

http://127.0.0.1/wordpress/wp-content/uploads/2020/08/1-1598075857.9448.php

1447b721d5cc98fef5e8a13264646533.png

image.png

分析

wp-setting.php 将wp_ajax_nopriv_wmuUploadFiles写入了$wp_filter

foreach ( wp_get_active_and_valid_plugins() as $plugin ) { wp_register_plugin_realpath( $plugin ); include_once $plugin; /** * Fires once a single activated plugin has loaded. * * @since 5.1.0 * * @param string $plugin Full path to the plugin's main file. */ do_action( 'plugin_loaded', $plugin );}

通过表单action参数插件加载

6cf0f153bfa66865f7f58dc41f2f7cc4.png

image.png

$action = ( isset( $_REQUEST['action'] ) ) ? $_REQUEST['action'] : '';

wordpress先加载插件

ed6b130e12b76151e75cfb8b4535fa43.png

image.png

入口文件

164ab84029c13feba0dbfe1db83b4f2b.png

image.png

上传的关键代码在wp-content\plugins\wpdiscuz\utils\class.WpdiscuzHelperUpload.php376行

public function uploadFiles() {……require_once(ABSPATH . "wp-admin/includes/image.php");foreach ($files as $file) {$error = false;$extension = pathinfo($file["name"], PATHINFO_EXTENSION); //$extension="php"$mimeType = $this->getMimeType($file, $extension);

检测文件mime类型

private function getMimeType($file, $extension) { $mimeType = ""; if (function_exists("mime_content_type")) { $mimeType = mime_content_type($file["tmp_name"]); //image/gif } elseif (function_exists("finfo_open") && function_exists("finfo_file")) { $finfo = finfo_open(FILEINFO_MIME_TYPE); $mimeType = finfo_file($finfo, $file["tmp_name"]); } elseif ($extension) { $matches = wp_check_filetype($file["name"], $this->options->content["wmuMimeTypes"]); $mimeType = empty($matches["type"]) ? "" : $matches["type"]; } return $mimeType;}

继续跟进

……if ($this->isAllowedFileType($mimeType)) { if (empty($extension)) { //$extension="php" 没进入 …… } $file["type"] = $mimeType;} else { ……}do_action("wpdiscuz_mu_preupload", $file); //没什么用if (!$error) { $attachmentData = $this->uploadSingleFile($file);

isAllowedFileType

private function isAllowedFileType($mimeType) { $isAllowed = false; if (!empty($this->options->content["wmuMimeTypes"]) && is_array($this->options->content["wmuMimeTypes"])) { $isAllowed = in_array($mimeType, $this->options->content["wmuMimeTypes"]); } return $isAllowed;}

$this->options->content["wmuMimeTypes"] 内容

302530339d94ccff4d925bd2318bc893.png

image.png

在数组内

$isAllowed=true

上传操作在

340行 $attachmentData = $this->uploadSingleFile($file);

uploadSingleFile

private function uploadSingleFile($file) {$currentTime = WpdiscuzHelper::getMicrotime();$attachmentData = [];$path = $this->wpUploadsPath . "/";$fName = $file["name"];$pathInfo = pathinfo($fName);$realFileName = $pathInfo["filename"];$ext = empty($pathInfo["extension"]) ? "" : strtolower($pathInfo["extension"]);$sanitizedName = sanitize_file_name($realFileName); $cleanFileName = $sanitizedName . "-" . $currentTime . "." . $ext;$cleanRealFileName = $sanitizedName . "." . $ext;$fileName = $path . $cleanFileName;if (in_array($ext, ["jpeg", "jpg"])) {$this->imageFixOrientation($file["tmp_name"]);}$success = apply_filters("wpdiscuz_mu_compress_image", false, $file["tmp_name"], $fileName, $q = 60);if ($success || @move_uploaded_file($file["tmp_name"], $fileName)) {

到这里已经把文件上传了 上传文件名为原文件名+时间戳+后缀

v7.0.5的改进

isAllowedFileType 对mime的后缀和文件后缀进行比较

private function isAllowedFileType($mimeType, $extension) { $isAllowed = false; if (!empty($this->mimeTypes) && is_array($this->mimeTypes)) { foreach ($this->mimeTypes as $ext => $mimes) { if ($ext === $extension) { if ($isAllowed = in_array($mimeType, explode("|", $mimes))) { break; } } } } return $isAllowed;}总结

整个上传过程只对文件头进行检测,并没有对文件后缀进行检测,导致可以设置一句话木马内容为

图片文件头+php代码

,进行getshell




推荐阅读
author-avatar
菜大虾
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有