我们先看下joomla官网怎么说的:
https://developer.joomla.org/security-centre/723-20180301-core-sqli-vulnerability.html

User Notes模块由于缺少变量类型转换,导致sql注入的产生。这个漏洞在3.8.6版本被解决。

漏洞介绍很模糊,单从介绍来看,根本不知道这个sql注入产生的位置。
但是既然是3.8.6版本解决的,那我们就来从3.8.6版本的update包中找找思路。
如下是github上joomla的releases列表
https://github.com/joomla/joomla-cms/releases
找到Update from Joomla! 3.8.5升级包下载,打开下载好的升级包,根据notes这个线索搜索下。果然,在升级包中看到了一个notes.php文件。

我们回到github上,看下这个notes.php改动了什么。

很明显,升级包中的notes.php中,对$categoryId的值进行了限制,强制转换为int类型,可以确定,这个漏洞就出在这里。

在这里说个题外话,notes.php中getState方法出现过很多次,分别有

getState(‘filter.search’)
getState(‘filter.published’)
getState(‘filter.category_id’)
getState(‘filter.user_id’)
getState(‘filter.level’)

但是唯有getState(‘filter.category_id’)方法没有进行(int)类型转换,存在着漏洞隐患,这可能是开发者一时的疏忽吧。

CVE-2018-8045 漏洞分析
来看下存在漏洞的代码:

// Filter by a single or group of categories.
$categoryId = $this->getState('filter.category_id');
 
if ($categoryId && is_scalar($categoryId))
{
   $query->where('a.catid = ' . $categoryId);
}

$categoryId未经过滤直接拼接sql语句进行查询,造成了sql注入。

但是$categoryId参数如何控制呢?

存在漏洞的文件位于\administrator\components\com_users\models\notes.php,是一个joomla的模型文件,它的控制器是\administrator\components\com_users\controllers\notes.php

我们登录joomla后台来看一下在哪里触发这个漏洞。

访问http://xxx/joomla/administrator/index.php?option=com_users&view=notes 即可触发该控制器。

但是如何控制$categoryId参数呢?如果只访问

http://xxx/joomla/administrator/index.php?option=com_users&view=notes

只会向服务器发送一个get请求,请求中根本不包含我们想要的categoryId参数

先看下出问题的这行代码

$categoryId = $this->getState('filter.category_id');

从getState(‘filter.category_id’)不难看出来,它的作用是一个过滤器,用来选择category_id的

因此想向它传参,一定和高级搜索之类功能的有关。
选择Search Tools选项 Select Category选项。

此时joomla的发包情况

此时我们需要的filter[category_id]参数出现在了post参数中,通过这个参数的值,即可畅通无阻的进行注入。
下面验证下这个filter[category_id]参部分可以直接传递给后台的$categoryId参数
我们修改了filter[category_id]参数内容为’kingsguard_test’,并发包

后台下断点,抓取$categoryId值,可见’kingsguard_test’原封不动的被传递给$categoryId参数,并拼接sql语句进行查询。

漏洞利用: