Openfire中存在目录遍历漏洞,通过使用UTF-16编码的../,可以绕过身份验证,访问一些敏感接口,通过这些接口可以新建管理员,上传插件,进一步造成代码执行
3.10.0 <= Openfire < 4.6.8 4.7.0 <= Openfire < 4.7.5
直接下载对应的exe安装即可
在Openfire中,/setup/setup-*开头的url由AuthCheckFilter处理,并且访问该url无需经过身份验证(白名单),这个Filter定义在xmppserver/src/main/java/org/jivesoftware/admin/AuthCheckFilter.java中。
<filter>
<filter-name>AuthCheck</filter-name>
<filter-class>org.jivesoftware.admin.AuthCheckFilter</filter-class>
<init-param>
<param-name>excludes</param-name>
<param-value>
login.jsp,index.jsp?logout=true,setup/index.jsp,setup/setup-*,.gif,.png,error-serverdown.jsp,loginToken.jsp
</param-value>
</init-param>
</filter>
在xmppserver/src/main/java/org/jivesoftware/admin/AuthCheckFilter.java中通过以下代码判断是否存在目录穿越
public static boolean testURLPassesExclude(String url, String exclude) {
// If the exclude rule includes a "?" character, the url must exactly match the exclude rule.
// If the exclude rule does not contain the "?" character, we chop off everything starting at the first "?"
// in the URL and then the resulting url must exactly match the exclude rule. If the exclude ends with a "*"
// character then the URL is allowed if it exactly matches everything before the * and there are no ".."
// characters after the "*". All data in the URL before
if (exclude.endsWith("*")) {
if (url.startsWith(exclude.substring(0, exclude.length()-1))) {
// Now make sure that there are no ".." characters in the rest of the URL.
if (!url.contains("..") && !url.toLowerCase().contains("%2e")) {
return true;
}
}
}
else if (exclude.contains("?")) {
if (url.equals(exclude)) {
return true;
}
}
else {
int paramIndex = url.indexOf("?");
if (paramIndex != -1) {
url = url.substring(0, paramIndex);
}
if (url.equals(exclude)) {
return true;
}
}
return false;
}
但该代码没有考虑到其他形式的UNICODE编码,而后端却可以解析该url,导致可以使用UTF-16编码绕过目录穿越检查,并且由于可以匹配/setup/setup-*,也无需身份验证,即攻击者可以利用该漏洞绕过身份验证,任意访问后台。
攻击者可以利用该漏洞添加管理员,而后通过管理员身份上传恶意插件,造成代码执行。
结果
通过该漏洞添加管理员账户

参考链接
https://github.com/igniterealtime/Openfire/security/advisories/GHSA-gw42-f939-fhvm
Created at 2023-06-20T17:42:33+08:00