MyBB 1.4 admin remote code execution vulnerability

来源:岁月联盟 编辑:zhuzhu 时间:2010-01-10

by flyh4t

date: 2010-01-10

测试版本MyBB 1.44.11

[一]漏洞分析

在index.php文件336行左右代码如下:

//index.php,336行左右

$plugins->run_hooks("index_end");
//出现了eval函数,注意参数
eval("$index = "".$templates->get("index")."";");
output_page($index);

 看以下eval()函数中的内容是否可以控制,继续找到templates类查看get函数的定义

//inc/class_templates.php,65行左右

function get($title, $eslashes=1, $htmlcomments=1)
 {
  global $db, $theme, $mybb;

  //
  // DEVELOPMENT MODE
  //
  if($mybb->dev_mode == 1)
  {
   $template = $this->dev_get($title);
   if($template !== false)
   {
    $this->cache[$title] = $template;
   }
  }

  if(!isset($this->cache[$title]))
  {
   $query = $db->simple_select("templates", "template", "title='".$db->escape_string($title)."' AND sid IN ('-2','-1','".$theme['templateset']."')", array('order_by' => 'sid', 'order_dir' => 'DESC', 'limit' => 1));
        //从数据库里面的取出模版的代码
   $gettemplate = $db->fetch_array($query);
   if($mybb->debug_mode)
   {
    $this->uncached_templates[$title] = $title;
   }

   if(!$gettemplate)
   {
    $gettemplate['template'] = "";
   }

   $this->cache[$title] = $gettemplate['template'];
  }
  $template = $this->cache[$title];

  if($htmlcomments)
  {
   if($mybb->settings['tplhtmlcomments'] == 1)
   {
    $template = "<!-- start: ".htmlspecialchars_uni($title)." -->n{$template}n<!-- end: ".htmlspecialchars_uni($title)." -->";
   }
   else
   {
    $template = "n{$template}n";
   }
  }

  if($eslashes)
  {
   $template = str_replace("'", "'", addslashes($template));
  }
  return $template;
 }

从上面的代码可以看出,get()函数是从数据库里面取出模板的内容经过处理后返回给eval函数。继续来跟以下,看看数据库里面的数据是如何来的