【漏洞】WordPress 论坛插件 bbPress 存储型 XSS 漏洞

一 、修复漏洞

这个漏洞在 bbPress 2.5.9 正式版上应该就已经修复了的,不知道阿里云为什么还报说有漏洞。

Ricky 最近无论是在使用 bbPress 2.6 Release Candidate 7 测试版还是 bbPress 2.5.14 正式版时,阿里云均提示该版本的 bbPress 插件存在一个存储型 XSS 漏洞,我看阿里云的自动化修复是这么修复的,将 /wp-content/plugins/bbpress/includes/core/functions.php 文件中的(从第 321 行开始):

function bbp_find_mentions_pattern() {

	// Filter & return
	return apply_filters( 'bbp_find_mentions_pattern', '/[@]+([A-Za-z0-9-_\.@]+)\b/' );
}

改成:

function bbp_find_mentions_pattern() {

	// Filter & return
	return apply_filters( 'bbp_find_mentions_pattern', '/^[@]+([A-Za-z0-9-_\.@]+)\b/' );
}

即可。但过了一段时间,阿里云又报有漏洞,再点击修复,又加了一个 ^ ,变成 ‘/^^[@]+([A-Za-z0-9-_\.@]+)\b/’【尴尬】。

源代码下载请点击这里(压缩包中 functions_old.php 为修改前的文件,functions.php 为修改后的文件)。

二 、来自阿里云的报道

漏洞存在于 wordpress 插件 bbpress 的 /wp-content/plugins/bbpress/includes/core/functions.php 文件中,攻击者通过用户提及功能(即@用户名,而 bbPress 的用户提及功能能够将@用户名替换成另外一个链接,创建了一个嵌套链接的 HTML 结构),可在论坛文章中存储恶意代码。而这些文章会被存储到数据库中,后面会展示给随后的访问者。如果攻击者有着更加成熟的技术,可通过这种方法从版主或者管理员处窃取 cookies ,以管理员身份进行操作,实现提权。

三 、来自 freebuf 和 Sucuri 的报道

WordPress & bbPress
WordPress & bbPress
近日,WordPress 母公司 Automattic 发布了 bbPress 2.5.9 版本,在这个官方的 WordPress 论坛插件的最新版本中,修复了一个威胁程度较高的存储型 XSS 漏洞,影响范围包括现有的 bbPress 版本,即版本 < 2.5.9 的皆会受到影响。

根据来自 WordPress.org 的统计数据,当前已有超过 30 万站点使用了该插件。而据悉,该漏洞是一个存储型 XSS 漏洞,此类漏洞与反射型 XSS 漏洞,并称为 XSS 的两大类型漏洞。我们知道,在存储型 XSS 漏洞中,攻击者可以利用漏洞在 Web 平台中植入恶意代码,而恶意代码会被存储于后台或数据库中,随后其他用户访问受影响页面时,便会执行攻击者此前植入的恶意代码,从而实现跨站的攻击。

该 XSS 漏洞存在于插件的用户提及功能中

在这个案例中,一开始来自 Sucuri 的安全研究人员称其发现一种方法,攻击者通过用户提及功能(即@用户名,而 bbPress 的用户提及功能能够将@用户名替换成另外一个链接,创建了一个嵌套链接的 HTML 结构),可在论坛文章中存储恶意代码。而这些文章会被存储到数据库中,后面会展示给随后的访问者。如果攻击者有着更加成熟的技术,可通过这种方法从版主或者管理员处窃取 cookies ,以管理员身份进行操作,实现提权。

Technical Details

All posts and replies are sanitized by the WordPress function wp_kses(), which acts as a whitelist sanitization function. This means it only allows approved HTML tags and their associated whitelisted attributes (and URL protocol, for attributes like href and src) through the filtering engine. After this happens, the resulting string is passed down to the following list of filters, hooked by bbPress:

wp_kses()
wp_kses()

技术细节

所有文章和回复的内容会通过 WordPress 的 wp_kses() 函数进行过滤,该函数执行着一个白名单过滤功能,这意味着它只允许通过过滤引擎批准的 HTML 标记及其关联的白名单属性(以及 URL 协议,用于 hrefsrc 等属性)。发生这种情况后,生成的字符串将被传递到下面的过滤器列表中,并挂钩到 bbPress :

wp_kses()
wp_kses()

We found the bbp_mention_filter function interesting, as it is one of the few functions that doesn’t come from WordPress.

bbp_mention_filter
bbp_mention_filter

我们发现 bbp_mention_filter 函数很有趣,因为它是少数几个不是来自 WordPress 的函数之一。

bbp_mention_filter
bbp_mention_filter

This code does the following:

1 、It searches for mentions in the post by calling the bbp_find_mentions, returning every match from the following regex:

/[@]+([A-Za-z0-9-_\.@]+)\b/

上述代码执行流程如下:

1 、它通过调用 bbp_find_mentions 搜索文章内容中存在的用户提及关键符号 “ @ ” ,并返回以下正则表达式中的每个匹配项:

/[@]+([A-Za-z0-9-_\.@]+)\b/

2 、For each of these matches, check if it corresponds to a known user, and whether they are active or not.

2 、对于每一个搜索到的结果,则检查是否有与它相匹配的用户,以及该用户是否在线。

3 、Once that is done, it will replace these mentions with a hyperlink HTML tag, linking to the user’s profile page.

3 、一旦这些完成,接下来便会在后台程序中将提及的用户名,替换为一个 HTML 超链接标签,可链接到用户的个人页面中去。

It doesn’t check if the mentions found are already located inside an HTML tag’s attribute; therefore if a user with the name ‘test’ sends a reply containing a hyperlink tag whose href attribute is set to @test, it would break the hyperlink tag.

To better illustrate, this:

<a href="@test">link</a>

实际上,它并没有检测提及的用户名是否存在于一个 HTML 标签属性中。我们假设现在有个用户,其名称为 “ test ” ,在某篇文章中回复了一个包含超链接标签的评论,并将其中的 “ href ” 属性设置为 @test ,则会破坏超链接的标记。

为了更加直观的说明这个问题,具体如下:

<a href="@test">link</a>

… would become:

<a href="<a href="http://targetsite/test/profile/" rel="nofollow">test</a>">link</a>

… 会成为:

<a href="<a href="http://targetsite/test/profile/" rel="nofollow">test</a>">link</a>

This breaks the hyperlink tag’s double-quote sequence, allowing an attacker to insert arbitrary event handlers in it (similar to the Akismet disclosure) in order to execute malicious Javascript code.

这打破了超链接标记的双引号序列,允许攻击者在其中插入任意事件处理程序(类似于 Akismet disclosure ),以便执行恶意的 javascript 代码。

Vulnerability Disclosure Timeline

  1. April 12th, 2016 – Bug discovered, initial report to the bbPress team
  2. May 2nd, 2016 – bbPress team announces security release
  3. May 3rd, 2016 – Sucuri releases disclosure

漏洞披露时间表

  1. 2016 年 4 月 12 日:Sucuri 安全团队向 bbPress 的管理者报告了该漏洞;
  2. 2016 年 5 月 2 日:bbPress 2.5.9 修复版本发布,并已解决该问题;
  3. 2016 年 5 月 3 日:Sucuri 安全团队发布漏洞细节。

如有安装此插件的用户,需尽快升级版本,保证站点安全性,降低遭受攻击风险。

 

参考自:

  • https://www.freebuf.com/vuls/103520.html
  • https://blog.sucuri.net/2016/05/security-advisory-stored-xss-bbpress-2.html
  • https://news.softpedia.com/news/stored-xss-bug-affects-all-bbpress-wordpress-forum-versions-503646.shtml

文章附件

这篇文章对你有帮助吗?

相关文章

发表评论?

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据